Skip to content

check object header message size after decoding its header - #6589

Open
naruto-lgtm wants to merge 4 commits into
HDFGroup:developfrom
naruto-lgtm:ohdr-message-size-bound
Open

check object header message size after decoding its header#6589
naruto-lgtm wants to merge 4 commits into
HDFGroup:developfrom
naruto-lgtm:ohdr-message-size-bound

Conversation

@naruto-lgtm

Copy link
Copy Markdown
Contributor

Describe your changes

Repro: open a file whose object header holds a message that declares a body reaching the end of its chunk, where the tail of the message header sits in those last bytes. Issue #6401 has a fuzzer PoC for it. By hand it is a version 1 header with a 12 byte chunk 0, one mtime message declaring an 8 byte body, and only 4 bytes left after the 8 byte message header.
Cause: H5O__chunk_deserialize() compares mesg_size against p_end while chunk_image still points at the flags byte, so the flags plus reserved bytes (version 1) or flags plus creation index (version 2) that follow are not counted. The body begins up to four bytes further into the chunk than the check assumed, and mesg->raw / mesg->raw_size then describe a region ending past the chunk image.
Fix: run the same check once the whole message header has been decoded, against the pointer that actually becomes the message body.

Every message class builds its own p_end from raw and raw_size, so this is not specific to mtime. Whichever decoder the type byte selects gets handed a buffer end outside the allocation, which is why the check belongs in the chunk loop rather than in the individual decoders, where the chunk image bound is not known.

On the unpatched library ASan reports a heap-buffer-overflow read at H5Omtime.c:137 from H5Ocache.c:1475, 0 bytes past the chunk image, and is clean afterwards. The trailing image size check rejects the file either way, so the new case in test/ohdr.c earns its keep under a sanitizer or valgrind, the same way test_ohdr_badness() above it does.

Issue ticket number (GitHub or JIRA)

#6401

Checklist before requesting a review

  • My code conforms to the guidelines in CONTRIBUTING.md
  • I made an entry in release_docs/CHANGELOG.md (bug fixes, new features)
  • I added a test (bug fixes, new features)

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Checklist

This PR touches the following areas. Each needs a sign-off
from its listed owners before merging.

hyoklee
hyoklee previously approved these changes Aug 4, 2026
Comment thread release_docs/CHANGELOG.md Outdated

### Fixed a heap buffer overflow when decoding object header messages

The size stored in an object header message header was checked against the chunk before the rest of that message header was decoded, so the check allowed a message body to start up to four bytes further into the chunk than the check accounted for. A corrupted or fuzzed file could declare a size that passed the check and still ran past the end of the chunk image, and the message's decode callback was then handed a buffer end outside the allocation. `H5O__chunk_deserialize()` now checks the message size once the whole message header has been decoded.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so the check allowed -> allowing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, reworded to "allowing".

vchoi-hdfgroup
vchoi-hdfgroup previously approved these changes Aug 4, 2026
@lrknox
lrknox dismissed stale reviews from vchoi-hdfgroup and hyoklee via 40c879d August 4, 2026 20:56
hyoklee
hyoklee previously approved these changes Aug 4, 2026
hyoklee
hyoklee previously approved these changes Aug 6, 2026
Comment thread release_docs/CHANGELOG.md Outdated

### Fixed a heap buffer overflow when decoding object header messages

The size stored in an object header message header was checked against the chunk before the rest of that message header was decoded, allowing a message body to start up to four bytes further into the chunk than the check accounted for. A corrupted or fuzzed file could declare a size that passed the check and still ran past the end of the chunk image, and the message's decode callback was then handed a buffer end outside the allocation. `H5O__chunk_deserialize()` now checks the message size once the whole message header has been decoded.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ran -> extended

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, switched to extended.

Signed-off-by: Nayyar <nayyar@bugqore.com>
@github-actions
github-actions Bot requested a review from hyoklee August 8, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To be triaged

Development

Successfully merging this pull request may close these issues.

5 participants