Skip to content

Limit nesting depth by default to guard against stack overflow #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

spyoungtech
Copy link
Owner

This change adds a limit to the nesting depth by default to guard against stack overflow in cases where arrays and/or objects are deeply nested.

Additionally, a new feature, unlimited_depth has been added (disabled by default) as an easy way for users to bypass this limit.

JSON5Parser structs also have a new constructor with_max_depth to allow a parser to be constructed with a user-specified max depth.

The default limit aims to prevent stack overflows in most normal circumstances on tier 1 operating systems. Some targets with extremely limited stack space may still experience stack overflows. The limit is adjusted based on operating system and the presence of the debug_assertions configuration, intended to allow higher default limits for release builds.

At time of writing, the default limit is as follows:

Operating System Depth limit with debug_assertions Depth limit without debug_assersions
Windows 700 2000
All other OS 1000 3000

@spyoungtech
Copy link
Owner Author

Because parse_unary is also implemented recursively, the depth limit also applies to unary signs.

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