Validate header length and array size in .npz loader (fix OOB reads in #106) - #107
Open
ValheruEldarr wants to merge 1 commit into
Open
Validate header length and array size in .npz loader (fix OOB reads in #106)#107ValheruEldarr wants to merge 1 commit into
ValheruEldarr wants to merge 1 commit into
Conversation
…duct overflow Adds bounds checks to the .npz read path (reported in rogersce#106): - parse_npy_header(buffer): reject header_len that exceeds the decompressed buffer (CWE-125) - load_the_npz_array: reject array size greater than the decompressed data before the unsigned subtraction/memcpy (CWE-191) - NpyArray ctor: reject shape*word_size products that overflow size_t (CWE-190)
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.
Fixes the heap out-of-bounds reads reported in #106 (CWE-125, CWE-191), plus the related constructor integer overflow (CWE-190).
Changes:
parse_npy_header(unsigned char* buffer, ...): thread the decompressed buffer size in and reject aheader_lenthat runs past it.load_the_npz_array: reject an array whose declared size exceeds the decompressed data, before the unsigned subtraction andmemcpy.NpyArrayconstructor: rejectshape * word_sizeproducts that overflowsize_t.The only signature change is the buffer overload of
parse_npy_header(one internal caller, updated here); the publicnpz_load/npy_loadAPI is unchanged.Verified with AddressSanitizer and UBSan: the three PoCs from #106 are now rejected with a clean exception instead of an out-of-bounds read, and a valid
.npz(round-tripped, two arrays) still loads. These are out-of-bounds reads; no code execution is involved.