Repository navigation
Share the decoder's argument queue to avoid superlinear option-skip cost #767
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 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
db93d7a
Bound wire-declared structural lengths in the decoder (candid 0.10.36)
lwshang 49e785f
Drop version bump; keep fix under an Unreleased changelog section
lwshang 6df9977
Address review: doc max_type_len arg bound, strengthen decoder tests
lwshang 8d37747
Narrow to the argument-queue sharing fix; drop the structural-count caps
lwshang 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
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,60 @@ | ||
| //! Wire-declared structural lengths must not turn into oversized up-front | ||
| //! allocations. A length prefix need not match the bytes actually present, so an | ||
| //! out-of-range argument, field, function-arity or method count must fail as an | ||
| //! ordinary parse error rather than reserving a correspondingly large buffer. | ||
| //! | ||
| //! The type table already carries this bound; these cases cover the remaining | ||
| //! length prefixes so that every `count`-sized allocation stays proportional to | ||
| //! the type description rather than to the raw byte length. | ||
|
|
||
| use candid::de::IDLDeserialize; | ||
| use candid::Encode; | ||
|
|
||
| /// Drive the full deserialize, including skipping every declared argument, so a | ||
| /// healthy parser rejects a malformed length and returns normally. | ||
| fn decode(hex: &str) -> candid::Result<()> { | ||
| let bytes = hex::decode(hex).unwrap(); | ||
| let mut de = IDLDeserialize::new(&bytes)?; | ||
| while !de.is_done() { | ||
| de.get_value::<candid::Reserved>()?; | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn argument_count_out_of_range_is_rejected() { | ||
| // "DIDL" 00 <uleb arg-count = 2^62> with an empty type table and no args. | ||
| assert!(decode("4449444c00808080808080808040").is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn record_field_count_out_of_range_is_rejected() { | ||
| // "DIDL" 01 6c <uleb field-count = 2^62>: a record type declaring 2^62 fields. | ||
| assert!(decode("4449444c016c808080808080808040").is_err()); | ||
| } | ||
|
lwshang marked this conversation as resolved.
Outdated
|
||
|
|
||
| #[test] | ||
| fn function_arity_out_of_range_is_rejected() { | ||
| // "DIDL" 01 6a <uleb arg-len = 2^62>: a func type declaring 2^62 arguments. | ||
| assert!(decode("4449444c016a808080808080808040").is_err()); | ||
| } | ||
|
lwshang marked this conversation as resolved.
Outdated
|
||
|
|
||
| #[test] | ||
| fn service_method_count_out_of_range_is_rejected() { | ||
| // "DIDL" 01 69 <uleb method-count = 2^62>: a service declaring 2^62 methods. | ||
| assert!(decode("4449444c0169808080808080808040").is_err()); | ||
| } | ||
|
|
||
| /// A well-formed message with trailing arguments that are skipped through the | ||
| /// option/backtracking path still round-trips. This exercises the shared | ||
| /// argument queue across the top-level pops that follow a backtracking clone. | ||
| #[test] | ||
| fn trailing_optional_arguments_still_decode() { | ||
| // encode (nat32, opt nat32, opt nat32) and decode only the first value, | ||
| // letting `done()` drain the rest through the skip path. | ||
| let bytes = Encode!(&7u32, &Some(8u32), &Some(9u32)).unwrap(); | ||
| let mut de = IDLDeserialize::new(&bytes).unwrap(); | ||
| let first: u32 = de.get_value().unwrap(); | ||
| assert_eq!(first, 7); | ||
| de.done().unwrap(); | ||
| } | ||
|
lwshang marked this conversation as resolved.
Outdated
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.