fix out-of-bounds write in store_dds_uncompressed_image for 3d ldr#643
Merged
solidpixel merged 3 commits intoJun 13, 2026
Merged
Conversation
solidpixel
previously approved these changes
Jun 13, 2026
solidpixel
approved these changes
Jun 13, 2026
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.
While checking the uncompressed DDS writer against the KTX one I noticed the LDR plane pointer in store_dds_uncompressed_image is advanced by dim_y * dim_z * image_components per slice, where a plane is actually dim_x * dim_y * image_components. The 16-bit branch in the same function, and both branches of the KTX writer, use dim_x, so this is a stray dim_z. For any 3D image whose depth is larger than its width the per-slice base pointer lands past the end of the pixel_data8 buffer and the scanline copy then writes over the heap. It is reachable when decoding a 3D LDR .astc straight to .dds, or when saving a 3D image array as .dds.
AddressSanitizer reports a heap write one byte past the pixel buffer on a 4x4x8 LDR image, traced back to this slice loop; with the stray dim_z swapped back to dim_x every plane pointer sits inside the buffer and the writer round-trips cleanly. The bound belongs in the writer because the buffer being indexed is the one this function allocates from the same dimensions, so a caller has no way to correct a stride computed internally.