Skip to content

fix raster over-read on undersized media in ipptransform - #191

Open
tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:ipptransform-margin-underflow
Open

tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:ipptransform-margin-underflow

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor
  1. pcl_start_page and ps_start_page build the page margins by subtracting a fixed 1/4" (PCL) or 1/6" (PostScript) margin from cupsWidth/cupsHeight into unsigned fields. When the media is smaller than twice that margin the subtraction wraps around, so right and bottom become ~4 billion.
  2. dither_gray/pack_* read right - left pixels per line and the band loop iterates bottom - top rows, so both then run far past the band buffer.

The media size is attacker-reachable: ippeveprinter and the rest of the IPP Everywhere path pass the job's media, including small custom and roll sizes, straight to this filter. On a sanitizer build it is a heap-buffer-overflow READ (adjacent heap bytes end up in the output raster):

$ tools/ipptransform -m application/vnd.hp-pcl -o media=custom_x_5x80mm -r 300dpi -t black_1 examples/document-letter.pdf >/dev/null
==ERROR: AddressSanitizer: heap-buffer-overflow ... in dither_gray ipptransform.c:1671
$ tools/ipptransform -m application/postscript -o media=custom_x_5x80mm -r 300dpi -t sgray_8 examples/document-letter.pdf >/dev/null
==ERROR: AddressSanitizer: heap-buffer-overflow ... in ps_write_line ipptransform.c:3047

Dropping a margin to zero when the page is too small to hold it keeps the computation in range; output for normal media is byte-identical. Added a tiny-media transform to run-tests.sh that aborts on the unpatched tree under the address sanitizer the CI already uses.

@michaelrsweet michaelrsweet self-assigned this Oct 22, 2026
@michaelrsweet michaelrsweet added the investigating Investigating the issue label Oct 22, 2026

@michaelrsweet michaelrsweet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will consider, needs cleanup for coding style. Also, no need for a long-term unit test for this and we prefer to write up the changelog entries...

@michaelrsweet michaelrsweet added bug Something isn't working priority-low and removed investigating Investigating the issue labels Oct 22, 2026
@michaelrsweet michaelrsweet added this to the Stable milestone Oct 22, 2026
pcl_start_page and ps_start_page subtract a fixed 1/4" or 1/6" margin
from the unsigned cupsWidth/cupsHeight, which wraps around when the media
is smaller than twice the margin so right/bottom become ~4 billion and the
per-line and band-row counts run past the raster buffer.  Drop a margin to
zero when the page is too small to hold it so the subtraction stays in
range.
@tanjiroK-coder
tanjiroK-coder force-pushed the ipptransform-margin-underflow branch from e4db51e to ec05a00 Compare October 23, 2026 07:50
@tanjiroK-coder

Copy link
Copy Markdown
Contributor Author

Cleaned up the coding style and dropped the test, now just the margin fix in pcl_start_page/ps_start_page. Left the changelog out for you to write up.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority-low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants