Repository navigation
uuEncoder: fix out-of-bounds write and several decoding bugs - #363
Merged
Merged
Conversation
Memory safety: - A 'b' line length which does not introduce a "begin" line made the decoder read 5 bytes while probing for the marker, more than such a line holds. The per-line read count 'inLength - inPos' then underflowed, and the resulting near-SIZE_MAX count drove a write past the decoder's 64-byte stack buffer. - A line length larger than 48 made the decoder write out up to 15 bytes of its output buffer which it had not decoded, leaking uninitialized stack memory into the decoded data. Hardening: - inputStreamStringAdapter and seekableInputStreamRegionAdapter now compare the requested count with the number of remaining bytes, instead of testing 'pos + count >= end': the sum may overflow and let a huge count through to the copy. - inputStreamStringAdapter no longer copies past the end of its range when it covers only a part of the string. Decoding: - The number of encoded characters on a line was computed as (length * 4) / 3, while the encoder writes 4 characters for each group of 3 bytes, including an incomplete last group. Any line whose length is not a multiple of 3 (usually the last one) was only partly read, and the decoder lost sync with its input. - The mode and filename of the "begin" line were both extracted from the start of the line, so the filename included the mode. - On a "begin\n" line with no mode nor filename, the following line, which holds data, was taken as the mode and filename. Fixes #362. Reported by Nguyen Dinh Hai (@Haind03).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Memory safety:
A 'b' line length which does not introduce a "begin" line made the decoder read 5 bytes while probing for the marker, more than such a line holds. The per-line read count 'inLength - inPos' then underflowed, and the resulting near-SIZE_MAX count drove a write past the decoder's 64-byte stack buffer.
A line length larger than 48 made the decoder write out up to 15 bytes of its output buffer which it had not decoded, leaking uninitialized stack memory into the decoded data.
Hardening:
inputStreamStringAdapter and seekableInputStreamRegionAdapter now compare the requested count with the number of remaining bytes, instead of testing 'pos + count >= end': the sum may overflow and let a huge count through to the copy.
inputStreamStringAdapter no longer copies past the end of its range when it covers only a part of the string.
Decoding:
The number of encoded characters on a line was computed as (length * 4) / 3, while the encoder writes 4 characters for each group of 3 bytes, including an incomplete last group. Any line whose length is not a multiple of 3 (usually the last one) was only partly read, and the decoder lost sync with its input.
The mode and filename of the "begin" line were both extracted from the start of the line, so the filename included the mode.
On a "begin\n" line with no mode nor filename, the following line, which holds data, was taken as the mode and filename.
Fixes #362. Reported by Nguyen Dinh Hai (@Haind03).