Repository navigation
Reject Arrow IPC inputs with an unsupported metadata version - #125224
alexey-milovidov merged 3 commits into
Conversation
`Message.version` and `Footer.version` name the edition of the Arrow IPC specification the writer used. The buffer layout differs between editions (V5 removed the validity buffer from unions), so a reader that decodes an edition it does not implement takes every following buffer from the wrong offset and returns silently wrong values. The native Arrow IPC reader never read either field. FlatBuffers verification does not catch this: an enum field is a plain `int16`, so a value outside the enum is still a well-formed buffer. Reading `apache/arrow-testing`'s `data/forward-compatibility/schema_v6.arrow`, which declares the non-existent `MetadataVersion::V6`, inferred a schema and returned no rows instead of throwing. Check the version in `MessageReader::readNextMessage`, which every message of both the stream and the file format passes through, and in `readArrowFileFooter`. A `static_assert` pins the upper bound to V5, so a submodule bump that adds a version breaks the build instead of widening the guard to a layout `RecordBatchDecoder` does not implement. Closes: ClickHouse#125149 Related: ClickHouse#125134
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@alexey-milovidov can you review this pr |
|
Could a maintainer add the |
|
Workflow [PR], commit [3d5e9df] Summary: ✅
AI ReviewSummaryThe change validates PR Metadata💡 The description still says that Missing context / blind spots
Final Verdict✅ Approve, with the description correction above and pending CI validation. |
|
Took the simpler option from the review: the accepted range is now V5 only, rather than V4-V5.
Changes in
|
RecordBatchDecoder implements the V5 union layout, where the validity buffer is absent. A V4 union still carries that buffer, so decoding a V4 message under V5 rules shifts every following buffer and silently corrupts the values. Narrow the accepted range to V5 instead of V4-V5, so such an input is rejected rather than misread.
b126c67 to
5461394
Compare
Accepting `V5` alone refused files ClickHouse has always read. The footer of `tests/queries/0_stateless/data_arrow/test.arrow` carries `V4`, as do the hardcoded `Arrow` and `ArrowStream` messages in `tests/integration/test_storage_kafka/test_batch_slow_0.py`, so `01273_arrow_load` and `test_kafka_formats` stopped working: a backward-incompatible change rather than a stale fixture. The layout difference between the two editions is unions alone - `V5` removed the union validity buffer, and `RecordBatchDecoder` implements only that layout. Every other type is identical byte for byte. The version guard now accepts `V4` and `V5` and still refuses `V1` to `V3`, an absent field, which reads back as `V1`, and anything above `V5`. `parseSchema` takes the metadata version and rejects a union field, including one nested in a list, struct or map, when the version is not `V5`. `04538_arrow_ipc_native_malformed_union` built its messages without a `version` field at all, so once the version is checked first the test no longer reached the union discriminant guard it exists to pin. Its two messages now set `V5`. `05361_arrow_ipc_unknown_metadata_version` asserted that `V4` is refused, which is no longer true, so it now asserts that a `V4` stream reads and that a `V4` union is refused.
|
Pushed The edition difference is unions alone -
Review appreciated. |
|
CI is green on No open issues on my side. @alexey-milovidov could you take a look when you have a moment? |
|
@nihalzp @groeneai you both own most of The guard accepts V4 and V5, and rejects only a V4 schema containing a union field, nested ones included. CI and |
|
I checked The stream path works as described: V4 dense and sparse unions, unions nested in The For the later V4 layout work: Arrow C++ reads a V4 union by skipping its validity buffer slot and refusing a non-zero null count ( Minor: the description still says "V5 is the single accepted edition; V4 is rejected rather than misread". |
|
@msohail22 @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Some writers of the V4 era left `Footer.version` unset, so it reads as the default `V1`, while all messages of the file are V4. Since #125224 such files are rejected with `Unsupported Arrow IPC metadata version V1 in the Arrow file footer`, although the same data in the stream format is read. Three files of the Arrow 0.14.1 integration set in `apache/arrow-testing` are affected (`generated_decimal`, `generated_primitive_no_batches`, `generated_primitive_zerolength`), as found by `05361_arrow_testing_corpus`. The Apache Arrow library does not check the footer version either. Read a footer older than V4 as V4: each message is still checked for its own version. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #125149
Reject Arrow IPC messages and file footers whose metadata version this reader does not implement. V5 changed the buffer layout for unions (it removed the validity buffer), so reading a message under the wrong edition's rules takes every following buffer from the wrong offset and produces silently wrong values.
Adds version validation in
MessageReader::readNextMessageandreadArrowFileFooter.RecordBatchDecoderimplements the V5 union layout only, so V5 is the single accepted edition; V4 is rejected rather than misread. Astatic_assertonMetadataVersion_MAXmakes a new Arrow edition fail the build instead of silently widening the guard.Changelog category:
Changelog entry:
Reject
ArrowandArrowStreaminputs with an unsupported metadata version.Workflow [PR]
Sync PR [sync-upstream/pr/125224]
Version info
26.11.1.568-master(included in26.11and later)