Fix heap-buffer-overflow write in CUT RLE parser#40
Open
JorgeBarredo14 wants to merge 1 commit intodanoli3:masterfrom
Open
Fix heap-buffer-overflow write in CUT RLE parser#40JorgeBarredo14 wants to merge 1 commit intodanoli3:masterfrom
JorgeBarredo14 wants to merge 1 commit intodanoli3:masterfrom
Conversation
When decompressing a CUT (Dr. Halo) format image, a zero-count byte in the RLE stream causes the scanline pointer to be decremented (bits -= pitch) without verifying that the pointer remains within the allocated bitmap. If the header declares height=1 but the RLE data contains multiple zero-count markers, the pointer underflows below the heap allocation, leading to an out-of-bounds write via the subsequent memset or read_proc call. Add a bounds check before the decrement to ensure the pointer does not move past the first scanline. CWE-787 (Out-of-bounds Write) Found during academic security research.
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
The CUT (Dr. Halo) format parser allocates a bitmap from the file header (
width * height). During RLE decompression, a zero-count byte triggersbits -= pitchto move to the previous scanline. If the header declaresheight=1but the RLE data contains multiple zero-count markers, the scanline pointer underflows below the heap allocation, causing an out-of-bounds write on the subsequentmemsetorread_proccall.Root cause
PluginCUT.cppline 169:bits -= pitch;— no check thatbitsremains within the allocated bitmap before decrementing.Fix
Add a bounds check before the decrement: verify that
bitsis at leastpitchbytes above the start of the bitmap data. If not, break out of the decompression loop.Metadata
width=0x230B,height=0x0001(available on request)memcpyatPluginCUT.cpp:193, triggered by_MemoryReadProc