OpenPrinting / OpenPrinting/libcupsfilters

Linking with libcups3 causing segfault

Open
#151 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
17
Forks
71
Avg merge
2d 17h
Merged PRs (30d)
13

Description

Test environment, Ubuntu Server 26.04 running CUPS 2.4.16 and libcupsfilters 2.1.1 from package manager. I compiled and installed libcups 3.0.2 from source. Trying to run any filter function results in a segfault or general protection fault. The same functions work fine when linked against libcups2.

Create the following program:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <cups/cups.h>
#include <cupsfilters/filter.h>

int main(int argc, char** argv)
{
    if (argc < 2) return 0;
    int fp = open(argv[1], O_RDONLY);
    if (!fp) return 0;
    int fp_out = open("output.pdf", O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
    if (!fp_out) return 0;
    cf_filter_data_t data;
    memset(&data, 0, sizeof(data));
    data.logfunc = cfCUPSLogFunc;
    data.job_title = "smth";
    data.job_user = "smth";
    //data.logdata = "log.txt";
    data.content_type = "application/postscript";
    data.final_content_type = "application/pdf";
    cfFilterUniversal(fp, fp_out, 1, &data, NULL);
    close(fp);
    close(fp_out);
    return 0;
}

Compile as follows: $ cc test.c -lcupsfilters -lcups Result is input Postscript files are converted to PDF as expected.

DEBUG: cfFilterUniversal: Converting from application/postscript to application/pdf
DEBUG: cfFilterUniversal: Final output format for job: application/pdf
DEBUG: cfFilterUniversal: Adding ghostscript to chain
INFO: cfFilterChain: Running filter: ghostscript
INFO: cfFilterChain: ghostscript (PID 13286) started.
DEBUG: cfFilterGhostscript: Output format: PDF
DEBUG: cfFilterGhostscript: Copying input to temp file "/tmp/033e66a25fa9e"
DEBUG: cfFilterGhostscript: Input format: PostScript
DEBUG: Color space requested: Default
DEBUG: Final output format: CUPS Raster
DEBUG: Format of the input document: application/postscript
DEBUG: Document's input format provides absolute size dimensions for each page, using these if no output page size is provided.
DEBUG: Print rendering intent =
DEBUG: Color Manager: Calibration Mode/Off
DEBUG: Color Manager: Invalid printer name.
DEBUG: Color Manager: Invalid input - Unable to find profile.
DEBUG: cfFilterGhostscript: Ghostscript using Any-Part-of-Pixel method to fill paths.
DEBUG: cfFilterGhostscript: Ghostscript command line: gs -dQUIET -dSAFER -dNOPAUSE -dBATCH -dNOINTERPOLATE -dNOMEDIAATTRS -dUsePDFX3Profile -sstdout=%stderr -sOutputFile=%stdout -sDEVICE=pdfwrite -dDoNumCopies -dShowAcroForm -dCompatibilityLevel=1.3 -dAutoRotatePages=/None -dAutoFilterColorImages=false -dNOPLATFONTS -dColorImageFilter=/FlateEncode -dPDFSETTINGS=/default -dColorConversionStrategy=/LeaveColorUnchanged -r300x300 -sOutputICCProfile=srgb.icc -c -f -_
DEBUG: cfFilterGhostscript: Started Ghostscript (PID 13290)
DEBUG: cfFilterGhostscript: Started logging (PID 13291)
DEBUG: cfFilterGhostscript: Input data feed completed
DEBUG: cfFilterGhostscript: Ghostscript (PID 13290) exited with no errors.
DEBUG: cfFilterGhostscript: Logging (PID 13291) exited with no errors.
DEBUG: cfFilterChain: ghostscript completed with status 0.
INFO: cfFilterChain: ghostscript (PID 13286) exited with no errors.

If we link to libcups3 instead by compiling $ cc test.c -lcupsfilters -lcups3 Running the program will result in a segmentation fault.

DEBUG: cfFilterUniversal: Converting from application/postscript to application/pdf
DEBUG: cfFilterUniversal: Final output format for job: application/pdf
Segmentation fault         (core dumped) ./a.out onepage-letter.ps

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the inline test.c program on Ubuntu using the two reported link commands, then compare the libcups2 and libcups3 paths beginning at cfFilterUniversal. Use the supplied debug output to identify where the libcups3 run stops; done means the program no longer segfaults and converts the PostScript input to PDF when linked with libcups3.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux, ubuntu
Domain
backend, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.