Skip to content

Commit

Permalink
Fuzz Testing: rust-cid::varint_read_u64 panics on unwrap in no_std en…
Browse files Browse the repository at this point in the history
…vironment (#1719)

# Goal
The goal of this PR is to eliminate a panic discovered in fuzz testing.
Closes #1712 
# Discussion
A PR was created in `multiformats/rust-cid` and merged to refactor
`unwrap()` to return a Result in a `no_std` environment.
See PR here:
[multiformats/rust-cid/pull/145](multiformats/rust-cid#145)

`Cargo.toml` was updated to be pinned to the PR commit with the fix in
`rust-cid`

# Checklist
- [ ] Chain spec updated
- [ ] Custom RPC OR Runtime API added/changed? Updated js/api-augment.
- [ ] Design doc(s) updated
- [x] Tests added
- [ ] Benchmarks added
- [ ] Weights updated

---------

Co-authored-by: Matthew Orris <--help>
  • Loading branch information
mattheworris authored Oct 17, 2023
1 parent d88c343 commit cbbf507
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"lruntime",
"pkill"
],
"rust-analyzer.showUnlinkedFileNotification": false
// Set the features to use for cargo commands
"rust-analyzer.cargo.features": [
"frequency-no-relay"
]
}
9 changes: 4 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pallets/messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", default-features
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
# Frequency related dependencies
common-primitives = { default-features = false, path = "../../common/primitives" }
cid = { version = "0.10.1", default-features = false }
# Pinning a specific commit to fix an unwrap-panic issue: REVIEW: remove when cid > 0.10.1
cid = { git = "https://github.com/multiformats/rust-cid", rev = "86c79126d851316350ad106d0df3e4ae69071874", default-features = false}
multibase = { version ="0.9", default-features = false }

[dev-dependencies]
Expand Down
10 changes: 10 additions & 0 deletions pallets/messages/src/tests/other_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,16 @@ fn validate_cid_not_correct_format_errors() {
})
}

#[test]
fn validate_cid_unwrap_panics() {
new_test_ext().execute_with(|| {
// This should not panic, but should return an error.
let bad_cid = vec![102, 70, 70, 70, 70, 70, 70, 70, 70, 48, 48, 48, 54, 53, 53, 48, 48];

assert_noop!(MessagesPallet::validate_cid(&bad_cid), Error::<Test>::InvalidCid);
})
}

#[test]
fn map_to_response_on_chain() {
let payload_vec = b"123456789012345678901234567890".to_vec();
Expand Down

0 comments on commit cbbf507

Please sign in to comment.