Skip to content

Use CAPACITY for inputs exceeding DOM size limit#2663

Open
jmestwa-coder wants to merge 1 commit intosimdjson:masterfrom
jmestwa-coder:dom-oversize-capacity-check
Open

Use CAPACITY for inputs exceeding DOM size limit#2663
jmestwa-coder wants to merge 1 commit intosimdjson:masterfrom
jmestwa-coder:dom-oversize-capacity-check

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

Short title (summary)

Return CAPACITY for oversize DOM allocation in parse flow


Description

  • Added an explicit bound check in document::allocate to return CAPACITY when the requested size exceeds SIMDJSON_MAXSIZE_BYTES.

  • Previously, oversized declared input lengths could reach allocation and return MEMALLOC, which misclassifies a capacity-limit violation as an allocation failure.

  • This ensures consistent error semantics: invalid sizes return CAPACITY, while real allocation failures continue to return MEMALLOC.

  • Issue reproduced: parsing with a declared length larger than the supported DOM capacity returns incorrect error classification.


Type of change

  • Bug fix
  • Optimization
  • New feature
  • Refactor / cleanup
  • Documentation / tests
  • Other (please describe):

How to verify / test

  • Added regression test: parser_parse_huge_declared_length_capacity
    • Uses parser.parse(...) with declared length SIMDJSON_MAXSIZE_BYTES + 1
    • Verifies that the parser returns CAPACITY
  • Test exercises real parse flow (parse → ensure_capacity → document::allocate)
  • Designed to be CI-safe:
    • Uses std::string input to avoid compiler object-size warnings (-Werror)
    • Includes guard to prevent overflow on 32-bit platforms

Run locally:

cmake -B build -D SIMDJSON_DEVELOPER_MODE=ON
cmake --build build
ctest --test-dir build

Checklist before submitting
- [x] I added/updated tests covering my change (if applicable)
- [x] Code builds locally and passes my check
- [ ] Documentation / README updated if needed
- [x] Commits are atomic and messages are clear
- [ ] I linked the related issue (if applicable)

Final notes
- Change is intentionally minimal and limited to error classification for oversized inputs.
-No impact on valid parsing behaviour.
-Test is structured to be portable and stable across compilers and architectures.

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