Repository navigation
Bound sparse writes to nir in Mat_VarWrite4 - #381
Merged
Merged
Conversation
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.
Repro: read a v5 sparse variable whose
irtag holds 1 index, withjc = {0, 64}and 64 doubles of data, then write it to a v4 file (test_mat -v 4 copy sparse.mat). ASan reports a heap-buffer-overflow READ of size 4 atmat4.c:209, 0 bytes after the 4-byteirallocation. Without ASan, 63 out-of-boundsuint32values from the heap end up in the output file.Cause:
Mat_VarRead5takesnir,njc, thejcvalues andndatafrom separate file tags, so they can disagree. The sparse branch ofMat_VarWrite4bounds eachjc[i]..jc[i+1]walk byndataonly and then readsir[j].Mat_VarPrintalready bounds the same walk by bothndataandnir.Fix: add the same
j < sparse->nirbound to all fivejcloops, so the row, column and value streams stay the same length. Valid sparse arrays (jc[njc-1] <= nir == ndata) are written byte-identically. All 6262 ctest cases pass under ASan/UBSan (non-HDF5 build).Generator for the crafted file: