JonSnow1807 opened a new pull request, #54914: URL: https://github.com/apache/arrow/pull/54914
### Rationale for this change `StringDataTransform` reuses the input offsets buffer whenever `input.offset == 0`, but it writes the transformed characters to a new data buffer starting at byte 0 (it allocates `offsets[length] - offsets[0]` bytes). When the first value offset is not 0 (a valid array, `ValidateFull()` accepts it) the reused offsets point past the end of the output data and the result is invalid: `Offset invariant failure: offset for slot 1 out of bounds: 8 > 3`. Reproduced with the issue's snippet for `string` and `large_string`. ### What changes are included in this PR? Only reuse the input offsets buffer when the first offset is 0. Otherwise fall into the existing branch that allocates new offsets and rebases them by `offsets[0]`, which is already what sliced inputs do. The common case (first offset 0, unsliced input) is unchanged and still reuses the buffer without copying. ### Are these changes tested? Yes. `TestStringKernels.AsciiCaseTransformNonZeroFirstOffset` (typed over `string` and `large_string`) builds an array with offsets `[5, 8, 8, 8, 10]`, a null, an empty string and a leading unused data prefix, checks it validates and equals `["abC", null, "", "De"]`, then checks all three kernels on the full array and on slices with a non-zero array offset. Without the fix the test fails with the offset invariant failure above; with it `arrow-compute-scalar-type-test` passes (350 tests, Debug + ASan/UBSan). Out of scope: for a length-0 input whose offsets buffer is absent, the reuse branch already copied `sizeof(offset_type)` bytes from a null pointer before this change; this PR does not change that path. ### Are there any user-facing changes? The three kernels now return valid arrays for such inputs. No API change. * GitHub Issue: #54906 AI usage: the fix and the test were written with an AI coding assistant (Claude Code) under my direction; I reviewed every line and ran the tests locally. -- 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]
