Repository navigation
fix: Write one zero offset for empty variable-size arrays - #978
Merged
paleolimbot merged 1 commit intoOct 20, 2026
Merged
Conversation
The array view of an empty string, binary, list or map array has a zero-length offsets buffer, and the encoder wrote that buffer as is. IPC permits it, but arrow-go and Apache.Arrow for .NET read the first offset unconditionally. Arrow C++ writes one zero offset; the encoder now does too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #978 +/- ##
=======================================
Coverage 78.30% 78.30%
=======================================
Files 106 106
Lines 16919 16924 +5
Branches 2016 2018 +2
=======================================
+ Hits 13248 13252 +4
Misses 2429 2429
- Partials 1242 1243 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
An offsets buffer holds
length + 1offsets, 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), andArrowIpcEncoderCollectArray()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 onString.ValueOffsets():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:
NanoarrowIpcEncoderWritesOffsetForEmptyArraysencodes an emptystruct<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. Onmainthe 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.ctestpasses (Linux aarch64, Debug, 868 tests withNANOARROW_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