Skip to content

Fix out-of-bounds write reading a Parquet DECIMAL wider than declared - #113046

Merged
PedroTadim merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-112659-parquet-decimal-width
Aug 4, 2026
Merged

PedroTadim merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-112659-parquet-decimal-width

Conversation

@groeneai

@groeneai groeneai commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #112659

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):

Fixed an out-of-bounds write when reading a Parquet DECIMAL column whose physical type is wider than the type its declared precision maps to, for example DECIMAL(9, 2) stored as physical INT64. Such files are valid Parquet and other writers produce them, but the reader sized the destination column from the declared precision while the decoder wrote the physical width, corrupting memory. Reading such a file now also raises DECIMAL_OVERFLOW when a value does not fit the declared precision, instead of returning corrupted data, and reads losslessly with a type hint at least as wide as the physical type.

Description

Reading a Parquet DECIMAL column whose physical element is wider than its declared precision maps to wrote past the end of the destination column, a SIGSEGV in DB::Parquet::Dictionary::index on ~60% of runs.

SchemaConverter::processPrimitiveColumn picked the decoder from the physical type but sized the destination from the declared precision alone, never setting out_decoded_type. So DECIMAL(9, 2) allocated Decimal32, 4 bytes per element, while the physical INT64 decoder wrote 8. Rejecting such files would be wrong, as the specification permits INT64 for precision 1 to 18. ClickHouse's writer always pairs a Decimal<T> with FIXED_LEN_BYTE_ARRAY of sizeof(T), so no round-trip test caught it.

The fix reconciles both widths where they are decided: on a mismatch out_decoded_type becomes the converter's width and the existing cast narrows the column. out_inferred_type is untouched, so DESCRIBE still reports the declared precision and every copy site becomes correct without a bounds check.

Row group statistics are no longer used for push-down on this shape: they decode to a value of the physical width, not the type the key range is built from, and allow_stats requires no conversion. Only a hint of exactly that width keeps them usable, matching how allow_stats treats every other type. Well-formed files are unaffected.

FIXED_LEN_BYTE_ARRAY carries the same defect and is covered too. My earlier comment on the issue called that branch correct because each precision bucket carries a length bound; those are upper bounds in an ordered chain, so an oversized length falls through to a wider bucket.

The test writes its fixtures with pyarrow instead of committing binaries. It covers both physical types, dictionary and plain pages, type_length 8 and 16, schema inference, the hint, the overflow boundary, and three 10-row-group push-down arms asserting exact prune counts.

Version info

  • Merged into: 26.8.1.730 (included in 26.8 and later)
  • Backported to: 26.7.3.8, 26.6.2.158, 26.5.7.3, 26.3.17.108

Reading a Parquet DECIMAL column whose physical element is wider than the
ClickHouse type its declared precision maps to wrote past the end of the
destination column. Reported as a SIGSEGV in DB::Parquet::Dictionary::index at
roughly 60% of runs; in debug and sanitizer builds a chassert aborts instead.

SchemaConverter::processPrimitiveColumn chose the decoder from the physical type
but derived the destination type from the declared precision alone, and never
assigned out_decoded_type. The caller therefore fell back to the
declared-precision type and allocated the decode target from it: DECIMAL(9, 2)
gives Decimal32, 4 bytes per element, while a physical INT64 decoder writes 8.
IntConverter::isTrivial returns true whenever output_size is unset, so every
consumer treated the column as a raw byte sink of input_size bytes per value.

Such a file is legal Parquet. The specification permits INT64 for precision 1 to
18 and FIXED_LEN_BYTE_ARRAY of any length up to 32, so a DECIMAL(9, 2) stored as
INT64 is valid and other writers emit it; rejecting the file would turn a crash
into a regression. ClickHouse's own writer always pairs a Decimal<T> with
FIXED_LEN_BYTE_ARRAY of sizeof(T), so no round-trip test caught this.

Reconcile the two widths at the single function that decides both: when the width
the chosen converter writes differs from the declared-precision width, set
out_decoded_type to the Decimal type of the converter's width and let the
existing castColumn path narrow it. max_precision is already the bucket precision
of every sub-branch (9, 18, 38, 76), which map to exactly 4, 8, 16 and 32 bytes.
out_inferred_type is untouched, so schema inference still reports the declared
precision, and every downstream copy site becomes correct without a per-site
bounds check. allow_stats now keys off the decoded width, which is the width
convertField actually produces; on the affected shape it was previously true
while convertField emitted a DecimalField<Decimal64> into a Decimal32 key range,
and on the explicit-wide-hint path it stays true so pruning is preserved.

Both defective physical types are covered. The FIXED_LEN_BYTE_ARRAY branch
carries the same defect as INT32/INT64: its precision and length bounds are upper
bounds within a bucket and the chain is ordered, so an oversized type_length
falls through to a wider bucket while the inferred type still follows the
declared precision. BYTE_ARRAY decimals bucket on precision only and are
unaffected.

A file whose values exceed its own declared precision now raises DECIMAL_OVERFLOW
instead of corrupting memory. Reading it losslessly remains possible with an
explicit wider type hint, so no workflow loses capability.

Closes ClickHouse#112659
The test asserted only scalar results, so the change that stops row group
statistics of the physical width from being compared against a key range of
the narrower declared type had no coverage: reverting it left every arm green.
That comparison can prune row groups holding matching rows, so it is a wrong
results guard, not a perf tuning.

Add two 10-row-group fixtures that differ only in declared precision and
assert the pruning verdict from ParquetReadRowGroups / ParquetPrunedRowGroups.
The mismatched file must decline pruning; the well-formed one must still prune,
which proves the layout and predicate admit pruning at all. Reverting only the
allow_stats argument flips the first verdict, so the arm is live.

The generator now reads the declared precision back out of each written file,
because the footer patch it uses is a blind byte replace and a mis-patched
fixture would produce a green but meaningless arm.
The previous two commit messages describe the change that stops row group
statistics of the physical width from being used as preventing wrong results.
That is not supported. The pruning comparison does not go through
Field::operator<, which bails on a tag difference; it goes through Range::less
to accurateLess, whose same-tag fast path is skipped on a tag mismatch, so it
falls to FieldVisitorAccurateLess, whose decimal arm reaches
DecimalField::operator< and compares through the wider of the two widths.
That is accurate across Decimal32 and Decimal64, so the pre-fix statistics
path produced the correct pruning verdict on this shape.

The change stays, on the contract instead: allow_stats is documented to
require that no conversion is needed, and on this shape convertField produces
a DecimalField<Decimal64> for a column whose type is Decimal(9, 2). Feeding
the decoded width to the predicate is simply the correct argument, and it is
worth pinning in a test rather than leaving to a refactor.

Adjusts one test comment accordingly. No executable change: the queries, the
reference and the fixtures are untouched.
@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

An independent model reviewed this diff cold, without the implementation notes, and a second
adversarial pass re-reviewed the full scope over three rounds. Findings and how each was resolved:

⚠️ The filter push-down test arm asserted nothing about push-down (04670_...sh). On this shape
allow_stats is false, so Reader::getHyperrectangleForRowGroup skips the statistics index
entirely; decimals are also ineligible for the bloom and dictionary filters
(parquetBloomFilterHash.cpp:36-41 accepts only none-or-int logical types), and the fixture had a
single row group. The arm's scalar result was therefore identical with push-down on, off or
declining. Fixed: two 10-row-group fixtures differing only in declared precision (2 bytes apart),
with a ParquetPrunedRowGroups assertion pinning that the mismatched shape declines pruning while
the well-formed control still prunes. Reverting only the allow_stats argument flips that verdict,
so the arm is live rather than merely green.

❌ A mechanism claim in the review's own first round was wrong, and had been written into the
commit message and a test comment.
It said the physical-width statistics value could prune row
groups holding matching rows, making the allow_stats change a wrong-results guard. It is not: the
pruning comparison does not use Field::operator< but Range::less -> accurateLess, which on a
tag mismatch dispatches to FieldVisitorAccurateLess, whose decimal arm compares through
decimalLess<MaxType> and is accurate across widths and scales (Field.h:120-125,
FieldAccurateComparison.cpp:201-202). The mutation measurement agrees: it pruned 8 of 10 row
groups, which is the correct count for the predicate, and the scalar result never changed. The
change stays, on its real justification: allow_stats requires that no type conversion be needed
(Decoding.h:150-161), and a DecimalField<Decimal64> for a Decimal(9, 2) column is a
conversion. The wording was corrected everywhere before publishing.

💡 The new comment uses "the column we decode into". Kept: the surrounding file already reads that
way (SchemaConverter.cpp:297, :482, :536).

💡 Test number 04670 is also claimed by several open pull requests. Kept: numeric prefixes shared
by distinct test basenames are normal here and are not enforced; the filenames are distinct.

No blockers were found in the source change itself. Every invariant carrier that sizes a write from
the decoder width or allocates from decoded_type was enumerated independently and checked:
Dictionary::index, memcpyIntoColumn, BigEndianDecimalFixedSizeConverter::convertColumn,
canReadDirectlyIntoColumn (whose chassert was a false invariant before this change), the plain,
delta and byte-stream-split decoders, and the statistics and page-index paths. All are correct once
the two widths agree, so no per-site bounds check is added.

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local -q "SELECT count(), sum(k) FROM file('04670_decimal_int64_precision9_dict.parquet', Parquet)" aborts with return code 134 on every attempt on a debug build of master 90042b2dc118. The chassert makes it deterministic in debug; release builds show the reported ~60% because there the overflow is silent corruption.
b Root cause explained? Yes. SchemaConverter::processPrimitiveColumn (SchemaConverter.cpp:1211-1292) chose the decoder from the physical type but the destination type from the declared precision alone, and never assigned out_decoded_type, so the caller fell back to the declared-precision type at :456 and Reader.cpp:1931 allocated a 4-byte-per-element Decimal32 while the INT64 decoder wrote 8.
c Fix matches root cause? Yes. The two widths are reconciled at the single function that decides both. No bounds check was added at any of the copy sites, which would have guarded the symptom at one of ten consumers and left the rest corrupting.
d Test intent preserved / new tests added? Yes. No existing test modified or weakened. New 04670_parquet_v3_decimal_physical_wider_than_destination.sh with 11 arms and 7 fixtures (23 KB total, well under the 1 MB limit). Two arms assert the row group pruning verdict from ParquetReadRowGroups/ParquetPrunedRowGroups, paired with a well-formed control that must still prune.
e Both directions demonstrated? Yes. On unfixed master 8 of the 11 arms abort with return code 134 (core dumped) at Decoding.cpp:1335 Dictionary::index, :1378 memcpyIntoColumn and :1709 BigEndianDecimalFixedSizeConverter<Int64>::convertColumn. With the fix every arm returns the values computed independently from the source data. The pruning arm is pinned separately: reverting only the allow_stats argument flips its verdict from not pruned to pruned. Build IDs recorded for the fixed, unfixed and mutated binaries.
f Fix is general across code paths? Yes. One change fixes both defective physical types (INT32/INT64 and FIXED_LEN_BYTE_ARRAY). All ten consumers of the width invariant read the same two values, so all are corrected; Decoding.cpp:1008 chassert(col.sizeOfValueIfFixed() == fixed_size_converter->input_size) becomes a true invariant rather than a false one. BYTE_ARRAY decimals were verified already-correct by reading the bucket chain.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Covered: INT64 dictionary and plain pages, FIXED_LEN_BYTE_ARRAY type_length 8 (adjacent bucket) and 16 (two-bucket skip), all under Nullable. Boundary: a value exceeding the declared precision raises DECIMAL_OVERFLOW; a narrower type_length still sign-extends. A five-shape well-formed matrix confirms those files take an unchanged path.
h Backward compatible? Yes. No setting added, no default changed, no serialization format touched, so no SettingsChangesHistory.cpp entry is required. Schema inference output is unchanged. The one deliberate change is that a file whose values exceed its own declared precision now raises DECIMAL_OVERFLOW instead of corrupting memory; reading it losslessly remains possible with an explicit wider type hint, so no workflow loses capability.
i Invariants and contracts preserved? Yes. The invariant established is that the decode target is exactly as wide as what the decoder writes, and it holds on every path including the error path (the narrowing cast throws rather than truncating). No concurrency contract is involved (schema conversion is single-threaded setup) and no lifetime changes (decoded_type is a shared_ptr moved into the out-parameter).

Session id: cron:clickhouse-impl-slot-7:20260802-153300

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

cc @grantholly-clickhouse @vitlibar, could you review this? SchemaConverter picked the decoder from the physical type but sized the destination column from the declared precision alone and never set out_decoded_type, so a DECIMAL(9, 2) stored as physical INT64 decoded 8 bytes per value into a 4-byte Decimal32 and wrote past the end of the column.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 3, 2026
@PedroTadim PedroTadim self-assigned this Aug 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8c797af]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug) FAIL
Logical error: ColumnBLOB should be converted to a regular column before usage (STID: 3059-0bf3) FAIL cidb IGNORED

AI Review

Summary

This PR fixes the Parquet DECIMAL width mismatch by making the decode target follow the physical-width converter and then narrowing through the existing castColumn path, with regression coverage for both INT64 and FIXED_LEN_BYTE_ARRAY plus the row-group statistics contract. I reviewed the current diff and prior discussion and did not find any remaining correctness, safety, test, or PR-metadata issues that warrant a new review comment.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 11/12 (91.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 3, 2026
# encoded value occupies (INT64 or FIXED_LEN_BYTE_ARRAY with precision 9 -> Decimal32). Reading
# any of them used to write past the end of the destination column.

echo '-- dictionary-encoded INT64, declared precision 9'

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.

@groeneai can you write the parquet files in the test to avoid creating more binary files in the repo?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 8c797af: all seven fixtures are gone, and the test writes them into $CLICKHOUSE_TMP/$CLICKHOUSE_TEST_UNIQUE_NAME with pyarrow, which the stateless image already pins (ci/docker/stateless-test/requirements.txt:6).

pyarrow always declares a precision that matches the physical width, so it cannot emit this shape directly. The test writes the wide precision and then rewrites the footer's compact-thrift DecimalType precision varint in place; the replacement is the same byte width, so every offset stays valid. That is the same in-test crafting idiom as 04561_parquet_v3_dictionary_filter_negative_page_count.sh.

I verified the generated files are byte-identical to the ones deleted here, so coverage is unchanged. The generator also reads back the physical type, type_length, row group count, per-row-group encodings and statistics of each file, because the write options only request them: a writer-option regression could otherwise have silently produced a different shape while every result assertion still passed through another decoder path. Mutating any of those four properties in the writer now aborts the test.


/// Decode into a column as wide as the converter writes; castColumn then narrows it to the
/// declared precision, throwing DECIMAL_OVERFLOW for values that don't fit.
auto decoded_type = createDecimal<DataTypeDecimal>(max_precision, scale);

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.

@groeneai are you sure this issue doesn't happen with other data types such as FixedString?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fair question, and I did not want to answer it from the existing narrative, since that narrative was already wrong once about FIXED_LEN_BYTE_ARRAY. I enumerated every branch of processPrimitiveColumn that pairs a converter with a destination type, and swept them empirically.

The invariant is that the converter's input_size must equal the destination element width. DECIMAL was the only branch where the two are computed from independent inputs: the converter from the physical type, the destination from the declared precision. Everywhere else the destination is derived from the physical type itself, so the two cannot disagree:

  • FixedString: the escape hatch at SchemaConverter.cpp:983-1006 only takes effect when size == fixed_string_type->getN(), so a narrower hint cannot reach it. The general FIXED_LEN_BYTE_ARRAY case builds DataTypeFixedString(element.type_length) from the physical length. A narrower hint therefore becomes a castColumn from the wider FixedString, which raises TOO_LARGE_STRING_SIZE rather than writing out of bounds. Verified with binary(4), binary(8) and binary(16) files read as every FixedString width from 1 to 26.
  • INTEGER: sets out_decoded_type to the physical width for 64-bit and uses output_size for 8 and 16 bits, which is the same reconciliation this PR adds for DECIMAL.
  • TIMESTAMP/TIME, DATE, UUID, FLOAT16, INT96, BOOLEAN, FLOAT, DOUBLE, BYTE_ARRAY: each pins both sides to one physical width, and UUID/FLOAT16 reject a mismatched type_length outright.
  • BYTE_ARRAY decimals bucket on precision only, so the converter width always equals the destination width.

Sweep: 19 fixtures covering every physical type (INT32, INT64, INT96, FLOAT, DOUBLE, BOOLEAN, BYTE_ARRAY, and FIXED_LEN_BYTE_ARRAY at lengths 2, 4, 8, 16, 26) against 21 hints each, including narrower and wider FixedString, integer, decimal and temporal types. On a debug build, zero aborted; every mismatch surfaced as an exception. The same sweep on pre-fix master also produced zero aborts, while the five DECIMAL fixtures in this test aborted there, so the sweep does have the sensitivity to catch this class.

@PedroTadim PedroTadim added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Aug 3, 2026
The seven fixtures were checked in as binaries. pyarrow can produce all of
them, so the test now writes them into its own temporary directory: pyarrow
picks the physical type, and a footer patch of the compact-thrift DecimalType
precision varint gives the declared precision that does not match it. The
replacement varint is the same byte width, so every offset stays valid. The
generated files are byte-identical to the ones removed here.

Also added an arm showing a hint of exactly the decoded width restores row
group pruning, which the previous arms did not cover.
The generator only requested a physical type and a dictionary encoding, so a
writer-option regression could have silently produced a different shape while
every result assertion still passed through another decoder path. It now reads
the physical type, type_length, row group count and per-row-group encodings
back out of each file.

The push-down arms printed a pruned or not-pruned verdict, which any positive
prune count satisfied. They now print the read and pruned counts, so pruning a
row group that holds matching rows would change the output.
@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

Note on the 00900_long_parquet_load_2 failure at 598bea8: it was caused by this PR and the fixture change above already resolves it.

00900_long_parquet_load_2.sh:54 sweeps data_parquet/ with find ... -iname '*.parquet' minus a literal EXCLUDE array, so any file added to that directory is swept. Five of the seven fixtures were deliberately malformed and a sixth must raise DECIMAL_OVERFLOW by design, which is the reported exception in stdout. They now live in the test's own temporary directory, so nothing this PR adds is swept and no EXCLUDE entry is needed.

I also ruled out the alternative, that the converter change altered how an existing corpus file reads: SELECT count(), sum(cityHash64(*)) over all 89 swept files gives identical output on this branch and on master, including 02588_data.parquet where the exception text began.

@grantholly-clickhouse

grantholly-clickhouse commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

@groeneai it might be worth add that we will now raise DECIMAL_OVERFLOW from castColumn, as mentioned in the new comment, to the changelog entry

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 8c797af

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug) / Logical error: ColumnBLOB should be converted to a regular column before usage (STID 3059-0bf3) marshalled column reaching a local consumer under enable_parallel_blocks_marshalling #111997 (mine, open)
Build (arm_release) / Post Hooks telemetry INSERT in build_profile_hook.py, job-level check_status = success a fix task is moved to pending (investigating at full effort, fixing-PR link to follow on this PR)

175/175 check-runs completed; Finish Workflow completed successfully.

The failing query is SELECT uniq(y) FROM view(SELECT DISTINCT y, ... FROM merge('default', 't.*')) SAMPLE 1 WITH ROLLUP, i.e. a Merge table consumed in-process, which is precisely the shape #111997
addresses: BlocksMarshallingStep is no longer added to plans whose blocks are consumed in the same
process. My diff here is a Parquet DECIMAL width fix in SchemaConverter.cpp plus one test, and the
failing query reads no Parquet at all. Breadth of the message over 45 days: 44 hits across 39
commit-and-check pairs, spread over AST fuzzer and Stress test flavours on both architectures,
including hits on master.

Session id: cron:our-pr-ci-monitor:20260803-163000

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 4, 2026
Merged via the queue into ClickHouse:master with commit 7904fee Aug 4, 2026
179 of 181 checks passed
@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Done, the changelog entry now mentions it.

I checked which shapes actually raise it before writing the sentence, since the error is narrower than "reading a decimal": out_decoded_type is only set when the decoded width differs from the width the declared precision maps to, so a well-formed file gains no cast and cannot throw. It is also value-conditional. Measured on the merged commit with this test's own fixtures: the mismatched file whose values fit reads 300 14083299.5, the one with an out-of-range value gives Code: 407 ... (DECIMAL_OVERFLOW), the same file with Decimal(18, 2) reads 300 10014083299.49, and the well-formed DECIMAL(18, 2) file is unchanged at 600 179997.

So the entry says reading such a file raises DECIMAL_OVERFLOW when a value does not fit the declared precision, rather than returning corrupted data, and reads losslessly with a hint at least as wide as the physical type. I dropped the sentence that had said the same thing in the description, so the body stays within its length budget, and I left castColumn out of the entry as an internal detail. The category is unchanged and both CI body checks still pass.

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 4, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 4, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 4, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 4, 2026
Backport #113046 to 26.7: Fix out-of-bounds write reading a Parquet DECIMAL wider than declared
PedroTadim added a commit that referenced this pull request Aug 4, 2026
Backport #113046 to 26.3: Fix out-of-bounds write reading a Parquet DECIMAL wider than declared
PedroTadim added a commit that referenced this pull request Aug 4, 2026
Backport #113046 to 26.5: Fix out-of-bounds write reading a Parquet DECIMAL wider than declared
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 4, 2026
PedroTadim added a commit that referenced this pull request Aug 4, 2026
Backport #113046 to 26.6: Fix out-of-bounds write reading a Parquet DECIMAL wider than declared
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @groeneai @PedroTadim @grantholly-clickhouse — while reviewing this PR I found the following:

Could you review the test PR and add the can be tested label if it looks good?
Happy to discuss — close anything that's wrong or already addressed.

groeneai pushed a commit to groeneai/ClickHouse that referenced this pull request Aug 5, 2026
UnamedRus pushed a commit to UnamedRus/ClickHouse that referenced this pull request Aug 12, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
DEC: Parquet DECIMAL stored wider than its precision implies (e.g. DECIMAL(9,2) as INT64) -> crash / memory corruption.
Effect in the production build a394e92: the upstream test returns wrong sums on the production build (e.g. 6978099.75 instead of 14083299.5); the Decimal512 shape (FIXED_LEN_BYTE_ARRAY wider than 32 bytes with a narrower declared precision) makes the Int512 converter write 64 bytes per value into a narrower column.
Upstream patch unchanged, with its test(s): 04670_parquet_v3_decimal_physical_wider_than_destination.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
…o reader bugs

tests/decimal512/tools/parquet/parquet_decimal_writer.py writes Parquet DECIMAL columns with
exactly the physical layout a test asks for (standard library only, no pyarrow): any
FIXED_LEN_BYTE_ARRAY width 1..64 with any declared precision, BYTE_ARRAY values of 0..64
bytes, PLAIN / BYTE_STREAM_SPLIT / DELTA_BYTE_ARRAY / RLE_DICTIONARY, UNCOMPRESSED or GZIP,
data page V1 or V2, REQUIRED or OPTIONAL, with an independent oracle for the expected text.

- 10317_parquet_decimal512_read_matrix: Decimal512 read through every value offset of the
  big-endian decoder (widths 1..64, lengths 0..64) in 16 layouts; passes on the production
  build and on the candidates (a coverage test for the padded read, no bug).
- 10318_parquet_decimal512_width_mismatch: a FIXED_LEN_BYTE_ARRAY wider than 32 bytes with a
  narrower declared precision (the Int512 decoder wrote 64 bytes per value into a 32/8/4-byte
  column: wrong sums and heap corruption on the production build) and a BYTE_ARRAY
  DECIMAL(100, 2) with DELTA_BYTE_ARRAY under PREWHERE (SIGSEGV on the production build);
  fixed by the backports of ClickHouse#113046 and ClickHouse#115703.

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 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-critical-bugfix 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

7 participants