Skip to content

Heap buffer overflow in cuJSONLinesIterator::gotoArrayIndex #5

Closed

Description

@TarekIbnZiad

Heap buffer overflow in cuJSONLinesIterator::gotoArrayIndex

Environment

  • cuJSON commit: 2ac7d3dcd7ad1ff64ebdb14022bf94c59b3b4953 (branch master)
  • OS: Ubuntu 22.04.5 LTS
  • GPU: NVIDIA A40 (Ampere, sm_86)
  • NVIDIA driver: 590.48.01
  • CUDA toolkit: 13.1 (nvcc V13.1.115)

Component

cuJSON — JSON Lines iterator, cuJSONLinesIterator::gotoArrayIndex (paper_reproduced/src/query/query_iterator.cpp:269-315)

Severity

High (CWE-122, Heap-based Buffer Overflow).

Description

cuJSONLinesIterator::gotoArrayIndex mirrors the standard iterator traversal logic and can advance nextNode beyond the valid parsed structure when an operation sequence requests an invalid array element, producing a host-side heap-buffer-overflow.

Root cause

The JSON Lines iterator shares the standard iterator's traversal logic and likewise lacks bounds checks around nextNode, node, pair_pos, and structural-array accesses. An out-of-range array index drives the iterator past the parsed structure and reads past the heap buffer.

Call path:

harness LLVMFuzzerTestOneInput
  -> cuJSONLinesIterator
  -> cuJSONLinesIterator::gotoArrayIndex   (heap-buffer-overflow)

Impact

Malformed JSON Lines input plus iterator operations can crash the host process and risk adjacent heap access in services that expose iterator navigation.

Reproduction

CUDA_HOME=${CUDA_HOME:-/usr/local/cuda}
nvcc -std=c++17 -arch=native -O2 \
  -I<cujson-src> -I${CUDA_HOME}/include \
  -Xcompiler -fsanitize=address,-fno-omit-frame-pointer \
  llm_harness_cuJSONLinesIterator.cu harness_afl_main.cpp \
  --compiler-bindir g++-13 -L${CUDA_HOME}/lib64 -lcudart \
  -Xlinker -fsanitize=address \
  -o /tmp/cujson_cuJSONLinesIterator_asan.bin

ASAN_OPTIONS=protect_shadow_gap=0:detect_leaks=0 \
  /tmp/cujson_cuJSONLinesIterator_asan.bin trigger.bin

Sanitizer evidence

==3418215==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7b9d4b70457f
SUMMARY: AddressSanitizer: heap-buffer-overflow in cuJSONLinesIterator::gotoArrayIndex(int)

Suggested fix

Add explicit bounds checks around nextNode, node, pair_pos, and structural-array accesses. Reject out-of-range array indices before traversal mutates iterator state.

Attachments

The following files from this finding are attached:

  • llm_harness_cuJSONLinesIterator.cu
  • harness_afl_main.cpp
  • trigger.bin
  • asan.log

Archive.zip

Activity

  1. self-assigned this
    on Jun 24, 2026
  2. ashkanvg commented on Sep 10, 2026

    @ashkanvg
    Collaborator

    Fixed by #16, which lands the bounds checks from #10 with a corrected byte-length bound.

    Verified on A100 (sm_80): with AddressSanitizer, master reports heap-buffer-overflow in cuJSONLinesIterator::getChar — the structural[0] = 0 sentinel makes pos = -1, so inputJSON[-1] is read on every getChar(0). After #16 the same adversarial navigation runs (index 1000000, 2147483000, and 40 chained gotoArrayIndex(0) calls) are completely clean, and getChar(0) correctly returns '['.

    Query results are byte-identical to the previous master across the paper's TT1-TT4 patterns plus deep-record probes, and all four shipped entry points produce identical output at scale (842 MB / 873 MB datasets, 61M elements).

    The fix was applied to all three copies of the iterator, including paper_reproduced/user_interface/src/query/ which the original PR did not cover.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions