Skip to content

Return CAPACITY instead of terminating on oversized max_depth in parser allocate APIs#2665

Open
jmestwa-coder wants to merge 1 commit intosimdjson:masterfrom
jmestwa-coder:parser-max-depth-allocation-safety
Open

Return CAPACITY instead of terminating on oversized max_depth in parser allocate APIs#2665
jmestwa-coder wants to merge 1 commit intosimdjson:masterfrom
jmestwa-coder:parser-max-depth-allocation-safety

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

Description

Fixes a case where passing an oversized max_depth to parser allocation APIs could terminate the process instead of returning an error.

Previously, extreme values (e.g., SIZE_MAX and boundary variants) could reach new[] in a noexcept context, triggering std::bad_array_new_length and causing std::terminate.
This change introduces a conservative bound on depth-related allocations and validates inputs before allocation, ensuring invalid values return CAPACITY consistently.


Type of change

  • Bug fix
  • Optimization
  • New feature
  • Refactor / cleanup
  • Documentation / tests
  • Other

How to verify / test

  • Added parser_max_depth_tests using public APIs.
  • Verified behavior with boundary values:
    • SIZE_MAX
    • SIZE_MAX / 2
    • SIZE_MAX / 8
    • SIZE_MAX / 16
  • Before fix: process terminates (std::bad_array_new_length)
  • After fix: returns CAPACITY without termination
  • Existing tests (errortests, ondemand_error_tests) pass unchanged

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.

1 participant