Uh oh!
There was an error while loading. Please reload this page.
Avoid quadratic block comment indent allocation - #47
Open
SantanDon wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes#38.
Summary
OSS-Fuzz issue 63220 reports a
fuzz_parsetimeout on a malformed JSON5 input. The timeout is driven by block-comment indentation handling:add_block_comment()constructs an indent-sizedStringfor every block comment, even when the comment is single-line and the string is never used.The published OSS-Fuzz reproducer contains 141,675 block-comment starts, many at large column offsets. Across that input, the existing code requests roughly 7.67 billion bytes worth of transient indent strings while parsing an 817,615-byte file.
This change checks the required leading-space prefix directly in the comment line instead of allocating a new indent string. Multiline alignment behavior is unchanged.
Reproducer / performance
Using the public reproducer from OSS-Fuzz issue 63220 on current
master(25a594b7daacb4605241dc8d63e7c36411208c87):The parser returns the same error result in both cases. This is about a 16x reduction on the minimized testcase; the OSS-Fuzz ASan job reported the original input exceeding its 60-second timeout.
Validation
cargo test --lib: 45 passed--cap-lints allow; currenttests/lib.rsotherwise fails at the crate-level#![deny(missing_docs)]lint before tests run, which is already the subject of bugfix: fix missing_docs error #44cargo test --example formatjson5: 2 passedrustfmt --check src/parser.rs: passedNo API or output-format changes are intended.