Skip to content

imagetops-pstops: fix off-by-one in doc_printf truncation check - #127

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-imagetops-pstops-doc-printf-truncation-v2
Nov 29, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-imagetops-pstops-doc-printf-truncation-v2

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

vsnprintf() returns the number of characters that would have been written for a big-enough buffer, not counting the terminator. When a single doc_printf() call formats exactly sizeof(buffer) characters, bytes > sizeof(buffer) is false, so the truncation branch is skipped and doc_write() is told to emit all 1024 bytes of buffer — including the NUL terminator vsnprintf left at buffer[1023] in place of the real (dropped) last character. That NUL ends up embedded in the generated PostScript stream.

Use >= for the check and drop only the terminator byte, not one more character of real content, when truncating.

Verified by building libppd from this branch against current upstream libcupsfilters and PDFio, running make check: 14/14 tests pass, 0 failures.

vsnprintf() returns the number of characters that would have been
written for a big-enough buffer, not counting the terminator. When a
single doc_printf() call formats exactly sizeof(buffer) characters,
"bytes > sizeof(buffer)" is false, so the truncation branch is
skipped and doc_write() is told to emit all 1024 bytes of "buffer" -
including the NUL terminator vsnprintf left at buffer[1023] in place
of the real (dropped) last character. That NUL ends up embedded in
the generated PostScript stream. Use >= for the check and drop only
the terminator byte, not one more character of real content, when
truncating.
@tillkamppeter
tillkamppeter merged commit e7ae7ce into OpenPrinting:master Nov 29, 2026
7 of 15 checks passed
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