GH-50707: [C++][Gandiva] fix out-of-bounds read in mask utf8proc length - #50709
Open
Arawoof06 wants to merge 1 commit into
Open
GH-50707: [C++][Gandiva] fix out-of-bounds read in mask utf8proc length#50709Arawoof06 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 Gandiva mask stubs walk a utf8 string calling
utf8proc_iterate(data + bytes_read, data_len, ...), passing the totaldata_lenas the remaining byte count even though the pointer has already advanced bybytes_read.utf8proc_iteratereads up tostrlenbytes, so a value ending in a truncated multi-byte glyph (for example a lead byte0xF0as the final byte of an exactly sized value buffer) makes it read continuation bytes pastdata + data_len. This is reachable frommask(),mask_first_n()andmask_last_n()on untrusted string columns.gdv_mask_last_n_utf8_int32happens to be shielded by itsutf8proc_decomposepre-pass, butgdv_mask_first_n_utf8_int32andmask_utf8_utf8_utf8_utf8have no such guard and over-read.What changes are included in this PR?
Pass
data_len - bytes_read(the real remaining length) at all fourutf8proc_iteratecall sites so utf8proc reports the truncated glyph instead of reading past the buffer.mask_utf8_utf8_utf8_utf8also lacked thechar_len < 0check that the other two paths already have, so I added it there to reject the now-detected invalid input rather than advancing by a negative length.Are these changes tested?
Yes.
TestMaskTruncatedUtf8NoOverreadfeeds a value whose reported length stops one byte short of a complete euro sign; before the change both functions consumed the out-of-range byte and returned a masked result, after it they report the truncated input. The existing mask tests still pass.Are there any user-facing changes?
No change for valid utf8. A value that ends in a truncated multi-byte glyph now surfaces an invalid-utf8 error instead of being silently masked using bytes past its end.
This PR contains a "Critical Fix". The wrong length argument lets
utf8proc_iterateread past the end of an exactly sized input buffer.