Arawoof06 opened a new pull request, #50709: URL: https://github.com/apache/arrow/pull/50709
### Rationale for this change The Gandiva mask stubs walk a utf8 string calling `utf8proc_iterate(data + bytes_read, data_len, ...)`, passing the total `data_len` as the remaining byte count even though the pointer has already advanced by `bytes_read`. `utf8proc_iterate` reads up to `strlen` bytes, so a value ending in a truncated multi-byte glyph (for example a lead byte `0xF0` as the final byte of an exactly sized value buffer) makes it read continuation bytes past `data + data_len`. This is reachable from `mask()`, `mask_first_n()` and `mask_last_n()` on untrusted string columns. `gdv_mask_last_n_utf8_int32` happens to be shielded by its `utf8proc_decompose` pre-pass, but `gdv_mask_first_n_utf8_int32` and `mask_utf8_utf8_utf8_utf8` have no such guard and over-read. ### What changes are included in this PR? Pass `data_len - bytes_read` (the real remaining length) at all four `utf8proc_iterate` call sites so utf8proc reports the truncated glyph instead of reading past the buffer. `mask_utf8_utf8_utf8_utf8` also lacked the `char_len < 0` check 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. `TestMaskTruncatedUtf8NoOverread` feeds 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_iterate` read past the end of an exactly sized input buffer. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
