Skip to content

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

Merged
gwsw merged 1 commit into
gwsw:masterfrom
tmarkettos:master
Jun 21, 2022
Merged

Prevent bin_file() -> is_utf8_well_formed() buffer overrun#271
gwsw merged 1 commit into
gwsw:masterfrom
tmarkettos:master

Conversation

@tmarkettos

Copy link
Copy Markdown
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.

2 participants