Skip to content

fix: enforce max_array_size during JSON array decode - #25

Merged
ruoka merged 1 commit into
masterfrom
cursor/critical-bug-management-265f
Jul 27, 2026
Merged

fix: enforce max_array_size during JSON array decode#25
ruoka merged 1 commit into
masterfrom
cursor/critical-bug-management-265f

Conversation

@cursor

@cursor cursor Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

max_array_size (100M elements) was declared as a DoS limit but never checked during JSON array parsing, so arrays could grow without bound.

Bug and impact

  • Trigger: Parse a JSON array (top-level, nested, or under an object) with more than max_array_size elements.
  • Impact: Unbounded memory growth / DoS; the documented limit was not enforced.

Root cause

The constant existed next to the enforced max_string_length / max_nesting_depth caps, but array element acceptance paths (array_first / array_next) never counted or rejected oversized arrays.

Fix

  • Track a per-nested-array element count on [ / ].
  • Reject when a new element would exceed the limit (before the value is built).
  • Allow a custom limit on decoder for fast regressions.

Validation

  • Added ArraySizeLimitEnforced covering exact limit, overflow, nested arrays, arrays under objects, and empty/short arrays.
  • ./tools/CB.sh debug test --tags='\[xson\]' — 422/422 passed.
Open in Web View Automation 

The DoS cap was declared but never checked, so arrays could grow without
bound. Count elements per nested array and reject past the limit; allow a
small custom limit for a fast regression test.

Co-authored-by: Kaius  Ruokonen <ruoka@users.noreply.github.com>
@ruoka
ruoka force-pushed the cursor/critical-bug-management-265f branch from 1275a94 to 48d2f62 Compare July 27, 2026 14:56
@ruoka
ruoka marked this pull request as ready for review July 27, 2026 14:56
@ruoka
ruoka merged commit 021c594 into master Jul 27, 2026
@ruoka
ruoka deleted the cursor/critical-bug-management-265f branch July 27, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants