-
Notifications
You must be signed in to change notification settings - Fork 773
fix(fuzz): fall back to fs operator so fuzz targets produce real coverage #7723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e8c52fd
fix(fuzz): fall back to fs service so fuzz targets work without env c…
tonghuaroot a1ceca8
fix(fuzz): add fuzz_path target and remove verbose comments
tonghuaroot cc7e718
fix(fuzz): register fuzz_path binary in Cargo.toml
tonghuaroot 1448df3
fix(fuzz): add fuzz_from_uri target for URI and config parsing
tonghuaroot 1468565
fix(fuzz): warn when falling back to the temporary fs operator
tonghuaroot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #![no_main] | ||
|
|
||
| use libfuzzer_sys::arbitrary::Arbitrary; | ||
| use libfuzzer_sys::fuzz_target; | ||
| use opendal::Operator; | ||
| use opendal::OperatorUri; | ||
|
|
||
| #[derive(Debug, Clone, Arbitrary)] | ||
| struct FuzzInput { | ||
| uri: String, | ||
| options: Vec<(String, String)>, | ||
| } | ||
|
|
||
| fuzz_target!(|input: FuzzInput| { | ||
| let _ = logforth::starter_log::stderr().try_apply(); | ||
|
|
||
| let _ = OperatorUri::new(&input.uri, input.options.clone()); | ||
| let _ = Operator::from_uri(input.uri.as_str()); | ||
| let _ = Operator::via_iter(&input.uri, input.options); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #![no_main] | ||
|
|
||
| use std::sync::LazyLock; | ||
|
|
||
| use libfuzzer_sys::arbitrary::Arbitrary; | ||
| use libfuzzer_sys::fuzz_target; | ||
| use opendal::Operator; | ||
| use opendal::tests::TEST_RUNTIME; | ||
| use opendal::tests::init_test_service; | ||
|
|
||
| #[derive(Debug, Clone, Arbitrary)] | ||
| struct FuzzInput { | ||
| path: String, | ||
| target: String, | ||
| } | ||
|
|
||
| static OPERATOR: LazyLock<Operator> = LazyLock::new(|| { | ||
| if let Some(op) = init_test_service().expect("operator init must succeed") { | ||
| return op; | ||
| } | ||
|
|
||
| log::warn!("OPENDAL_TEST is not set; falling back to a temporary fs operator"); | ||
| let root = std::env::temp_dir().join(format!("opendal-fuzz-{}", uuid::Uuid::new_v4())); | ||
| std::fs::create_dir_all(&root).expect("create fuzz root dir must succeed"); | ||
| Operator::new(opendal::services::Fs::default().root(&root.to_string_lossy())) | ||
| .expect("operator init must succeed") | ||
| .finish() | ||
| }); | ||
|
|
||
| async fn fuzz_path(op: Operator, input: FuzzInput) { | ||
| let _ = op.write(&input.path, "data".as_bytes()).await; | ||
| let _ = op.stat(&input.path).await; | ||
| let _ = op.list(&input.path).await; | ||
| let _ = op.create_dir(&input.path).await; | ||
| let _ = op.copy(&input.path, &input.target).await; | ||
| let _ = op.rename(&input.path, &input.target).await; | ||
| let _ = op.delete(&input.target).await; | ||
| let _ = op.delete(&input.path).await; | ||
| } | ||
|
|
||
| fuzz_target!(|input: FuzzInput| { | ||
| let _ = logforth::starter_log::stderr().try_apply(); | ||
|
|
||
| let op = OPERATOR.clone(); | ||
| TEST_RUNTIME.block_on(async { | ||
| fuzz_path(op, input.clone()).await; | ||
| }) | ||
| }); |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find! Do we need a fallback since we could always exit 1 and warn the user in fuzzer test? Because a test failure will force us to check CI status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @erickguan! Good question. The fallback is deliberately scoped to the unconfigured case only:
init_test_service()returnsOk(None)whenOPENDAL_TESTis unset,Ok(Some(op))when a service is selected and inits, andErr(..)when a selected service fails to init.init_test_service().expect("operator init must succeed")still panics loudly if someone explicitly sets e.g.OPENDAL_TEST=s3and it fails to init — a genuine misconfiguration does fail the run and shows up in CI, exactly as you want. Thefsfallback only kicks in for theOk(None)(nothing selected) case.The reason we fall back instead of
exit 1in that unconfigured case is OSS-Fuzz: it runs these binaries continuously with noOPENDAL_TESTenv set (that's the root cause of the zero coverage in #7722). If the target exited 1 / panicked when unconfigured, OSS-Fuzz would just record every run as an immediate crash and we'd still get no useful coverage — the same dead state we're fixing, only louder. Falling back tofs(which needs no external setup beyond a temp dir, and exercises OpenDAL's real path-handling code) gives the fuzzer something concrete to drive, while local/CI runs can still target any specific service viaOPENDAL_TEST.Happy to switch the unconfigured default to
memoryinstead if you'd prefer to avoid filesystem side effects — just let me know which you'd like.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a
log::warn!on the unconfigured fallback per your suggestion (pushed in 1468565) so it's visible in logs. PTAL!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the context. I understand the problem much better.
Indeed true. Having a silent fallback to fs works to bring back fuzz coverage. This would be a good fix.
Now considering a maintenance perspective, if
Ok(None)panics, any maintainers would be able to tell something requires for a fix. It might be stringent to understand fuzz setup but that would help someone else to jump in.Nevertheless, I would be happy to see we are getting fuzz coverage. So your call.