Skip to content

fix(iff): detect corrupt chunk sizes, flags, channel configs - #5268

Merged
lgritz merged 2 commits into
AcademySoftwareFoundation:mainfrom
lgritz:lg-iffchunk
Jul 2, 2026
Merged

fix(iff): detect corrupt chunk sizes, flags, channel configs#5268
lgritz merged 2 commits into
AcademySoftwareFoundation:mainfrom
lgritz:lg-iffchunk

Conversation

@lgritz

@lgritz lgritz commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Detect and reject corrupt chunk sizes, flags, and channel configurations in the header.

Assisted-by: Claude Code / Claude Opus 4.8

lgritz added 2 commits June 27, 2026 19:30
Detect and rejecct corrupt chunk sizes, flags, and channel
configurations in the header.

Assisted-by: Claude Code / Claude Opus 4.8

Signed-off-by: Larry Gritz <lg@larrygritz.com>
A crafted Maya IFF with the TBHD ZBUFFER flag set but RGBA clear took the
ZBUFFER-only branch, which set rgba_count=1/rgba_bits=32 while leaving
zbuffer=0. open() then exposed the image as 1-channel UINT16 (so callers
size their tile buffer from ImageSpec::tile_bytes(true)), but the internal
pixel_bytes() stayed 32-bit. read_native_tile() copied by the internal
pixel size, writing past the smaller caller buffer -- a heap out-of-bounds
write.

Such files can never be decoded anyway: readimg()'s tile loop only handles
8- and 16-bit RGBA pixels and explicitly errors on 32-bit. So reject
ZBUFFER-only headers at open() instead of fabricating an inconsistent spec.

Also:
- Generalize the channel-config check to require rgba_count in {3,4}, which
  additionally rejects headers with no color flags at all.
- Clear m_buf when readimg() fails. readimg() resizes m_buf before decoding,
  so a partial/failed decode left a non-empty buffer that a later tile
  request would reuse, skipping the (failed) decode and copying stale data.

Adds regression test src/zbuffer_only.iff.

Assisted-by: Claude Code / Claude Opus 4.8

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz

lgritz commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

I have amended this PR to handle an additional related case.

@mikaelsundell mikaelsundell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Z-only Maya depth files may exist and could be handled in a separate PR with a real .z sample and dedicated tests. Let me see what I can do about that.

@lgritz

lgritz commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Did we support it before?

If we never supported it properly, let's let this stand and we'll come back to it.
But if this PR is breaking z-only support, I can try to rework the PR.

@mikaelsundell

Copy link
Copy Markdown
Contributor

My code was broken, I suggest we move on, let me prepare a new PR
on top of this to properly deal with .z iff files?

@lgritz

lgritz commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

OK, but actually, maybe wait until I get some more PRs submitted. I have more iff ones in flight, so let's let the security bug fixes settle down before adding support for things that never worked. If it didn't work before and nobody complained, there can't be much of a rush.

@lgritz
lgritz merged commit 9cda48b into AcademySoftwareFoundation:main Jul 2, 2026
28 checks passed
@lgritz
lgritz deleted the lg-iffchunk branch July 2, 2026 16:10
@mikaelsundell

mikaelsundell commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Thats cool, it may have worked but never properly tested or validated. Need to create a sample file in Maya so no stress 👍🏻

lgritz added a commit that referenced this pull request Jul 15, 2026
Detect and reject corrupt chunk sizes, flags, and channel configurations
in the header.

Assisted-by: Claude Code / Claude Opus 4.8

---------

Signed-off-by: Larry Gritz <lg@larrygritz.com>
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Jul 15, 2026
…SoftwareFoundation#5268)

Detect and reject corrupt chunk sizes, flags, and channel configurations
in the header.

Assisted-by: Claude Code / Claude Opus 4.8

---------

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz

lgritz commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

CVE-2026-63419

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