Validate metadata cache load sizes before allocation - #6506
Conversation
|
Pushed a follow-up for the CI failures. The first issue was formatting in The update keeps the non-SWMR metadata size checks in place, removes the too-early continuation-message EOA check, and skips this cache-entry EOA validation only for Local verification:
|
| * EOA cache is refreshed. Lower VFD read paths already bypass EOA | ||
| * validation for SWMR reads and rely on read retries / EOF handling. | ||
| */ | ||
| if (H5F_INTENT(f) & H5F_ACC_SWMR_READ) |
There was a problem hiding this comment.
I'm somewhat suspicious about the need for this addition; does this become an issue only after the addition of the call to H5C__verify_len_eoa() in H5C__load_entry()? That sticks out to me as indicating that H5C__load_entry() may not be the place this issue needs to be solved at.
There was a problem hiding this comment.
Yes—the conflict was specific to applying the new non-speculative EOA check to SWMR readers. I kept the validation in H5C__load_entry() because this is the common point after the client computes len and immediately before allocating len + H5C_IMAGE_EXTRA_SPACE; validating later in a decoder would be after the allocation we need to bound. The SWMR exception is now scoped only to that new non-speculative call site, while the shared helper retains its pre-existing behavior for speculative clients. The focused cache and full ohdr binaries pass in a Debug build.
e4b02ab to
4faca29
Compare
4faca29 to
397b13b
Compare
|
Are there later checks that could be changed into asserts with this change? Or are there other paths to reach those later checks besides through H5C__load_entry()? |
|
Good questions — I looked at both. Could later checks become asserts? I'd recommend against it for the checks inside the client
The only assert that would be sound is one in Are there other paths to those later checks? Yes —
There While checking that, I noticed the "known exactly" premise doesn't hold for a malformed file. In H5F_addr_decode(f, &p, &pf_entry_ptr->addr);
/* Validate address range */
eoa = H5F_get_eoa(f, H5FD_MEM_DEFAULT);
if (!H5_addr_defined(pf_entry_ptr->addr) || H5_addr_overflow(pf_entry_ptr->addr, pf_entry_ptr->size) ||
H5_addr_ge(pf_entry_ptr->addr + pf_entry_ptr->size, eoa))
HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, NULL, "invalid entry address range");
/* Decode entry length */
H5F_DECODE_LENGTH(f, p, pf_entry_ptr->size);The range check runs before the length is decoded. That is not an out-of-bounds read in the decoder itself: the following Moving that validation to after the length decode looks like a small, self-contained fix. Happy to fold it into this PR or open a separate one — whichever you prefer. |
|
@mattjala Friendly ping — this PR has hyoklee's approval and the CI is green. Could you check off the src/test areas in the review checklist when you have a moment? Happy to address any remaining concerns. |
|
I think this can go in as it is now, though there's still a CHANGELOG conflict to resolve. |
c0d7333 to
9d90808
Compare
Describe your changes
This hardens malformed-file handling for metadata cache entry loads:
ohdrregression that creates an object header continuation chunk, corrupts the encoded continuation size on disk, and verifies the malformed object header is rejected before the cache allocates that size.This prevents malformed metadata from driving very large allocations before the later file-read/EOA checks run.
AI assistance disclosure: this patch was prepared with assistance from OpenAI Codex. I reviewed the changes and ran the verification below locally.
Issue ticket number (GitHub or JIRA)
N/A
Checklist before requesting a review
Local verification
git diff --check origin/develop..HEADcmake --build build-asan-o0 --target ohdr h5dump -j$(nproc)ASAN_OPTIONS=detect_leaks=0:allocator_may_return_null=0:abort_on_error=1 timeout 180s build-asan-o0/bin/ohdrbuild-asan-o0/bin/h5dump -H test/testfiles/tmtimeo.h5