Repository navigation
Conversation
`GenericReader::read` resized `Array` and `Map` to the block count declared in the file, and `DataFileReaderBase::readDataBlock` let `snappy::Uncompress` allocate the length prefix of the compressed data. Grow the containers with the decoded items, and validate the snappy buffer first.
An `Array` whose items encode to zero bytes (`null`, an empty record, a zero-length `fixed`) is not bounded by the input, so the block count declared in the file still drove unbounded growth. Cap the total item count of such arrays at 2^24 and throw `avro::Exception` beyond it.
motsc
added a commit
to ClickHouse/ClickHouse
that referenced
this pull request
Nov 7, 2026
`contrib/avro` now caps arrays whose items encode to zero bytes (ClickHouse/avro#48).
Weight the zero-byte budget by the number of GenericDatum objects an item materializes (a record builds one per field), and charge it only when decoding the item did not advance the input stream. Items that consume input are bounded by the input and are no longer limited when resolving schemas.
…at reading materialized
…the input advances The budget for values that take no bytes was shared by a whole top-level datum and only charged array items that consumed no input, so it rejected valid input-bounded data (`array<array<null>>` with 70000 items) and did not see default maps, strings or union branches at all. Array items, map entries, selected union branches and strings that are not backed by the input are now charged when they are created, to a budget of 65536 datums that refills whenever `Decoder::inputPosition` advances. A stretch of the input that does not advance is bounded however arrays, maps, records and defaults are nested, and input that does advance is bounded by its size. `JsonParser::position` no longer counts the token that was peeked but not consumed, so JSON arrays of scalars are not mistaken for items that take no bytes.
…cted `GenericReader` charged the datums of a selected union branch after `selectBranch` had already constructed them, and constructing a branch builds the datum of every field of a record eagerly. A union `["null", R]` where `R` has 70000 fields therefore allocated the whole record, a couple of MiB from a one-byte index, before the budget was consulted. The count of the branch now comes from its schema, with `datumNodeCount`, and is charged before `selectBranch` runs. Only the selected branch is counted, so a recursive branch is not rejected for the branches that it could reach, and unions at the root, in records, array items, map values and the unions that a resolving decoder selects are all covered. `GenericDatum::branchSchema` returns the schema of a branch of a union datum without constructing it, and reports an index outside the union as `Exception`.
GenericFixed resized its value to the size declared by the schema when constructed, and BinaryDecoder::decodeFixed resized to the declared size before reading, so a schema declaring a huge fixed allocated it before any input was read. The constructor now leaves the value empty, decodeFixed reads in bounded chunks, and a fixed that is filled by a default is charged to the datum budget like strings and bytes. GenericWriter rejects a fixed whose value size differs from its schema.
…backs it A `GenericDatum` constructed from a schema constructed the datums of every field of every record of the schema, which is exponential in the size of a schema whose records refer to a named record several times, before any input was read. `ShallowTag` constructs a datum whose record has no fields, whose array and map are empty and whose union holds its shallow first branch. `GenericReader` constructs the root, the items, the entries, the union branches and the fields shallow and charges each to the budget just before it constructs it, so a value that the input backs is not rejected for the datums that it holds, and what a stretch of the input that does not advance constructs is bounded by the budget. The constructors without the tag are unchanged and stay eager. The default of a record or union field of a schema is built shallow, so compiling a schema constructs what its default holds and not the datums of the schema.
Use the default buffer data pointer without indexing its first element. Records made entirely of null fields have an empty binary default, so indexing element zero triggers a hardened vector assertion before resolving can read the default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allocations driven by malformed
Avrofiles previously preceded validation.GenericReader::readresizedArrayandMapvalues to their declared counts,DataFileReaderBasepassed unchecked snappy lengths tosnappy::Uncompress, and values with no input bytes could expand without a schema-size bound.This validates snappy before allocation, grows containers as data is decoded, limits zero-input expansion, and reads
string,bytesandfixedvalues incrementally. Reading throughGenericReadernow constructs records one field at a time, including the root and resolved defaults, usingShallowTag. The call can be interrupted while JSON or resolving decoders are active.Ordinary eager
GenericDatum(schema)construction and its const default access are unchanged. Untrusted-data readers should useShallowTag, as the Iceberg and Hudi metadata paths do.Found by fuzzing. The legacy and resolving decoders pass their existing suites plus the allocation and compatibility regression cases.