Skip to content

rastertopclx: check the row end before reading in CompressData - #807

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
Sharadhi-v98:rastertopclx-compress-bounds-order
Nov 18, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
Sharadhi-v98:rastertopclx-compress-bounds-order

Conversation

@Sharadhi-v98

Copy link
Copy Markdown
Contributor
  1. In CompressData() the mode 3 loop that collects up to 8 non-matching bytes tests *line_ptr != *seed before line_ptr < line_end, and both mode 10 RGB tuple scans read line_ptr[0..2] / seed[0..2] before (line_ptr + 2) < line_end. Whenever a run reaches the end of the row (or the row length is not a multiple of 3 in mode 10), the filter reads 1 to 3 bytes past PixelBuffer (or the dot buffer) and SeedBuffer, both exact-size heap allocations.
  2. cupsCompression comes from the job's page header, so this happens on ordinary pages of any mode 3 or mode 10 job. ASan, running the function on a 5-byte (mode 3) or 6-byte (mode 10) row: heap-buffer-overflow ... READ of size 1 ... 0 bytes after 5-byte region at each of the three loops.
  3. Moved the bounds test to the front of each condition. Because && short-circuits, the output is unchanged for in-bounds data: a differential run of the old and new function over 300k random rows (modes 0/1/2/3/10, gray and RGB, valid and invalid seed) gave zero output mismatches.

The mode 1, mode 2 and gray mode 10 loops already test the bound first, and rastertoescpx only has the PackBits path, which is fine.

The mode 3 loop that collects non-matching bytes and both mode 10 RGB
tuple scans dereferenced line_ptr and seed before testing them against
line_end, so a run reaching the end of the row read up to 3 bytes past
the row and seed buffers. Test the bound first.
@tillkamppeter
tillkamppeter merged commit 03d2056 into OpenPrinting:master Nov 18, 2026
10 of 11 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