Repository navigation
rastertops: bound cupsBytesPerLine before sizing the line buffers - #123
Merged
tillkamppeter merged 1 commit intoNov 23, 2026
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
write_flate()sizes itsin/outstack buffers fromheader.cupsBytesPerLine, a field read straight off the incoming raster stream with no validation.The bug
The existing guard only handled a zero
cupsBytesPerLine(defaultingline_bytesto 1); there was no upper bound at all. Worse,line_bytesand 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