rustyconover opened a new pull request, #978: URL: https://github.com/apache/arrow-nanoarrow/pull/978
An offsets buffer holds `length + 1` offsets, so even an empty string, binary, list or map array has one: `offsets[0] = 0`. The array view of an empty array has a zero-length offsets buffer, though (`ArrowArrayViewSetArray()` deliberately doesn't require one), and `ArrowIpcEncoderCollectArray()` wrote that buffer as is. So every empty variable-size array nanoarrow writes has a 0-byte offsets buffer. IPC permits that, and Arrow C++ reads it, but not every reader does. With nanoarrow 0.9.0 (Python) writing `struct<s: string, l: list<int32>>` with zero rows, arrow-go v18.8.0 reads the batch and then panics on `String.ValueOffsets()`: ``` panic: runtime error: slice bounds out of range [:1] with capacity 0 ``` The same batch written by pyarrow 25.0.1 has a 4-byte offsets buffer (8 bytes for `large_string`), and arrow-go reads it. Apache.Arrow for .NET had the same problem (apache/arrow-dotnet#462, now fixed there, but released versions still throw). The encoder now writes one zero offset (4 or 8 bytes) in place of a zero-length offsets buffer of an empty array, as Arrow C++ does. Non-empty arrays and other buffer types are unchanged. Tests: - `NanoarrowIpcEncoderWritesOffsetForEmptyArrays` encodes an empty `struct<s: string, b: binary, ls: large_string, l: list<int32>>` built the usual way. It decodes the message and checks that each child's offsets buffer holds one zero offset of the right width. On `main` the test fails: the buffers are 0 bytes. - `AssertArrayViewIdentical()`, used by the decoder round-trip tests, compared buffer sizes exactly. It now expects that one zero offset where the original empty array's view has a zero-length offsets buffer. `ctest` passes (Linux aarch64, Debug, 868 tests with `NANOARROW_BUILD_TESTS_WITH_ARROW`), and 393 tests under ASan/UBSan with clang. The changed files are formatted with clang-format 16.0.6, the pre-commit version. This PR's code and description were written by AI (Claude Code) and reviewed by a human maintainer. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
