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

Prevent bin_file() -> is_utf8_well_formed() buffer overrun #271

Merged
merged 1 commit into from
Jun 21, 2022

Conversation

tmarkettos
Copy link
Contributor

When supplied with a file of random data >256 bytes, read()
would return a full buffer of data[256] to bin_file().
That function loops through the buffer, but calls is_utf8_well_formed()
with the full length of the buffer. When looping on the last byte of the
buffer, is_uft8_well_formed() reads past the end.

This commit fixes bin_file() to only inspect the remaining bytes in the
buffer.

Found and tested with CheriBSD on an Arm Morello platform running with strong
memory safety.

Example file of random data 'rand' attached (zipped), sha256sum:
a1419d3bcf8702b825a5a565a49ded104d5df3f04995244c06cd41430f5d6cf7 rand
rand.zip

When supplied with a file of random data >256 bytes, read()
would return a full buffer of data[256] to bin_file().
That function loops through the buffer, but calls is_utf8_well_formed()
with the full length of the buffer.  When looping on the last byte of the
buffer, is_uft8_well_formed() reads past the end.

This commit fixes bin_file() to only inspect the remaining bytes in the
buffer.

Found and tested with CheriBSD on an Arm Morello platform running with strong
memory safety
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.

None yet

2 participants