fix(pdftoraster): OOB read and NULL-ptr write in write_page_image()#146
Open
kimaiden1984-boop wants to merge 1 commit intoOpenPrinting:masterfrom
Open
fix(pdftoraster): OOB read and NULL-ptr write in write_page_image()#146kimaiden1984-boop wants to merge 1 commit intoOpenPrinting:masterfrom
kimaiden1984-boop wants to merge 1 commit intoOpenPrinting:masterfrom
Conversation
Fix two bugs introduced by commit 0ad5d2a ("fix padding issue") in the write_page_image() function when the rendered PDF image is smaller than the output page: 1. Heap-buffer-overflow READ (CVE candidate): The forward copy loop used h <= copy_height instead of h < copy_height, causing one extra row iteration past the allocated colordata buffer. The OOB data flows through lcms2 color conversion into the CUPS raster output. 2. NULL-ptr WRITE (DoS): Unconditional memset(lineBuf, ...) without checking doc->allocLineBuf. When select_special_case() sets allocLineBuf=false (14 color spaces), lineBuf is NULL and the memset crashes with SEGV. The reverse/duplex loop condition h <= copy_height is correct because h descends from page_height to 1, so h == copy_height processes the last valid row (index copy_height-1) with no subsequent OOB read. A self-contained unit test is added that validates both fixes across 5 scenarios (image<page, image==page, image>page, image=0 edge case, allocLineBuf=false) for both forward and reverse loops. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Fix two memory safety bugs introduced by commit 0ad5d2a ("fix padding issue") in the
write_page_image()function, which trigger when the rendered PDF image is smaller than the output page:h <= copy_heightinstead ofh < copy_height, causing one extra row iteration past the allocatedcolordatabuffer. This OOB data flows through lcms2 color conversion and leaks into the CUPS raster output.memset(lineBuf, ...)was called without checkingdoc->allocLineBuf. Whenselect_special_case()setsallocLineBuf=false(affecting 14 color spaces),lineBufis NULL and thememsetcauses a SEGV crash.(Note: The reverse/duplex loop condition
h <= copy_heightat line 1981 remains unchanged. It is correct becausehdescends frompage_heightto1, meaningh == copy_heightprocesses the last valid row at indexcopy_height - 1with no subsequent OOB read.)Testing Performed:
Added a self-contained unit test that validates both fixes across 5 scenarios for both forward and reverse loops:
image < pageimage == pageimage > pageimage = 0(edge case)allocLineBuf = false