Skip to content

rastertops: bound cupsBytesPerLine before sizing the line buffers - #123

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/rastertops-line-buffer-upper-bound
Nov 23, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix/rastertops-line-buffer-upper-bound

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

Summary

write_flate() sizes its in/out stack buffers from header.cupsBytesPerLine, a field read straight off the incoming raster stream with no validation.

The bug

The existing guard only handled a zero cupsBytesPerLine (defaulting line_bytes to 1); there was no upper bound at all. Worse, line_bytes and the two stack buffers were declared before that guard ran, so by the time the check executed, the stack allocation sized from the raw header value had already happened. A corrupted or malicious raster header with an oversized bytes-per-line value turns into an uncontrolled stack allocation before a single byte of validation occurs.

Fix

Move the validation ahead of the buffer declarations, and reject an unreasonably large cupsBytesPerLine (over 16 MiB) in addition to a zero one.

Test plan

  • Code-traced the full guard-then-declare ordering against current upstream/master; no build environment available locally for this repo to compile-verify.

write_flate() sizes its "in"/"out" stack buffers from
header.cupsBytesPerLine, a field read straight off the incoming raster
stream. The existing zero-guard only defaulted a zero value to 1; it
did nothing for an oversized one, and worse, line_bytes and the two
buffers were declared before any check ran at all, so a corrupted or
malicious raster header with a huge bytes-per-line value sized an
uncontrolled stack allocation before the guard even executed.

Move the validation ahead of the buffer declarations and reject an
unreasonably large value, not just a zero one.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@tillkamppeter
tillkamppeter merged commit 70236f8 into OpenPrinting:master Nov 23, 2026
14 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.

3 participants