Avoid out-of-bounds dims read for a scalar HDF5 dataspace#319
Open
naruto-lgtm wants to merge 1 commit into
Open
Avoid out-of-bounds dims read for a scalar HDF5 dataspace#319naruto-lgtm wants to merge 1 commit into
naruto-lgtm wants to merge 1 commit into
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: open a v7.3 file with a numeric dataset stored as a scalar (rank-0) HDF5 dataspace and marked MATLAB_empty, or a sparse variable whose ir/jc/data subdataset is stored the same way.
Cause: Mat_H5ReadDims sizes its result with malloc(*rank * sizeof(size_t)), so a scalar dataspace gives malloc(0); Mat_H5ReadDatasetInfo's empty branch and the sparse ir/jc/data readers in Mat_VarRead73 then read dims[0] off that zero-length buffer (ASan heap-buffer-overflow read at mat73.c:920 and :3204).
Fix: return one zeroed element for a scalar dataspace so dims[0] stays in bounds. rank stays 0, so the struct-field reader that already special-cases a scalar is unchanged and the malformed empty/sparse datasets are rejected downstream.