CVE-2020-22524 - Fix integer overflow leading to undersized allocation in PFM loader - #56
Merged
Merged
Conversation
…VE-2020-22524) Load() computed the RLE/pixel line buffer size as `const unsigned lineWidth = 3 * width;` (RGBF) or `= width;` (FLOAT), where width is an int read directly from the PFM header with no upper bound (only `width <= 0` is rejected). For the RGBF case in particular, `3 * width` is evaluated as a 32-bit signed int multiply before being stored into lineWidth, so a sufficiently large width (~715M+) silently overflows and wraps to a small value. malloc(lineWidth * sizeof(float)) then succeeds with a buffer far smaller than the real per-scanline size, while the pixel-unpacking loop right below it still iterates `for (x = 0; x < width; x++)` against the original, un-overflowed width - reading/writing past the end of that undersized lineBuffer. Compute lineWidth in size_t instead, so the multiply can't overflow before it reaches malloc(); genuinely unreasonable widths now just fail malloc() cleanly, which Load() already handles via the existing `if(!lineBuffer) throw FI_MSG_ERROR_MEMORY` check. CWE-190 (Integer Overflow) leading to CWE-787/CWE-125 (Out-of-bounds Write/Read) Fixes: CVE-2020-22524
The previous commit's edit was re-serialized as UTF-8, corrupting the file's original ISO-8859-1 "Hervé Drolon" byte sequence into a replacement character. Restore it by converting the original file to UTF-8 properly rather than accidentally.
danoli3
force-pushed
the
fix/pfm-overflow-allocation
branch
from
August 16, 2026 08:29
d3bbac1 to
6ac71b4
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.
Load()computed the PFM line buffer size as3 * width(int/unsigned), wherewidthcomes straight from the file header with only a<= 0check — no upper bound. Past ~715M,3 * widthoverflows the 32-bit multiply and wraps small, somalloc()undersizeslineBufferwhile the unpack loop right below still iterates the original, un-overflowedwidth— reading/writing past the end of it.Computes the line width in
size_tinstead, so the multiply can't overflow before it reachesmalloc().Fixes: CVE-2020-22524