Skip to content

pdftops: fix the printer make and model used for quirks - #97

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
Ar-maan05:pdftops-make-model
Nov 2, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
Ar-maan05:pdftops-make-model

Conversation

@Ar-maan05

Copy link
Copy Markdown
Contributor

two small bugs in how ppdFilterPDFToPS() works out the make and model it uses for printer quirks.

before/after from a small harness calling the filter:

printer-make-and-model "Hewlett-Packard LaserJet 4000"
before: Printer make and model: HP
after:  Printer make and model: HP LaserJet 4000

PPD with no *Product line
before: SEGV on address 0x1 in snprintf, from pdftops.c:462
after:  Printer make and model: (empty)

PPD with *Product: ""
before: ASan heap-buffer-overflow in snprintf
after:  Printer make and model: (empty)

the first one is strncpy(make, "HP", sizeof(make)) padding the whole buffer with NULs, which also clears the model becuase model points into that same buffer. So those printers never matched the HP LaserJet checks further down. The other two come from using ppd->product + 1 without checking it's there.

the fix writes only the 3 bytes of "HP" and skips the PPD branch when there's no usable manufacturer or product. An empty make and model is already handled by the code below.

tested with ASan and UBSan using that harness. I didn't add a repo test since the filter goes on to run a renderer, happy to add one if you have a preference for how.

For a printer-make-and-model starting with "Hewlett-Packard " or "Hewlett Packard ", strncpy(make, "HP", sizeof(make)) pads the rest of the buffer with NULs, which wipes the model it was about to use. "Hewlett-Packard LaserJet 4000" came out as "HP ", so the HP LaserJet quirks never matched. Write just "HP" and its terminator instead.

In the PPD case, ppd->product is only set if the PPD has a *Product line, so without one ppd->product + 1 crashes, and an empty *Product reads past the end of the string. Leave the make and model empty in those cases, the code after it already handles that.
@tillkamppeter
tillkamppeter merged commit 804aeac into OpenPrinting:master Nov 2, 2026
15 checks passed
@Ar-maan05
Ar-maan05 deleted the pdftops-make-model branch November 2, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants