Skip to content

Validate header length and array size in .npz loader (fix OOB reads in #106) - #107

Open
ValheruEldarr wants to merge 1 commit into
rogersce:masterfrom
ValheruEldarr:fix/npz-loader-bounds-checks
Open

Validate header length and array size in .npz loader (fix OOB reads in #106)#107
ValheruEldarr wants to merge 1 commit into
rogersce:masterfrom
ValheruEldarr:fix/npz-loader-bounds-checks

Conversation

@ValheruEldarr

Copy link
Copy Markdown

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 a header_len that runs past it.
  • load_the_npz_array: reject an array whose declared size exceeds the decompressed data, before the unsigned subtraction and memcpy.
  • NpyArray constructor: reject shape * word_size products that overflow size_t.

The only signature change is the buffer overload of parse_npy_header (one internal caller, updated here); the public npz_load / npy_load API 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.

…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant