Skip to content

write ktx imageSize field as uint32 not size_t#647

Merged
solidpixel merged 3 commits into
ARM-software:mainfrom
sahvx655-wq:ktx-imagesize-uint32
Jun 19, 2026
Merged

write ktx imageSize field as uint32 not size_t#647
solidpixel merged 3 commits into
ARM-software:mainfrom
sahvx655-wq:ktx-imagesize-uint32

Conversation

@sahvx655-wq

Copy link
Copy Markdown
Contributor

Noticed the .ktx files written by a -dl decode came out four bytes longer than the header plus surface should account for, which is what led me here.

  1. the per-level imageSize is written with file.write(&image_bytes, sizeof(image_bytes)), and image_bytes is now a size_t since the write-buffer sizing was widened, so eight bytes are emitted.
  2. the KTX1 container defines that field as a fixed 32-bit unsigned value, and load_ktx_uncompressed_image reads it straight back as a uint32_t, so the writer disagrees with both the format and our own loader.

The four stray bytes land in front of the surface, so a re-load picks the pixels up from the wrong offset and quietly corrupts the round trip rather than failing cleanly. Narrowed the value to a uint32_t for the serialised field and left the size_t sizing maths alone.

solidpixel
solidpixel previously approved these changes Jun 19, 2026
@solidpixel solidpixel merged commit 8a537ca into ARM-software:main Jun 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants