Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

READ_DATA macro needs checks before float to int casts #241

Open
seanm opened this issue Mar 4, 2024 · 1 comment
Open

READ_DATA macro needs checks before float to int casts #241

seanm opened this issue Mar 4, 2024 · 1 comment

Comments

@seanm
Copy link
Contributor

seanm commented Mar 4, 2024

Hi @tbeu,

I've been fuzzing lately, and found something that's better to discuss before I attempt any PR. The macro READ_DATA has this line:

data[i + j] = (T)SwapFunc(&v[j]);

When v is float/double it could be outside the range of the integer type T. Like for huge or non-finite floats. UBSan will then complain of undefined behaviour casting such things to integers.

Probably some range checks will be needed, but that may be tricky as this macro works for many different types...

@tbeu
Copy link
Owner

tbeu commented Mar 4, 2024

One idea would be to additionally pass min and max rage values to macros READ_DATA and READ_COMPRESSED_DATA and check if in range before casting.

seanm added a commit to seanm/matio that referenced this issue Mar 4, 2024
seanm added a commit to seanm/matio that referenced this issue Mar 5, 2024
seanm added a commit to seanm/matio that referenced this issue Mar 5, 2024
seanm added a commit to seanm/matio that referenced this issue Mar 19, 2024
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

No branches or pull requests

2 participants