Skip to content

GH-37757: [C++][Compute] Fix out-of-bounds read in utf8_split_whitespace - #55771

Open
ikrommyd wants to merge 1 commit into
apache:mainfrom
ikrommyd:GH-37757-split-whitespace-oob
Open

ikrommyd wants to merge 1 commit into
apache:mainfrom
ikrommyd:GH-37757-split-whitespace-oob

Conversation

@ikrommyd

@ikrommyd ikrommyd commented Nov 24, 2026 •

Copy link
Copy Markdown

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:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

…hitespace

Signed-off-by: Iason Krommydas <iason.krom@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 23:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

split_whitespace sporadically produces different results on MacOS

2 participants