GH-50462: [C++][Gandiva] fix out-of-bounds read in translate_utf8_utf8_utf8#50463
Open
Arawoof06 wants to merge 1 commit into
Open
GH-50462: [C++][Gandiva] fix out-of-bounds read in translate_utf8_utf8_utf8#50463Arawoof06 wants to merge 1 commit into
Arawoof06 wants to merge 1 commit into
Conversation
|
|
|
|
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.
Rationale for this change
The multi-byte branch of
translate_utf8_utf8_utf8(taken whenever the input, FROM, or TO contains a byte > 127) readsgdv_fn_utf8_char_lengthon a lead byte and then builds astd::stringof that width from the buffer without checking how many bytes remain. A truncated trailing glyph in the input reads past IN, a multi-byte input character missing from FROM reads one byte past FROM at the end-of-list sentinel (thefrom_for == from_lencheck ran after the read), and a truncated glyph in TO reads past TO. All three are reachable from the SQLtranslate(in, from, to)call on truncated column data.What changes are included in this PR?
Clamp each utf8 character width to the bytes left in its buffer before copying, consuming a single byte on a truncated or invalid lead byte (which also stops a zero-width advance from looping forever), and move the FROM end-of-list check ahead of the read so the sentinel iteration no longer touches
from[from_len]. Valid input keeps its existing grouping since the clamp only fires past the end.Are these changes tested?
Yes. Added two cases to
TestGdvFnStubs.TestTranslate: a truncated trailing glyph in the input, and a valid multi-byte input char absent from FROM. Both use exact-sized buffers so ASAN trips on the pre-patch over-read and passes after the fix.Are there any user-facing changes?
No.
This PR contains a "Critical Fix". It fixes a heap out-of-bounds read (crash) in
translatereachable from user-supplied string data.