You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++][Python] JSON reader segfaults or silently corrupts values when a field changes between array/object and scalar across blocks #55833
Describe the bug, including details regarding any error messages, version, and platform.
pyarrow.json.read_json crashes the process, or silently returns wrong values, when a field is an array or object in one block and a scalar in a later block. With default options this happens on any file just over 1 MiB. If the conflicting rows are in the same block, it correctly raises ArrowInvalid: JSON parse error: Column(/c) changed from object to number.
Reproduced on pyarrow 12.0.1 through 26.0.1 (Linux x86-64) and with arrow::json::TableReader built from main @ 5ef973d.
Cause: blocks are parsed independently, and ChunkedStructArrayBuilder::InsertChildren passes a field's column to the child builder created for that field's first block without checking its kind (chunked_builder.cc#L419). The list and struct builders then checked_cast it to ListArray / StructArray, guarded only by a DCHECK (#L224-L225, #L318). They should instead return the same changed from X to Y error.
I reproduced this on macOS arm64 with PyArrow 26.0.1 and with a debug build of main. It also crashes in the other order, when a number or string comes first. That path fails in the converters.
Environment
macOS 26.5, arm64
PyArrow 26.0.1, Python 3.14.8
main at 6f040e8: Debug, ASan and UBSan, Apple clang 21.0.0, CMake 4.5.1
segfault in 18 of 20 script runs; the other 2 raised ArrowInvalid: Resize capacity must be positive with a negative size
read('{"c":[1]}', '{"c":1}')
segfault (20 of 20)
read('{"c":{"x":1}}', '{"c":1}')
no error, returns [{'c': {'x': 1}}, {'c': {'x': None}}] (20 of 20 script runs)
Expected: ArrowInvalid ... Column(/c) changed from ... to .... A single-block read already does this for object then number, and open_json does it for object and number in both orders.
All kind pairs on main
One field, one line per block, use_threads=false. Row is block 1, column is block 2.
Both traces above go through InsertChildren, the place the report points to. When the number comes first, the failure is further down: GetDictionaryArray only has a DCHECK. BooleanConverter already returns Invalid for a wrong input type.
A check in InsertChildren alone would miss values inside lists. {"c":[1]} then {"c":[{"x":1}]} also aborts at converter.cc:51.
The 246 tests in arrow-json-test pass on this build.
Not checked: Linux, x86, nested explicit schemas.
Terminal output
PyArrow 26.0.1: negative size error, then segfault. Traceback trimmed.
>>> read('{"c":1}', '{"c":{"x":1}}')
pyarrow.lib.ArrowInvalid: Resize capacity must be positive (requested: -504403121473044216)
>>> read('{"c":[1]}', '{"c":1}')
zsh: segmentation fault
Activity
RajaBabu15 commentedon Nov 29, 2026
I reproduced this on macOS arm64 with PyArrow 26.0.1 and with a debug build of main. It also crashes in the other order, when a number or string comes first. That path fails in the converters.
Environment
6f040e8: Debug, ASan and UBSan, Apple clang 21.0.0, CMake 4.5.1Reproduce on 26.0.1
read('{"c":1}', '{"c":{"x":1}}')ArrowInvalid: Resize capacity must be positivewith a negative sizeread('{"c":[1]}', '{"c":1}')read('{"c":{"x":1}}', '{"c":1}')[{'c': {'x': 1}}, {'c': {'x': None}}](20 of 20 script runs)Expected:
ArrowInvalid ... Column(/c) changed from ... to .... A single-block read already does this for object then number, andopen_jsondoes it for object and number in both orders.All kind pairs on main
One field, one line per block,
use_threads=false. Row is block 1, column is block 2.converter.cc:51,Check failed: (in->type_id()) == (Type::DICTIONARY)chunked_builder.cc:224,Check failed: (unconverted->type_id()) == (Type::LIST)std::bad_castNotImplemented: JSON conversion to ... is not supported. This looks like [C++] An unstable crash may appears when reading table from a json file. #20253, a separate path.InvalidStack: number then object on main (A)
Frames shortened.
Stack: object then number on main (C)
macOS crash report: list then number on 26.0.1
Argument lists and some namespaces shortened.
C++ reproducer and build commands
From the repository root:
Notes for a fix
InsertChildren, the place the report points to. When the number comes first, the failure is further down:GetDictionaryArrayonly has aDCHECK.BooleanConverteralready returnsInvalidfor a wrong input type.InsertChildrenalone would miss values inside lists.{"c":[1]}then{"c":[{"x":1}]}also aborts atconverter.cc:51.arrow-json-testpass on this build.PyArrow 26.0.1: negative size error, then segfault. Traceback trimmed.
main at
6f040e8, debug build: number then objectRajaBabu15 commentedon Nov 29, 2026
I am working on a fix for this.
apacheGH-55833: [C++] Reject non-list input in the list builder
apacheGH-55833: [C++] Reject non-struct input in the struct builder
apacheGH-55833: [C++] Reject nested input in number and string conver…
apacheGH-55833: [C++] Require a type error and both block orders
apacheGH-55833: [C++] Run every type change case with threads
apacheGH-55833: [C++] Check the JSON kind of each block in the builders
apacheGH-55833: [C++] Test number and string kind changes across blocks
apacheGH-55833: [C++] Check the input type in JSON converters before …
apacheGH-55833: [C++] Reject JSON kind changes between blocks
apacheGH-55833: [C++] Test JSON kind changes across blocks