fix(dds): reject corrupt bytes-per-pixel before it forces a huge allocation#5286
Merged
Merged
Conversation
…cation A DDS file with a garbage pixel-format bpp field (e.g. fmt.bpp ~2.5e9) yields a native bytes-per-pixel (m_Bpp) of hundreds of millions. internal_readimg() then does `new uint8_t[width * m_Bpp]`, a multi-GB allocation that OOMs under the fuzzer's RSS limit. The core resolution/imagesize limits do not catch this: they only see the small output ImageSpec, not the native pixel size, and the existing fmt.bpp check is gated on RGB/LUM/YUV/ALPHA flags that a corrupt header can simply omit. Validate m_Bpp for uncompressed formats right after it is computed in open(): the largest real uncompressed DDS/DXGI pixel is 128-bit (16 bytes), so anything outside [1,16] is a corrupt header and is rejected before any allocation. The check is confined to uncompressed formats because m_Bpp is neither set nor used for compressed (block) formats, which size their data via GetStorageRequirements. Add the fuzzer reproducer as testsuite/dds/src/crash-bpp.dds. crash-1635.dds now reports this error slightly earlier than the prior "bit depth" message; update the reference accordingly. Assisted-by: Claude Code / Claude Opus 4.8 Signed-off-by: Larry Gritz <lg@larrygritz.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.
A DDS file with a garbage pixel-format bpp field (e.g. fmt.bpp ~2.5e9) yields a native bytes-per-pixel (m_Bpp) of hundreds of millions. internal_readimg() then does
new uint8_t[width * m_Bpp], a multi-GB allocation that OOMs. The core resolution/imagesize limits do not catch this: they only see the small output ImageSpec, not the native pixel size, and the existing fmt.bpp check is gated on RGB/LUM/YUV/ALPHA flags that a corrupt header can simply omit.Validate m_Bpp for uncompressed formats right after it is computed in open(): the largest real uncompressed DDS/DXGI pixel is 128-bit (16 bytes), so anything outside [1,16] is a corrupt header and is rejected before any allocation. The check is confined to uncompressed formats because m_Bpp is neither set nor used for compressed (block) formats, which size their data via GetStorageRequirements.
Assisted-by: Claude Code / Claude Opus 4.8