use size_t for slice size when packing array slices#641
Merged
solidpixel merged 1 commit intoJun 9, 2026
Conversation
solidpixel
approved these changes
Jun 9, 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.
When packing a 3D image from a set of 2D slices, load_uncomp_file() reads each slice's dimensions from its file header and works out the per-plane copy length as
slice_size * 4, with slice_size held in a plain int. dim_x and dim_y come straight from the KTX/DDS/PNG slice headers, so they are untrusted; once a slice reaches around 24576x24576 the dim_x*dim_y product still fits an int butslice_size * 4overflows the signed type, and the negative intermediate is promoted to a size_t close to SIZE_MAX before it reaches memcpy. I spotted this auditing the array path after the recent alloc_image size_t change: the destination plane is now allocated at its true 64-bit size while the copy length wraps, which is the usual heap-overflow signature.Holding slice_size as a size_t keeps the byte maths in 64-bit and lines the copy length up with the width alloc_image already uses for the same plane. Keeping the calculation here, beside the slice load and the plane allocation, means the packer does not rely on each loader having pre-checked the texel count first. Left as is, a crafted set of large slices walks a memcpy off the end of both the source slice and the destination plane on an ordinary -array load.