ikrommyd opened a new pull request, #55771: URL: https://github.com/apache/arrow/pull/55771
### Rationale for this change Closes #37757 Until recently I used to maintain https://github.com/scikit-hep/awkward and and now I maintain a fork of it https://github.com/CoffeaTeam/awkward-lite and the original issue report game from `awkward`. The issue is still present to this day in CI where we get sporadic failures that are fixed by a rerun. When a run of whitespace reaches the end of a string, `utf8_split_whitespace` decodes the next code point before checking `i < end`, so it reads past the string (and before its start in reverse). The result then depends on that byte: a valid byte adds an extra `""`, an invalid one leaves a stray `" "`. For the last value of an array the byte is uninitialized memory, which is why the results in #37757 are sporadic. `ascii_split_whitespace` has the same out-of-bounds read, although its output does not depend on the byte read. ### What changes are included in this PR? 1. `SplitWhitespaceUtf8Finder::Find`/`FindReverse`: check the bounds before decoding, so a separator extends to the string boundary without reading outside the string. 2. `SplitWhitespaceAsciiFinder::Find`/`FindReverse`: check the bounds before dereferencing. ### Are these changes tested? Yes. New tests cover whitespace runs at the start and end of strings, and values surrounded by invalid UTF-8 bytes or by the ends of an exactly sized buffer (the latter fails under ASAN without the fix). ### Are there any user-facing changes? Yes. For strings that start or end with two or more whitespace characters, `utf8_split_whitespace` now returns the same result as `ascii_split_whitespace`, e.g. `" abc "` gives `["", "abc", ""]` instead of `["", "abc", "", ""]` or `["", "abc", " "]`. ### Was AI used for this PR? An AI model was used to find the cause of the bug. Then the model was used to find the appropriate locations to add the tests cause I've never worked with the arrow project source code. The PR description and all communication is done by a human. **PR code and description written by:** - [x] Human - [x] AI **Reviewed before submission by:** - [x] Human - [ ] AI - [ ] Not reviewed * GitHub Issue: (filled in automatically from the PR title) -- 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]
