Skip to content

Avoid quadratic block comment indent allocation - #47

Open
SantanDon wants to merge 1 commit into
google:masterfrom
SantanDon:fix/ossfuzz-63220-block-comment-indent
Open

Avoid quadratic block comment indent allocation#47
SantanDon wants to merge 1 commit into
google:masterfrom
SantanDon:fix/ossfuzz-63220-block-comment-indent

Conversation

@SantanDon

Copy link
Copy Markdown

Fixes#38.

Summary

OSS-Fuzz issue 63220 reports a fuzz_parse timeout on a malformed JSON5 input. The timeout is driven by block-comment indentation handling: add_block_comment() constructs an indent-sized String for 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):

input size: 817,615 bytes
before: 4,720,363 us (release build)
after: 289,199 us (release build)

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
  • integration test binary: 38 passed after compiling the existing test target with --cap-lints allow; current tests/lib.rs otherwise fails at the crate-level #![deny(missing_docs)] lint before tests run, which is already the subject of bugfix: fix missing_docs error #44
  • cargo test --example formatjson5: 2 passed
  • rustfmt --check src/parser.rs: passed

No API or output-format changes are intended.

Sign up for freeto 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.

OSS-Fuzz issue 63220

1 participant

@SantanDon