Repository navigation
fix(fuzzing): return 0 (not 1) from the size guard in every harness - #3579
Merged
wasphin merged 1 commit intoOct 5, 2026
Merged
Conversation
LLVMFuzzerTestOneInput may only return 0 (input consumed) or -1 (input rejected); libFuzzer asserts this after every call (compiler-rt/lib/fuzzer/FuzzerLoop.cpp:622) and runs the empty input first, so every harness here aborts an assert-enabled libFuzzer at startup. Returning 0 keeps out-of-range inputs out of the corpus (the harness body is still skipped) and matches the convention newer harnesses already use. All 18 test/fuzzing/fuzz_*.cpp harnesses share the same guard. Signed-off-by: li-lizhe <147392333@qq.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
All affected harnesses now satisfy libFuzzer’s callback contract without changing in-range processing.
Review effort: Balanced
Findings: None
What changed in this PR
Updates all fuzzing harness size guards to return a valid libFuzzer result, preventing startup assertions on empty input.
Changes:
- Replaces invalid
return 1withreturn 0in all 18 harnesses. - Leaves in-range fuzzing logic unchanged.
| File | Description |
|---|---|
test/fuzzing/fuzz_uri.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_thrift.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_streaming.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_sofa.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_shead.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_redis.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_mongo.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_memcache.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_json.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_hulu.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_http.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_http_parser.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_hpack.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_esp.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_couchbase.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_butil.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_baidu_rpc.cpp |
Fixes size-guard return value. |
test/fuzzing/fuzz_amf.cpp |
Fixes size-guard return value. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
|
LGTM |
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 free
to 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.
LLVMFuzzerTestOneInputmay only return0(input consumed) or-1(input rejected). libFuzzer enforces this after every call —assert(CBRes == 0 || CBRes == -1)incompiler-rt/lib/fuzzer/FuzzerLoop.cpp:622— and its first input is the empty one, so every harness here aborts an assert-enabled libFuzzer at startup.All 18 harnesses under
test/fuzzing/open withFixes #3578 —
return 1;becomesreturn 0;in all 18 files.return -1would also satisfy the contract if these inputs should be rejected outright;return 0is used here because it matches what the newer harnesses already do (test/fuzzing/fuzz_rtmp.cppin #3516). Either way the body is still skipped, so behaviour for in-range inputs is unchanged.Verification
Standalone driver asserting the exact contract libFuzzer enforces (
assert(r == 0 || r == -1), clang 17.0.6, openEuler 24.03, aarch64):LLVMFuzzerTestOneInput(empty, 0)return 1)1return 0)0return-value contract satisfied: CBRes=0, exit 0The fixed harness also links and runs under a real libFuzzer (
clang++ -std=c++17 -fsanitize=fuzzer,./fuzz -runs=5→Done 5 runs in 0 second(s), exit 0).Not tested: a full brpc build + OSS-Fuzz run — the harnesses link the brpc libraries, which were not built here. The change is a single return value per file and touches no harness logic.