Repository navigation
rastertops.c: Fail cleanly on truncated raster row read - #107
Merged
tillkamppeter merged 1 commit intoNov 14, 2026
Merged
tillkamppeter merged 1 commit into
tillkamppeter merged 1 commit into
Conversation
Contributor
Author
|
Hi @tillkamppeter, these are my first PRs to |
In write_flate(), verify non-zero header dimensions and malloc() results, and require cupsRasterReadPixels() to return header.cupsBytesPerLine bytes before compressing each row. On short reads or OOM, free allocated buffers, call deflateEnd(), and return Z_DATA_ERROR or Z_MEM_ERROR so uninitialized heap bytes are never compressed into PostScript output. Also free pixdata on fwrite() error. In ppdFilterRasterToPS(), propagate non-Z_OK status after z_error() and write_end_page() rather than returning 0. Add regression test T51 in ppd/test_ppd_filter.c for a two-page raster stream truncated after page 2's header. Fixes OpenPrinting#86 Signed-off-by: Ronit Mehta <ronitdmehta@gmail.com>
RonitMehta08
force-pushed
the
fix/rastertops-truncated-row-86
branch
from
November 14, 2026 12:33
adba0ba to
ec29df9
Compare
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
Fix truncated CUPS Raster row handling in
ppd/rastertops.cso short pixel reads fail cleanly instead of compressing uninitialized heap memory into PostScript output.Root Cause
write_flate()(ppd/rastertops.c),malloc(header.cupsBytesPerLine)was not checked forNULL, and the return value ofcupsRasterReadPixels(ras, pixdata, header.cupsBytesPerLine)was ignored. When a raster stream was truncated after a page header (or mid-page),pixdataremained uninitialized (under ASan, filled with0xbe) and was compressed straight into the PostScriptFlateDecodestream.header.cupsBytesPerLine == 0could also size stack VLAs to zero.ppdFilterRasterToPS(), non-Z_OKreturns fromwrite_flate()logged viaz_error(), did not callwrite_end_page(), and fell through toreturn (0);.Changes
ppd/rastertops.c:header.cupsBytesPerLine == 0 || header.cupsHeight == 0withZ_DATA_ERRORinwrite_flate()while keeping stack VLAs non-zero (line_bytes).malloc()returns (Z_MEM_ERRORafterdeflateEnd()) and requirecupsRasterReadPixels()to returnheader.cupsBytesPerLinebytes (free(pixdata),deflateEnd(), returnZ_DATA_ERROR).pixdataalongsideconvertedpixonfwrite()failure.ppdFilterRasterToPS(), propagatestatus = 1and callwrite_end_page(&doc)before breaking out of the page loop whenwrite_flate()returns non-Z_OK.ppd/test_ppd_filter.c:ppdFilterRasterToPS()returns non-zero (rc=1) with 0 bytes in Page 2's image stream (using a NUL-safefind_bytes()helper since Page 1 Flate streams contain0x00bytes).Verification
Built and tested on Ubuntu (
CFLAGS="-g -O1 -fsanitize=address,undefined"):ppdFilterRasterToPSreturnedrc=0and wrote 12 zlib bytes inflating to0xbe * 64on Page 2.ppdFilterRasterToPSreturnedrc=1and wrote0bytes into Page 2's image stream.make check):13/13modern test suites (test_ppd_localize,test_ppd_cache,test_ppd_ipp,test_ppd_mark,test_ppd_custom,test_ppd_attr,test_ppd_page,test_ppd_conflicts,test_ppd_emit,test_ppd_filterincludingT51 PASS (rc=1 page2_stream_bytes=0),test_ppd_generator,test_ppd_load_profile,test_ppd_thread) PASS with ASan + UBSan + LSan enabled (0failures).14/14total suites PASS underASAN_OPTIONS=detect_leaks=0 make check(testppdhas pre-existing leak warnings unrelated to this change).Fixes #86