Skip to content

Fix regression: accept 0-byte offsets buffer for empty Arrow String/Binary columns - #107764

Merged
Algunenano merged 1 commit into
ClickHouse:masterfrom
Algunenano:fix-arrow-empty-string-offsets
Jun 22, 2026
Merged

Algunenano merged 1 commit into
ClickHouse:masterfrom
Algunenano:fix-arrow-empty-string-offsets

Conversation

@Algunenano

@Algunenano Algunenano commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Caused by: #106395
Closes: #107749

checkBinaryOffsetsBuffer (introduced in #106395) always required at
least sizeof(offset_type) bytes even when chunk.length() == 0.
Apache Arrow Java < 19.0.0, as bundled with Apache Spark, emits a 0-byte
offsets buffer for empty String/Binary children (e.g. when every map
row is empty, so the key child has zero elements). Every other Arrow
implementation (arrow-cpp, pyarrow, arrow-rs, Arrow Java >= 19.0.0)
accepts this; the non-compliance was fixed in apache/arrow-java#989, but
Spark users cannot control which Arrow Java version Spark bundles.

When chunk.length() == 0, every caller's iteration loop is skipped and
no byte of the offsets buffer is accessed, so requiring any bytes was a
spec-pedantry regression with no security benefit. The checkValidityBitmap
call remains unconditional and continues to validate the null bitmap.

Fix: gate the +1 sentinel on chunk.length() > 0; when the column is
empty, set count_plus_one = 0 so any buffer size (including 0 bytes)
passes.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Reading Arrow/ArrowStream data with empty String/Binary columns produced by Apache Arrow Java < 19.0.0 (including Apache Spark) no longer throws INCORRECT_DATA.

Version info

  • Merged into: 26.6.1.1123
  • Backported to: 26.5.4.4, 26.4.5.61, 26.3.15.3, 25.8.25.31

…columns

`checkBinaryOffsetsBuffer` always required at least `sizeof(offset_type)`
bytes (the `+1` sentinel entry), even when `chunk.length() == 0`.
Apache Arrow Java < 19.0.0, as bundled with Apache Spark, emits a 0-byte
offsets buffer for empty String/Binary children (e.g. when every map row
is empty so the key child has zero elements).  Every other Arrow
implementation (arrow-cpp, pyarrow, arrow-rs, Arrow Java >= 19) accepts
this; arrow-java fixed the non-compliance in apache/arrow-java#989.

When `chunk.length() == 0`, every caller's iteration loop is skipped and
no byte of the offsets buffer is ever accessed, so requiring any bytes was
a spec-pedantry regression, not a security necessity (confirmed by
thorough code review of all 8 call sites).  The `checkValidityBitmap`
call inside `checkBinaryOffsetsBuffer` is unconditional and continues to
validate the null bitmap.

Fix: gate the `+1` sentinel on `chunk.length() > 0`; when the column is
empty, set `count_plus_one = 0` so any buffer size (including 0 bytes)
passes the check.

Regression tests in `04356_arrow_empty_string_offsets.sh` cover:
standalone empty `String` column, `Map(String, Int32)` with all-empty
rows, and `Array(String)` with all-empty rows — all using the 0-byte
offsets buffer that Arrow Java < 19.0.0 produces.

Closes: ClickHouse#107749

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b17ae96]

Summary: ❌

job_name test_name status info comment
Stress test (amd_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue ISSUE EXISTS
Stress test (arm_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR fixes the ArrowColumnToCHColumn regression where empty String/Binary arrays with a 0-byte offsets buffer were rejected with INCORRECT_DATA. The changed checkBinaryOffsetsBuffer still requires offset + length + 1 entries for non-empty chunks, while allowing length == 0, and the relevant readers do not call value_offset or GetView for empty chunks. The regression test covers standalone empty String, Map(String, Int32) with empty maps, and Array(String) with empty arrays. I did not find any blocker or major issue.

Missing context / blind spots
  • ⚠️ The CI report link currently resolves to zero test results, so I could not use CI as execution evidence for the new stateless test.
  • ⚠️ I could not run 04356_arrow_empty_string_offsets locally because this workspace has no build artifacts and no pyarrow module installed.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 17, 2026
@Algunenano Algunenano added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jun 17, 2026
@Avogar Avogar self-assigned this Jun 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.20% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 7/9 (77.78%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@Algunenano
Algunenano added this pull request to the merge queue Jun 22, 2026
Merged via the queue into ClickHouse:master with commit dc8e5e5 Jun 22, 2026
320 of 326 checks passed
@Algunenano
Algunenano deleted the fix-arrow-empty-string-offsets branch June 22, 2026 15:16
robot-ch-test-poll4 added a commit that referenced this pull request Jun 22, 2026
Cherry pick #107764 to 25.8: Fix regression: accept 0-byte offsets buffer for empty Arrow String/Binary columns
robot-clickhouse added a commit that referenced this pull request Jun 22, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Jun 22, 2026
Cherry pick #107764 to 26.3: Fix regression: accept 0-byte offsets buffer for empty Arrow String/Binary columns
robot-clickhouse added a commit that referenced this pull request Jun 22, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Jun 22, 2026
Cherry pick #107764 to 26.4: Fix regression: accept 0-byte offsets buffer for empty Arrow String/Binary columns
robot-clickhouse added a commit that referenced this pull request Jun 22, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Jun 22, 2026
Cherry pick #107764 to 26.5: Fix regression: accept 0-byte offsets buffer for empty Arrow String/Binary columns
robot-clickhouse added a commit that referenced this pull request Jun 22, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 22, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 22, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 22, 2026
fm4v added a commit that referenced this pull request Jun 23, 2026
Backport #107764 to 26.4: Fix regression: accept 0-byte offsets buffer for empty Arrow String/Binary columns
Algunenano added a commit that referenced this pull request Jun 23, 2026
Backport #107764 to 26.5: Fix regression: accept 0-byte offsets buffer for empty Arrow String/Binary columns
Algunenano added a commit that referenced this pull request Jun 23, 2026
Backport #107764 to 26.3: Fix regression: accept 0-byte offsets buffer for empty Arrow String/Binary columns
Algunenano added a commit that referenced this pull request Jun 23, 2026
Backport #107764 to 25.8: Fix regression: accept 0-byte offsets buffer for empty Arrow String/Binary columns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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: reading rejects empty String/Binary column with a 0-byte offsets buffer (length == 0)

5 participants