Skip to content

fix(fuzz): use the real reader settings keys in the fuzzer - #1730

Merged
baylesj merged 1 commit into
masterfrom
fix-fuzz-settings-keys
Oct 26, 2026
Merged

baylesj merged 1 commit into
masterfrom
fix-fuzz-settings-keys

Conversation

@baylesj

@baylesj baylesj commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

src/test_lib_json/fuzz.cpp set most CharReaderBuilder settings under names with a trailing underscore (allowComments_, strictRoot_, rejectDupKeys_, …). newCharReader() only reads the names without the underscore, so those keys were ignored, and failIfExtra was also set twice. Only failIfExtra and collectComments ever varied, which means OSS-Fuzz has been fuzzing the reader with every other mode left at its default.

The existing FuzzTest/fuzzDoesntCrash unit test didn't catch this: its input, "{}", is shorter than the 4-byte settings header, so the fuzzer returned before it reached the settings code.

Fix

  • Use the real key names. Each setting keeps its bit position, and the duplicate failIfExtra bit (6) now controls skipBom.
  • Bit 11 turns on a small stackLimit, taken from the upper 16 bits, so the depth-limit error paths are reachable without huge inputs.
  • Call abort() if CharReaderBuilder::validate() rejects the settings, so a misspelled key crashes immediately instead of silently disabling a mode.
  • fuzzDoesntCrash now runs inputs with no settings, all settings, and a stack limit of 1.

The proto fuzzer currently in OSS-Fuzz has the same misspelled keys; #1724 already fixes them in its copy.

The fuzzer set most CharReaderBuilder settings under names with a
trailing underscore ("allowComments_", "strictRoot_", ...), which
newCharReader() does not read, and set failIfExtra twice. As a result
only failIfExtra and collectComments ever varied; every other reader
mode was stuck at its default.

Use the real key names, give the duplicate failIfExtra bit to skipBom,
and add an optional small stackLimit (bit 11, value from the upper 16
bits) so the depth-limit error paths are reachable. Abort if
CharReaderBuilder::validate() rejects the settings, so a misspelled key
fails loudly instead of silently disabling a mode.

The FuzzTest unit test only passed "{}", which is shorter than the
4-byte settings header and returned before touching any settings.
Exercise no settings, all settings, and a tiny stack limit.

In a local 2-minute libFuzzer run from test/data seeds, json_reader.cpp
edge coverage goes from 465 to 570 of 1996.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 40342106111

Coverage increased (+0.02%) to 89.926%

Details

  • Coverage increased (+0.02%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 2740
Covered Lines: 2615
Line Coverage: 95.44%
Relevant Branches: 2640
Covered Branches: 2223
Branch Coverage: 84.2%
Branches in Coverage %: Yes
Coverage Strength: 23835.16 hits per line

💛 - Coveralls

@greptile-apps

greptile-apps Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Fixes the reader settings used by the fuzz harness.

  • The JSON reader fuzzer now varies real reader settings from each input.

No actionable issues found. Tests were not run during this review.

Reviews (1) · Last reviewed commit: "fix(fuzz): use the real reader settings ..." · Reviewed by Greptile

@baylesj
baylesj merged commit 839a454 into master Oct 26, 2026
53 checks passed
@baylesj
baylesj deleted the fix-fuzz-settings-keys branch October 26, 2026 14:57
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