You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++][Gandiva] Out-of-bounds read in utf8_length_ignore_invalid on truncated multi-byte input #50355
Describe the bug, including details regarding any error messages, version, and platform.
utf8_length_ignore_invalid in cpp/src/gandiva/precompiled/string_ops.cc counts glyphs while tolerating invalid bytes. When it hits a byte that is not a valid continuation byte it extends char_len:
The inner loop keeps reading data[i + j] as char_len grows, but it never rechecks the buffer end. If a value ends in a truncated multi-byte sequence (for example a 0xF0 lead byte followed by non-continuation bytes) char_len grows past the remaining bytes and the loop reads past data_len.
The function is reached from untrusted string data through lpad/rpad (lpad_utf8_int32_utf8, rpad_utf8_int32_utf8), which call it on the input text before computing padding.
Reproduced against a verbatim copy of the function under AddressSanitizer with the 4-byte input {0xF0, 'a', 'a', 'a'} in an exactly-sized heap buffer:
==ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 1 ... 0 bytes after 4-byte region
#0 utf8_length_ignore_invalid
The sibling helpers (utf8_length, reverse_utf8, utf8_byte_pos) already guard the equivalent access with i + char_len > data_len; this one does not.
Activity
apacheGH-50355: [C++][Gandiva] break on invalid continuation byte, ve…
apacheGH-50355: [C++][Gandiva] set char_len to mismatch offset on break
apacheGH-50355: [C++][Gandiva] use exact-sized heap buffers in pad tests
apacheGH-50355: [C++][Gandiva] drop now-unused <vector> include in pa…
GH-50355: [C++][Gandiva] fix out-of-bounds read in utf8_length_ignore…
kou commentedon Jul 8, 2026
Issue resolved by pull request 50356
#50356