use size_t for dds and ktx surface size to avoid overflow#626
Merged
Conversation
Contributor
|
Thanks for the PR - will review in the next few days. |
Contributor
|
I've refactored the overflow checks into common library functions in #628, which should simplify the added code here. Will rebase this after the other PR has merged. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the CLI’s uncompressed KTX and DDS loaders against crafted headers that previously triggered uint32_t truncation during surface-size computation, leading to undersized allocations and out-of-bounds heap reads during scanline copies.
Changes:
- Switch KTX and DDS surface size/stride computation to
size_twithastc::mul_safe()overflow detection and reject inconsistent or overflowing sizes. - Update related local fields (
components,bitness,bytes_per_component, and DDS DXGI table fields) to unsigned types. - Improve DDS robustness by handling allocation failure for the input surface buffer and updating stride-based source addressing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
Existing issues spotted while reviewing, I'll pick up in follow-on PRs for these:
|
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.
Fuzzing the image loaders with crafted KTX and DDS headers turned this up. The surface size in load_ktx_uncompressed_image and load_dds_uncompressed_image is computed in uint32_t, so large width/height/depth truncate the byte count and the buffer is allocated too small while the scanline copy still walks the full dimensions, reading off the end of the heap. The KTX size check is bypassed by setting the stored surface size to the truncated value. Same shape as the recent .astc fix, so compute in size_t and reject on overflow here too.