Skip to content

Audit user-controlled length and offset arithmetic for overflow #12325

Open

Description

@Rich-T-kid

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

We keep finding realistic integer-overflow bugs one callsite at a time. Recent examples include Parquet byte-array offsets (#12179 and #12215), MapBuilder offsets (#12052), FixedSizeList validation (#11859), and CSV allocation sizing (#9886).

These bugs tend to have the same shape: a length, offset, count, or allocation size derived from input is combined with unchecked + or *; overflow then bypasses a bounds check, panics, requests the wrong allocation, or violates an unsafe precondition. They are especially easy to miss on 64-bit development machines when the failure is reachable on supported 32-bit targets.

Fixing only the reported expression leaves sibling paths with the same problem and produces a stream of very small follow-up PRs. We should audit the realistic overflow boundaries once and fix them in coordinated batches.

Describe the solution you'd like

Audit arithmetic involving user-controlled or format-controlled lengths, offsets, counts, and capacities, focusing on:

  • parsing and decoding Parquet, IPC, CSV, JSON, and Avro input;
  • arithmetic used before slicing, unchecked indexing, pointer arithmetic, or buffer writes;
  • allocation and reserve sizes such as count * element_size and offset + length;
  • builders and kernels that produce i32/u32 offsets, dictionary keys, run ends, or other narrow physical values;
  • code whose correctness differs between 32-bit and 64-bit targets.

Use checked_add, checked_mul, checked_sub, or checked conversions where overflow is reachable, and return the existing crate error before allocation, mutation, or unsafe access. Add boundary tests that fail without the check, including a 32-bit-target test when 64-bit arithmetic cannot reproduce the overflow.

This should not be a mechanical replacement of every arithmetic operator. Loop counters and other arithmetic already bounded by a clear invariant should remain simple, and numeric kernels with documented wrapping, saturating, or overflow semantics are out of scope.

To avoid another flood of single-callsite PRs, contributors should claim a crate or subsystem, inspect sibling implementations and wrapper paths, and submit one coherent patch for that area. The issue can track the audited areas and any expressions that are intentionally left unchecked with their invariant.

Audit checklist

Check a leaf item only after its realistic candidates have been fixed or documented as safe. Check the crate when all of its leaf items are complete.

Core Arrow crates

  • arrow
    • Array facade and re-exports (array)
    • Compute facade and dispatch (compute)
    • Datatype facade (datatypes)
    • Utilities (util)
  • arrow-arith
    • Aggregates (aggregate)
    • Arithmetic, arity, and numeric kernels (arithmetic, arity, numeric)
    • Bitwise and boolean kernels (bitwise, boolean)
    • Temporal kernels (temporal)
  • arrow-array
    • Array implementations (array)
    • Builders (builder)
    • Record batches and array readers (record_batch, array_reader)
    • Iterators, run arrays, and delta handling (iterator, run_iterator, delta)
    • Temporal conversions and timezones (temporal_conversions, timezone)
    • FFI and stream interfaces (ffi, ffi_stream)
  • arrow-buffer
    • Allocation and memory pools (alloc, pool)
    • Buffers and builders (buffer, builder)
    • Bit and bitmap utilities (util)
    • Native values and byte conversions (native, bytes)
    • Arithmetic, bigint, and interval helpers (arith, bigint, interval)
  • arrow-data
    • ArrayData construction and validation (data)
    • Mutable transforms (transform)
    • ByteView layout and validation (byte_view)
    • Equality and decimal handling (equal, decimal)
    • FFI (ffi)
  • arrow-schema
    • Datatype parsing and display (datatype, datatype_parse, datatype_display)
    • Fields and schemas (field, fields, schema)
    • Extensions and metadata (extension, metadata)
    • FFI (ffi)

Compute crates

  • arrow-cast
    • Cast kernels and nested/dictionary dispatch (cast)
    • Parsing and local-time conversion (parse, local_time)
    • Display and pretty formatting (display, pretty)
    • Base64 conversion (base64)
  • arrow-cmp
    • Comparison kernels and type dispatch
  • arrow-ord
    • Comparators and ordering (cmp, comparison, ord)
    • Sorting and partitioning (sort, partition)
    • Ranking (rank)
  • arrow-row
    • Fixed-width row encoding (fixed)
    • Variable-width row encoding (variable)
    • List row encoding (list)
    • Run-end encoded rows (run)
  • arrow-select
    • Filter and take (filter, take)
    • Concat and interleave (concat, interleave)
    • Merge, zip, and window (merge, zip, window)
    • Coalescing (coalesce)
    • Dictionary handling (dictionary)
    • Null and union helpers (nullif, union_extract)
  • arrow-string
    • Length, substring, and concatenation (length, substring, concat_elements)
    • LIKE and regular expressions (like, binary_like, regexp)
    • String and binary predicates (predicate, binary_predicate)

Format and transport crates

  • arrow-avro
    • Readers, including async readers (reader)
    • Writers (writer)
    • Schema, codec, and compression (schema, codec, compression)
  • arrow-csv
    • Reader and record decoder (reader)
    • Writer (writer)
  • arrow-json
    • Readers and decoders (reader)
    • Writers and encoders (writer)
  • arrow-ipc
    • File and stream readers (reader)
    • File and stream writers (writer)
    • Compression and decompression (compression)
    • Schema and FlatBuffer conversion (convert)
  • arrow-flight
    • Encoding, decoding, and streams (encode, decode, streams)
    • Client and SQL support (client, sql)
    • Utilities, errors, and trailers (utils, error, trailers)
  • arrow-flight/gen
    • Generated binding boundaries and conversions (do not hand-edit generated code)

Parquet crates

  • parquet
    • Arrow array readers and decoders (arrow/array_reader, arrow/decoder, arrow/record_reader)
    • Arrow reader orchestration and selection (arrow/arrow_reader, arrow/async_reader)
    • Arrow writers and buffers (arrow/arrow_writer, arrow/async_writer, arrow/buffer)
    • Arrow schema conversion and push decoding (arrow/schema, arrow/push_decoder)
    • Column readers and writers (column/reader, column/writer, column/chunker)
    • Encoding and decoding (encodings/encoding, encodings/decoding)
    • File pages, metadata, and page indexes (file, file/metadata, file/page_index)
    • Compression and physical datatypes (compression, data_type, basic)
    • Schemas and records (schema, record)
    • Bloom filters, encryption, and geospatial paths (bloom_filter, encryption, geospatial)
    • Variant integration and utilities (variant, util)
  • parquet-geospatial
    • Bounding boxes and intervals (bounding, interval)
    • Geospatial types (types)
  • parquet-variant
    • Builders (builder)
    • Decoder and variant access (decoder, variant)
    • Paths and utilities (path, utils)
  • parquet-variant-compute
    • Arrow/Variant conversion (arrow_to_variant, variant_to_arrow, type_conversion)
    • Array builders and casts (variant_array, variant_array_builder, cast_to_variant)
    • Shredding and unshredding (shred_variant, unshred_variant)
    • Variant access and JSON conversion (variant_get, from_json, to_json)
  • parquet-variant-json
    • JSON parsing (from_json)
    • JSON serialization (to_json)
  • parquet_derive
    • Derive input parsing and generated field code (parquet_field)
  • parquet_derive_test
    • Generated-code boundary tests

Interop and support crates

  • arrow-integration-test
    • Datatype, field, and schema conversion
  • arrow-integration-testing
    • JSON integration helpers and validators
  • arrow-pyarrow
    • PyArrow FFI conversion boundaries

Acceptance criteria

  • Relevant crates and subsystems have been inventoried and tracked here.
  • Each candidate is fixed or documented as safe because of a concrete dominating bound.
  • Fixes cover sibling and wrapper paths, not only the originally reported expression.
  • Fallible paths report an error before partial mutation or unsafe access.
  • Applicable overflow boundaries have regression tests, including 32-bit coverage where needed.

Open issues expected to be resolved by this audit

This list contains open issues whose root cause is directly within the audit scope. Closing this audit should also close each of these issues.

Activity

  1. Rich-T-kid commented on Nov 18, 2026

    @Rich-T-kid
    ContributorAuthor

    a decent chunk of PR's I see recently are just this, AI is pretty good and dealing with things like this. Will test out

  2. mbutrovich commented on Nov 18, 2026

    @mbutrovich
    Contributor

    a decent chunk of PR's I see recently are just this, AI is pretty good and dealing with things like this. Will test out

    Perhaps something you can use https://github.com/mbutrovich/arrow-pbt for? Happy to accept PRs :)

  3. Rich-T-kid commented on Nov 19, 2026

    @Rich-T-kid
    ContributorAuthor

    PR #12340 completes the audit for arrow-csv, arrow-integration-test, arrow-integration-testing, and arrow-pyarrow. The three newly completed crate entries are now checked off.

  4. Mola-maker commented on Nov 28, 2026

    @Mola-maker
    Contributor

    I'd like to take the parquet-variant decoder and variant access section (decoder, variant). I'll audit offset, length and field-id arithmetic on the encoded bytes and send one PR for the section. I'll keep clear of the code #12309 touches.

  5. Mola-maker commented on Nov 28, 2026

    @Mola-maker
    Contributor

    Audited the parquet-variant decoder and variant access section. All offset, length and field-id arithmetic on encoded bytes is already checked, and crafted boundary inputs through the try_* APIs return errors without panics, so there is nothing to fix here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions