reject non-positive extents in load_npy and load_mat#9221
Open
Nashit-h wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
alexreinking
approved these changes
Jul 19, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9221 +/- ##
=======================================
Coverage ? 69.76%
=======================================
Files ? 255
Lines ? 78885
Branches ? 18859
=======================================
Hits ? 55038
Misses ? 18266
Partials ? 5581 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
load_npyandload_matbuild the output buffer straight from the extents in the file header without checking their sign, then read the payload withf.read_bytes(im->begin(), im->size_in_bytes()). A negative extent makes the computedend()fall short of the real end of the allocation, sosize_in_bytes()reports more than was allocated and the payload read writes past the heap block;Buffer::check_overflowonly catches this underassert, which is gone in a release build.load_tmpalready validatesheader[0..3] > 0for the same reason, so this applies that check in the two loaders that were missing it.Reproducer: a
.npywith'shape': (2, -3)and a.matwith extents(4, -4), both built in the new test. On the unpatched tree, compiled-O2 -DNDEBUG -fsanitize=address, each gives a heap-buffer-overflow write athalide_image_io.h:1367(npy) and:1861(mat); the test aborts. With the fix both are rejected and the existing round-trip tests are unaffected.Checklist