Skip to content

Linking with libcups3 causing segfault #151

@NJRoadfan

Description

@NJRoadfan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions