Skip to content

bound MATLAB_class and MATLAB_sparse attribute reads to one element - #324

Open
naruto-lgtm wants to merge 1 commit into
tbeu:masterfrom
naruto-lgtm:mat73-attr-scalar-read
Open

bound MATLAB_class and MATLAB_sparse attribute reads to one element#324
naruto-lgtm wants to merge 1 commit into
tbeu:masterfrom
naruto-lgtm:mat73-attr-scalar-read

Conversation

@naruto-lgtm

Copy link
Copy Markdown
Contributor

Repro: open a v7.3 file whose MATLAB_class attribute (read for every variable) or MATLAB_sparse attribute (on a struct/sparse group) is stored with a simple dataspace of two or more elements.
Cause: both are read with a bare H5Aread into a single-element destination, calloc(class_len+1) for the class string in Mat_H5ReadVarInfo and a stack unsigned nrows in Mat_H5ReadGroupInfo, but H5Aread copies the whole attribute, so a multi-element attribute writes past the destination during Mat_VarReadNextInfo. ASan shows a heap write of 14 bytes at mat73.c:591 and a stack write of 8 bytes at mat73.c:1068.
Fix: read both through Mat_H5ReadScalarAttribute, which already rejects a non-scalar attribute before the copy, the same guard the MATLAB_global, MATLAB_int_decode and MATLAB_empty reads use.

@naruto-lgtm

Copy link
Copy Markdown
Contributor Author

any update?

@tbeu

tbeu commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Seen it.

@tbeu
tbeu force-pushed the mat73-attr-scalar-read branch from 85aa3b1 to 650faa0 Compare August 11, 2026 20:06
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.

2 participants