Repository navigation
PluginTARGA: bound RLE decode by image rows (CVE-2024-28581) - #215
Merged
Merged
Conversation
loadRLE's per-packet dib_end check assumes a flat address model, but pixel rows wrap at line_size while the image only has height rows. An over-long RLE packet whose flat span fits dib_end can still wrap past the last row, overflowing the heap in _assignPixel (WRITE, all depths). Stop the decode with a corruption notice once pixels run past the last row; the check sits at the top of the pixel loop so packets ending exactly on the last pixel still exit cleanly. Also harden the same path: load 16/32-bit cache pixels with memcpy (the RLE byte cache is file-offset aligned, not 2/4-aligned; UBSan misaligned-load on crafted and valid files), and zero-fill short IOCache refills at EOF so stale heap bytes never surface in pixels. RED (ASan+UBSan, pre-fix) -> GREEN (post-fix) verified with Ruanxingzhi/vul-report freeimage-r1909 cases 10024/10412/10470 plus a guard-isolating crafted TGA; valid 8/16/24/32-bit RLE TGAs still decode pixel-identically. AI assistance disclosure: this patch was authored with AI assistance (agentic coding CLI) and verified with AddressSanitizer/UBSan red/green runs before submission.
Owner
|
Thank you will run analysis
…On Tue, 27 Oct 2026 at 1:42 pm, w4ffl35 ***@***.***> wrote:
Root cause (CVE-2024-28581
<https://github.com/advisories/GHSA-5vqc-63mj-rggw>)
loadRLE<N> checks each packet once against dib_end assuming a flat
address model, but pixel rows wrap at line_size while the image only has
height rows. An over-long RLE packet whose flat span still fits dib_end
(e.g. exact-fit, where padding makes pitch > line_size) wraps past the
last row mid-packet and overflows the heap on the next _assignPixel
write. ASan pre-fix: heap-buffer-overflow ... in _assignPixel<8> via
loadRLE<8>.
Fix
- Stop the decode with the established FI_MSG_ERROR_CORRUPTED path
once pixels run past the last row (y >= height, checked at the top of
each pixel iteration so exact-fit packets still exit cleanly, returning the
completed bitmap).
- Same-path hardening: 16/32-bit cache pixels are loaded with memcpy
(the RLE byte cache is file-offset aligned, not 2/4-aligned; UBSan
misaligned-load fired even on valid 32-bit RLE files), and short
IOCache refills at EOF are zero-filled so stale heap bytes never
surface in decoded pixels.
Verification (ASan+UBSan, serial build)
- RED pre-fix / GREEN post-fix: Ruanxingzhi/vul-report freeimage-r1909
cases 10024/10412 (WRITE overflow), 10470 (misaligned WORD load),
10421/10955/10800 (READ variants), plus a crafted 66-byte guard-isolating
TGA whose flat span exactly fits dib_end.
- No regressions: valid 8/16/24/32-bit RLE TGAs (incl. flip flags,
header-only mode, exact-fit packets) decode pixel-identically with zero
sanitizer findings.
- Related CVE-2025-70968
<https://github.com/advisories/GHSA-m37w-3x8g-3vw4> (TARGA UAF)
verified already-fixed on master (`loadRLE(FIBITMAP*&)" + NULL-safe flips);
its PoC (flip flags set) returns clean NULL. No change needed for it.
PoC repos used as reproducers only, never as patch sources.
AI assistance disclosure: this patch was authored with AI assistance
(agentic coding CLI) and verified with AddressSanitizer/UBSan red/green
runs before submission.
------------------------------
You can view, comment on, or merge this pull request online at:
#215
Commit Summary
- 2124a26
<2124a26>
PluginTARGA: bound RLE decode by image rows (CVE-2024-28581)
File Changes
(1 file <https://github.com/danoli3/FreeImage/pull/215/files>)
- *M* Source/FreeImage/PluginTARGA.cpp
<https://github.com/danoli3/FreeImage/pull/215/files#diff-cb1c60d6f85246f16217922604fdd3bf9fe9304af189ce67a57cdad5d9fe48e6>
(55)
Patch Links:
- https://github.com/danoli3/FreeImage/pull/215.patch
- https://github.com/danoli3/FreeImage/pull/215.diff
—
Reply to this email directly, view it on GitHub
<#215?email_source=notifications&email_token=AAGK2HB3MSJXIPJECO6QMSD5WADQBA5CNFSNUABEM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UF42TAMRXG42TMMBYGWTHEZLBONXW5KTTOVRHGY3SNFRGKZFFMV3GK3TUVRTG633UMVZF6Y3MNFRWW>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGK2HHKSLRVNM72IUCKC4D5WADQBAVCNFSNUABEKJSXA33TNF2G64TZHMZDGNRUHE2TQNJ3JFZXG5LFHM3DANJRHA4DQOJQG6QXMAQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Owner
|
Reviewed against current
Nits, non-blocking:
Verdict: approve once CI is green. |
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.
Root cause (CVE-2024-28581)
loadRLE<N>checks each packet once againstdib_endassuming a flat address model, but pixel rows wrap atline_sizewhile the image only hasheightrows. An over-long RLE packet whose flat span still fitsdib_end(e.g. exact-fit, where padding makespitch > line_size) wraps past the last row mid-packet and overflows the heap on the next_assignPixelwrite. ASan pre-fix:heap-buffer-overflow ... in _assignPixel<8>vialoadRLE<8>.Fix
FI_MSG_ERROR_CORRUPTEDpath once pixels run past the last row (y >= height, checked at the top of each pixel iteration so exact-fit packets still exit cleanly, returning the completed bitmap).memcpy(the RLE byte cache is file-offset aligned, not 2/4-aligned; UBSan misaligned-load fired even on valid 32-bit RLE files), and shortIOCacherefills at EOF are zero-filled so stale heap bytes never surface in decoded pixels.Verification (ASan+UBSan, serial build)
freeimage-r1909cases 10024/10412 (WRITE overflow), 10470 (misaligned WORD load), 10421/10955/10800 (READ variants), plus a crafted 66-byte guard-isolating TGA whose flat span exactly fitsdib_end.PoC repos used as reproducers only, never as patch sources.
AI assistance disclosure: this patch was authored with AI assistance (agentic coding CLI) and verified with AddressSanitizer/UBSan red/green runs before submission.