Skip to content

guard recursive comparisons against stack exhaustion - #1078

Open
atharvmantri wants to merge 3 commits into
DaveGamble:masterfrom
atharvmantri:fix/limit-comparison-recursion
Open

guard recursive comparisons against stack exhaustion#1078
atharvmantri wants to merge 3 commits into
DaveGamble:masterfrom
atharvmantri:fix/limit-comparison-recursion

Conversation

@atharvmantri

@atharvmantri atharvmantri commented Sep 14, 2026

Copy link
Copy Markdown

Summary

Bound recursive JSON comparisons by the existing CJSON_NESTING_LIMIT.

cJSON_Compare() recursively descends arrays and objects without a depth check, and the private comparison used by JSON Patch test and merge-patch generation has the same behavior. Deep or cyclic caller-supplied trees can therefore exhaust the native stack even though parsing, printing, and duplication already enforce recursion limits.

This change keeps the public API unchanged, threads a depth counter through the internal recursion, and returns false when the configured limit is reached. The merge-patch generator also carries the limit instead of re-entering through the public wrapper, and propagates a failed nested patch rather than silently dropping it. Both comparison paths use the existing project-wide limit rather than introducing a second policy.

Related: #1073.

Testing

  • git diff --check
  • Verified all recursive calls use the depth-carrying helpers, all entry points start at depth zero, and nested merge-patch failure is propagated.
  • A native C compiler is not available in the submission environment, so the project test suite could not be run locally.

Copilot AI lite review requested due to automatic review settings September 14, 2026 03:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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