Skip to content

fix(ipc): Reject fields that share a dictionary with different value types - #989

Open
pedrobtz wants to merge 1 commit into
apache:mainfrom
pedrobtz:fix-ipc-shared-dictionary-types
Open

pedrobtz wants to merge 1 commit into
apache:mainfrom
pedrobtz:fix-ipc-shared-dictionary-types

Conversation

@pedrobtz

Copy link
Copy Markdown

ArrowIpcDictionariesInit() supports several fields sharing one dictionary id. It makes one ArrowIpcDictionary per unique id and decodes its batches with the value type of the first field that has that id. Nothing checks that the other fields with the id have the same value type. If they don't, ArrowIpcDecoderWalkSetArrayView() views the decoded dictionary with the second field's type.

For a string dictionary read by a field whose values are large_string, the 4-byte offsets are read as 8-byte ones. ASan reports a heap-buffer-overflow in ArrowArrayViewValidateDefault(). ArrowIpcArrayStreamReader hits this on a schema message with two such fields, followed by a dictionary batch and a record batch.

ArrowIpcDictionariesInit() now returns EINVAL when two fields share an id but not a value type. The comparison covers formats, children and nested dictionaries, not names, flags or metadata. Shared dictionaries with the same value type work as before.

The new NanoarrowIpcSharedDictionaryValueTypes test initialises dictionaries for two fields with id 0, first both string, then string and large_string. It expects success and then EINVAL. Without the fix the second case succeeds. I also read the stream that crashed through ArrowIpcArrayStreamReader. It now fails with the new message instead of reading out of bounds.

Found by fuzzing the IPC reader in the zuarrow R package, which vendors nanoarrow.

ctest passes in a plain Debug build and with ASan and UBSan (410 tests each). The changed files are formatted with the pinned clang-format 16.0.6.

🤖 Generated with Claude Code

…types

A dictionary batch is decoded with the value type of the first field
that uses its id. A second field with the same id and another value type
then viewed those buffers as its own type and read past them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant