GH-50504: [C++][Gandiva] fix out-of-bounds read in upper/lower/initcap#50505
Open
Arawoof06 wants to merge 1 commit into
Open
GH-50504: [C++][Gandiva] fix out-of-bounds read in upper/lower/initcap#50505Arawoof06 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
upper(),lower()andinitcap()decode a multibyte glyph witharrow::util::UTF8Decodeingdv_string_function_stubs.ccwithout checking that the whole glyph fits insidedata_len. When a string ends in a truncated multibyte sequence (a trailing0xC3or0xE0lead byte),UTF8Decodewalks continuation bytes pastdata[data_len]. The input is a string array value buffer, so a packed, exactly-sized buffer makes that read land past the allocation. The three functions share the same decode loop, so all three are affected.ASAN on an exact-sized input buffer:
What changes are included in this PR?
Reject a glyph whose declared length runs past
data_lenbefore decoding it, ingdv_fn_lower_utf8,gdv_fn_upper_utf8andgdv_fn_initcap_utf8. This takes the same invalid-utf8 error path the functions already use for a bad lead byte, so valid input is handled exactly as before.One existing initcap test also passed length 19 for a 20-byte literal, which cut off the final
ɦglyph. That only stayed hidden because a string literal keeps a spare trailing byte; the length is corrected to 20.Are these changes tested?
Yes. New cases in
TestUpper,TestLowerandTestInitCapfeed an exact-sizednew char[]buffer ending in a truncated lead byte. They fail under ASAN on the current code (heap-buffer-overflow inUTF8Decode) and pass with the fix.Are there any user-facing changes?
No.