Harden serialized selection decoding#6509
Open
Alb3e3 wants to merge 1 commit into
Open
Conversation
Contributor
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.
Summary
This hardens serialized dataspace selection decoding against malformed or truncated selection buffers.
The patch adds explicit length validation before decoding the common serialized selection type, passes the remaining selection-type-specific payload size to the concrete deserializers, rejects zero-length concrete selection payloads, and validates the decoded hyperslab rank before it is used to patch or allocate a dataspace.
Motivation and context
Several selection deserializers computed
*p + p_size - 1before proving thatp_sizewas non-zero. A malformed serialized selection can therefore underflow the end pointer and let later bounds checks reason about an invalid buffer range. Hyperslab selection decoding also accepted an unchecked serialized rank before patching the dataspace rank.Testing
Built and tested with Clang 18 ASan/UBSan on
develop:cmake -S . -B build-asan -G "Unix Makefiles" -DCMAKE_C_COMPILER=clang-18 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON -DHDF5_BUILD_TOOLS=ON -DHDF5_BUILD_CPP_LIB=OFF -DHDF5_BUILD_FORTRAN=OFF -DHDF5_BUILD_JAVA=OFF -DHDF5_ENABLE_PARALLEL=OFF -DCMAKE_C_FLAGS_RELWITHDEBINFO="-O1 -g -DNDEBUG -fsanitize=address,undefined -fno-omit-frame-pointer" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined"cmake --build build-asan --target testhdf5 h5dump h5ls -j2ASAN_OPTIONS=allocator_may_return_null=1:detect_leaks=0:abort_on_error=1 UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1 build-asan/bin/testhdf5 -only selecttest/testfilestool baseline across 456h5dump/h5lsinvocations: 0 sanitizer failures. The existing slowtlayouto.h5defaulth5dumpcase still timed out and was treated separately from sanitizer findings.AI assistance was used to find and prepare this patch. I reviewed the changes and verified them locally with the commands above.