Repository navigation
Conversation
|
Thanks for opening a pull request! This pull request has been automatically closed because you currently have 8 open pull requests, which is more than the limit of 3. Due to the increase in pull requests opened by AI bots, and in order to keep the review queue manageable, Apache Arrow limits contributors without repository access to at most 3 concurrently open pull requests. This helps make sure each pull request gets the attention it needs and that work in progress does not go stale. Once one of your other open pull requests has been merged or closed, you are welcome to reopen this one. See also: |
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 padding kernels (
ascii_lpad/ascii_rpad/ascii_center,utf8_lpad/utf8_rpad/utf8_centerandutf8_zero_fill) preallocate the output values buffer fromMaxCodeunits, which returnsinput_ncodeunits + k * ninputs * options_.widthwith no handling of the width's range.Transformcopies a string unchanged whenever it is already at leastwidthcharacters wide, so the buffer must always hold the whole input.A negative width breaks that.
ascii_rpadwithwidth=-8on 64 eight-byte strings sizes the buffer at 0 bytes and then copies 512 bytes into it (ASAN reports a global-buffer-overflow write into the zero-size allocation). Smaller inputs with a negative width fail with "Negative buffer resize" instead of returning the strings unchanged. A very large width has the same effect through signed overflow:utf8_lpadwithwidth=1<<62wraps4 * ninputs * widthto 0, and the kernel then writes padding far past the allocation (ASAN heap-buffer-overflow).What changes are included in this PR?
A small
PadMaxCodeunitshelper inscalar_string_internal.hused by all three pad transforms. It treats a negative width as 0, which matches whatTransformalready does with it, and computes the bound withMultiplyWithOverflow/AddWithOverflow. If the bound doesn't fit inint64_tit saturates, so the existing output capacity check or the allocation fails with an error instead of producing an undersized buffer.Are these changes tested?
Yes.
PadAscii,PadUTF8andUTF8ZeroFillnow check that a negative width returns the input unchanged and that a width whose size estimate overflows returns an error. On the unpatched tree, the negative width cases fail with "Negative buffer resize" and the overflow case aborts under ASAN with a heap-buffer-overflow. With the patch,arrow-compute-scalar-type-testpasses (Debug + ASAN,utf8andlarge_utf8).Are there any user-facing changes?
A negative width now leaves strings unchanged for every input size instead of either erroring or corrupting memory. A width too large to size the output now returns an error. Behavior for ordinary widths is unchanged.
This PR contains a "Critical Fix". A negative or very large
PadOptions/ZeroFillOptionswidth makes the pad kernels write past their output buffer.Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by: