Skip to content

Reject Arrow IPC inputs with an unsupported metadata version - #125224

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
msohail22:arrow-reject-unknown-metadata-version
Oct 22, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
msohail22:arrow-reject-unknown-metadata-version

Conversation

@msohail22

@msohail22 msohail22 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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::readNextMessage and readArrowFileFooter. RecordBatchDecoder implements the V5 union layout only, so V5 is the single accepted edition; V4 is rejected rather than misread. A static_assert on MetadataVersion_MAX makes a new Arrow edition fail the build instead of silently widening the guard.

Changelog category:

  • Bug Fix

Changelog entry:

Reject Arrow and ArrowStream inputs with an unsupported metadata version.


Workflow [PR]
Sync PR [sync-upstream/pr/125224]

Version info

  • Merged into: 26.11.1.568-master (included in 26.11 and later)

`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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-11T18:27:58.886159Z 24a5a35 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clickhouse-gh clickhouse-gh Bot added comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization labels Oct 11, 2026
@msohail22

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov can you review this pr

@msohail22

Copy link
Copy Markdown
Contributor Author

Could a maintainer add the can be tested label? CI has not run on this PR yet, so there are no check results for a reviewer to look at.

@george-larionov george-larionov added the can be tested Allows running workflows for external contributors label Oct 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3d5e9df]

Summary: ✅


AI Review

Summary

The change validates Arrow and ArrowStream metadata versions, preserves ordinary V4 inputs, and rejects V4 schemas containing union fields because the decoder implements the V5 union layout. No new blocking code findings remain.

PR Metadata

💡 The description still says that V5 is the only accepted edition and that all V4 inputs are rejected. Replace that explanation with: “The reader accepts V4 and V5. Schemas containing union fields, including nested unions, are rejected under V4 because RecordBatchDecoder implements the V5 union layout only.” The Bug Fix category and required changelog entry are appropriate.

Missing context / blind spots
  • ⚠️ Relevant functional and integration CI checks are pending for 3d5e9df45c8f284431b7d5ac8a0186d7967ec4a9. No ClickHouse binary is available locally; only the Python fixture generators were executed successfully. Passing 05361_arrow_ipc_unknown_metadata_version, 04538_arrow_ipc_native_malformed_union, 01273_arrow_load, and test_kafka_formats would close the execution gap. CI report.
Final Verdict

✅ Approve, with the description correction above and pending CI validation.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 13, 2026
@msohail22

msohail22 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Took the simpler option from the review: the accepted range is now V5 only, rather than V4-V5.

RecordBatchDecoder assumes the V5 union layout (no validity buffer) in decodeUnion and decodeBatchColumn. A V4 union still carries that buffer, so accepting V4 would shift every following buffer read and silently corrupt imported values. Plumbing Message.version into the decoder and implementing the V4/V5 layout split is a larger change that belongs in its own PR, so this one just rejects V4.

Changes in 5461394:

  • MessageReader::readNextMessage and readArrowFileFooter now require MetadataVersion_V5 exactly. The two separate "future"/"legacy" messages collapse into one: Unsupported Arrow IPC metadata version V{n}: this reader implements V5 only.
  • The static_assert on MetadataVersion_MAX stays, so a new Arrow edition in the submodule fails the build rather than quietly widening the guard.
  • The test case that read a pyarrow V4 stream back now asserts that it is rejected, for both DESCRIBE and SELECT. The V1, V6 and ClickHouse-roundtrip cases are unchanged.

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.
@msohail22
msohail22 force-pushed the arrow-reject-unknown-metadata-version branch from b126c67 to 5461394 Compare October 13, 2026 18:38
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.
@msohail22

Copy link
Copy Markdown
Contributor Author

Pushed 3d5e9df45c8. Accepting V5 alone was backward-incompatible: the footer of data_arrow/test.arrow and the hardcoded Arrow/ArrowStream messages in the Kafka test are V4, which is why 01273_arrow_load and test_kafka_formats broke.

The edition difference is unions alone - V5 dropped the union validity buffer and RecordBatchDecoder implements only that layout - so the guard now accepts V4 and V5 and rejects a union field, nested ones included, when the version is not V5. V1 to V3, an absent version field and anything above V5 are still refused.

04538 set no version at all, so it had stopped reaching the union discriminant guard; its messages now set V5. 05361 asserted that V4 is refused, so it now asserts that a V4 stream reads and a V4 union does not.

Review appreciated.

@msohail22

Copy link
Copy Markdown
Contributor Author

CI is green on 3d5e9df4 and the AI review is an approve. The description is now updated to match the final behaviour: the reader accepts V4 and V5, and rejects only V4 schemas containing union fields (including nested ones), because RecordBatchDecoder implements the V5 union layout only.

No open issues on my side. @alexey-milovidov could you take a look when you have a moment?

@msohail22

Copy link
Copy Markdown
Contributor Author

@nihalzp @groeneai you both own most of src/Processors/Formats/Impl/ArrowIPC/, so this sits in your area.

The guard accepts V4 and V5, and rejects only a V4 schema containing a union field, nested ones included. RecordBatchDecoder::decodeUnion and decodeBatchColumn implement the V5 union layout only, so a V4 union shifts every following buffer read. V5-only was backward-incompatible: the V4 fixtures behind 01273_arrow_load and test_kafka_formats broke.

CI and CH Inc sync are green on 3d5e9df4 and all review threads are resolved. @alexey-milovidov for the merge.

@groeneai

Copy link
Copy Markdown
Collaborator

I checked 3d5e9df4 (the CI build_amd_release binary) against pyarrow 24.0.0 fixtures.

The stream path works as described: V4 dense and sparse unions, unions nested in List and Struct, and a dictionary-encoded union are all rejected with the new message, and a V4 stream without unions reads.

The Arrow file path misses the most common V4 producer. Arrow C++ always writes the footer at kCurrentMetadataVersion (contrib/arrow/cpp/src/arrow/ipc/metadata_internal.cc:1430), so ipc.new_file(..., options=ipc.IpcWriteOptions(metadata_version=ipc.MetadataVersion.V4)) gives a V5 footer over V4 schema and record batch messages. The union check runs against the footer version, so for such a file with a union column DESCRIBE returns Variant(Int32, String) and SELECT fails in the decoder with Arrow IPC union type ids buffer is too small: have 0 bytes, need 3, the same as master. A crafted stream whose schema message says V5 over a V4 record batch behaves the same. The body layout follows the version of the message that carries it, so checking unions against msg.header->version() where record batches and dictionary batches are decoded would close both; a new_file V4 union case in 05361 would pin it.

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 (contrib/arrow/cpp/src/arrow/ipc/reader.cc:320-333, :480-499), which may be smaller than expected.

Minor: the description still says "V5 is the single accepted edition; V4 is rejected rather than misread".

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Oct 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 22, 2026
Merged via the queue into ClickHouse:master with commit 052ff78 Oct 22, 2026
177 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@msohail22 @alexey-milovidov — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

alexey-milovidov added a commit that referenced this pull request Oct 28, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arrow: an IPC stream with an unknown future metadata version is accepted instead of rejected

6 participants