Skip to content

Avoid out-of-bounds dims read for a scalar HDF5 dataspace#319

Open
naruto-lgtm wants to merge 1 commit into
tbeu:masterfrom
naruto-lgtm:mat73-scalar-dataspace-dims
Open

Avoid out-of-bounds dims read for a scalar HDF5 dataspace#319
naruto-lgtm wants to merge 1 commit into
tbeu:masterfrom
naruto-lgtm:mat73-scalar-dataspace-dims

Conversation

@naruto-lgtm

Copy link
Copy Markdown
Contributor

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.

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