Bound header_length and check shape-product overflow when loading .npy (fix #44)#45
Open
ValheruEldarr wants to merge 2 commits into
Open
Bound header_length and check shape-product overflow when loading .npy (fix #44)#45ValheruEldarr wants to merge 2 commits into
ValheruEldarr wants to merge 2 commits into
Conversation
Owner
|
Thank you for your contribution. |
Adds input validation to read_header/comp_size (reported in llohse#44): - cap the attacker-controlled v2 header_length (16 MiB, well above any real header) before allocating, so a tiny crafted file can no longer force a multi-gigabyte allocation (CWE-789) - reject shape-dimension products that overflow ndarray_len_t (CWE-190)
c8c614c to
d05cd28
Compare
Owner
|
Tests are failing. It looks like an import is missing. |
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 unbounded allocation and shape-product integer overflow reported in #44 (CWE-789, CWE-190).
Changes:
read_header: cap the attacker-controlled v2header_length(16 MiB, well above any real header) before allocating, so a tiny crafted file can no longer force a multi-gigabyte allocation.comp_size: reject shape-dimension products that overflowndarray_len_t(the wrap previously produced a silent undersized buffer or a giant allocation downstream).Verified with AddressSanitizer: the PoCs from #44 are now rejected with a clean exception, and a valid
.npy(ndim=3, nelem=24) still loads. This is denial-of-service and undersized-allocation class; no code execution is involved.