Fix NULL pointer dereferences in H5HL_protect and H5HL_unprotect - #6377
Open
tbeu wants to merge 7 commits into
Open
Fix NULL pointer dereferences in H5HL_protect and H5HL_unprotect#6377tbeu wants to merge 7 commits into
tbeu wants to merge 7 commits into
Conversation
tbeu
requested review from
bmribler,
brtnfld,
fortnern,
glennsong09,
jhendersonHDF,
mattjala,
qkoziol and
vchoi-hdfgroup
as code owners
April 21, 2026 17:32
Collaborator
Contributor
Author
|
The issue occurs with corrupted HDF5 files on fuzzing. It is not possible to detect / prevent the error outside hdf5, i.e. as consumer of hdf5 lib. |
tbeu
force-pushed
the
fix/H5HL-null-deref
branch
from
April 28, 2026 18:39
29146df to
59ff4be
Compare
tbeu
force-pushed
the
fix/H5HL-null-deref
branch
3 times, most recently
from
May 7, 2026 19:16
929f097 to
4b735bd
Compare
tbeu
force-pushed
the
fix/H5HL-null-deref
branch
2 times, most recently
from
May 18, 2026 21:15
5fecc19 to
60538fa
Compare
tbeu
force-pushed
the
fix/H5HL-null-deref
branch
2 times, most recently
from
June 10, 2026 17:03
5aad41a to
12c3822
Compare
lrknox
removed their request for review
June 11, 2026 21:20
tbeu
force-pushed
the
fix/H5HL-null-deref
branch
from
June 16, 2026 18:01
12c3822 to
a0db16d
Compare
Contributor
|
This pull request has had no activity for 30 days and has been marked stale. Push a commit or comment to keep it open, or it will be flagged for maintainer review. |
Collaborator
|
Hi @tbeu, how would you like to proceed with this PR? |
mattjala
reviewed
Aug 12, 2026
mattjala
requested changes
Aug 12, 2026
mattjala
left a comment
Contributor
There was a problem hiding this comment.
In addition to my other comments, this should include a regression test case using the file from the OSS report and a CHANGELOG.md entry describing the problem that was fixed.
When reading corrupted HDF5 files, H5HL_protect can encounter a heap where prfx->heap is NULL or heap->dblk_image is NULL. Similarly, H5HL_unprotect can encounter a heap where heap->prfx or heap->dblk has been set to NULL by H5HL__prfx_dest during cache eviction of corrupted entries. In both cases, the code proceeded to dereference NULL pointers, causing a segfault (found by OSS-Fuzz via matio). Replace the assert in H5HL_unprotect with proper NULL checks and HGOTO_ERROR, and add equivalent guards in H5HL_protect, so corrupted files are rejected gracefully instead of crashing.
…sion test + changelog - Remove the NULL checks in H5HL_protect for prfx->heap and heap->dblk_image. prfx->heap is set in H5HL__prfx_new and only cleared in H5HL__prfx_dest (which frees the prefix in the same call), so the check is unreachable and could leak prfx via the done block. heap->dblk_image is NULL by design whenever the data block is not contiguous with the prefix, so that check was a false positive. - Keep the H5HL_unprotect NULL checks for heap->prfx and heap->dblk, which are the actual fix for the reported crash (OSS-Fuzz 504827191). - Add a regression test (corrupt_heap_unprotect) in test/lheap.c using the minimized fuzzer file heap_corrupt_prfx.h5, asserting the corrupted file fails gracefully instead of crashing in H5HL_unprotect. - Document the fix in release_docs/CHANGELOG.md.
Replace the file-based traversal (which does not deterministically reach the cache-eviction path that nulls heap->prfx) with a white-box check that protects a local heap, simulates the corrupted/evicted condition by nulling the heap's prfx/dblk pointers, and verifies H5HL_unprotect() returns an error instead of dereferencing NULL. Keep a best-effort open/traverse of the OSS-Fuzz minimized file (issue 504827191) as a smoke test. Verified: without the fix the test aborts (H5AC_unpin_entry(NULL)); with the fix it passes.
tbeu
force-pushed
the
fix/H5HL-null-deref
branch
from
August 16, 2026 07:26
05ee0fa to
ecdc3cb
Compare
Contributor
Author
|
Review remarks are addressed. |
Contributor
Author
|
It has been published meanwhile. |
mattjala
reviewed
Aug 17, 2026
mattjala
reviewed
Aug 17, 2026
mattjala
reviewed
Aug 17, 2026
mattjala
reviewed
Aug 17, 2026
mattjala
reviewed
Aug 17, 2026
mattjala
reviewed
Aug 17, 2026
mattjala
reviewed
Aug 17, 2026
mattjala
reviewed
Aug 17, 2026
mattjala
reviewed
Aug 17, 2026
mattjala
requested changes
Aug 17, 2026
mattjala
reviewed
Aug 18, 2026
mattjala
reviewed
Aug 18, 2026
- Use H5L_info2_t in visitor (matches H5L_iterate2_t signature) - Use H5O_info2_t with H5Oget_info_by_name3 - Replicate matio's exact traversal: H5Literate2 + H5Gopen2/H5Dopen2 + H5Lvisit2 recursion, H5Aiterate2 attribute reads, skip #refs#/#subsystem# - Keep white-box deterministic NULL-pointer guard (fuzzer file does not deterministically crash via public API alone; original crash required matio fuzzer's specific cache-pressure environment) - Add CORRUPT_HEAP_TESTFILE define back for white-box test
tbeu
force-pushed
the
fix/H5HL-null-deref
branch
from
August 19, 2026 04:47
1c479d2 to
cd5a632
Compare
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 reading corrupted HDF5 files,
H5HL_protectcan encounter a heap whereprfx->heapis NULL orheap->dblk_imageis NULL. Similarly,H5HL_unprotectcan encounter a heap whereheap->prfxorheap->dblkhas been set to NULL byH5HL__prfx_destduring cache eviction of corrupted entries.In both cases the code proceeded to dereference NULL pointers, causing a segfault. This was found by OSS-Fuzz via the matio project's fuzzer.
Changes
H5HL_protect: Add NULL checks forprfx->heapandheap->dblk_imageafter loading the local heap prefix from the cache. Return an error viaHGOTO_ERRORinstead of crashing.H5HL_unprotect: Replace theassert(heap->dblk)with a proper NULL check andHGOTO_ERROR. Add an equivalent NULL check forheap->prfxin thesingle_cache_objbranch.ASAN report (from OSS-Fuzz)
https://issues.oss-fuzz.com/504827191