Skip to content

Ignore pathologically large depths longer than strlen#67

Merged
crazyxman merged 2 commits intocrazyxman:masterfrom
TysonAndre:depth-ignore
Oct 1, 2022
Merged

Ignore pathologically large depths longer than strlen#67
crazyxman merged 2 commits intocrazyxman:masterfrom
TysonAndre:depth-ignore

Conversation

@TysonAndre
Copy link
Copy Markdown
Collaborator

@TysonAndre TysonAndre commented Sep 29, 2022

Closes #66

For example, for parsing strings shorter than the depth, e.g. simdjson_decode('{}', true, 1000000000), we only need a depth that's at least strlen('{}') === 2 to get identical results for invalid json.

PHP programmers may assume that a large depth is a safe way to avoid depth errors because it was safe for json_decode

To avoid allocating too much virtual memory and wasting page table entries or potentially fatal out of memory errors, reduce depth to a safe value behaving the same way if the requested depth is larger than the allocated depth, larger than the string length, and exceeds 100000.
Do this in a way that reduces reallocations.

Closes crazyxman#66

For example, for `simdjson_decode('{}', true, 1000000000)`,
we only need a depth that's at least 2 to get identical results.

PHP programmers may assume that a large depth is a safe way to avoid
depth errors because it was safe for `json_decode`

To avoid allocating too much virtual memory and wasting page table
entries or potentially fatal out of memory errors,
reduce depth to a safe value behaving the same way if the requested depth is
larger than the allocated depth, larger than the string length, and
exceeds 100000.
Do this in a way that reduces reallocations.
@TysonAndre
Copy link
Copy Markdown
Collaborator Author

I expect 2.0.4 to be released tomorrow at the earliest, if it's approved by then

@crazyxman crazyxman merged commit 2cb3982 into crazyxman:master Oct 1, 2022
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.

Ignore pathologically large depths such as simdjson_decode('{}', true, 1000000000)

2 participants