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
Check RequestPair payload length during decoding #7292
Conversation
Ok(Self { request_id: u64::decode(buf)?, message: T::decode(buf)? }) | ||
let header = Header::decode(buf)?; | ||
// Check that the buffer is large enough for the payload length | ||
if buf.len() < header.payload_length { |
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.
@Rjected I don't think this is necessary, because Header::decode
check it already.
https://github.com/alloy-rs/rlp/blob/main/crates/rlp/src/header.rs#L71-L73
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.
yeah this looks redundant
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.
@Rjected I don't think this is necessary, because
Header::decode
check it already.https://github.com/alloy-rs/rlp/blob/main/crates/rlp/src/header.rs#L71-L73
Right, then let's just do the consumption check
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.
Done.
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.
as discussed, let's remove the initial payload_length
check against buf.len
as it's redundant, and we'll keep the consumption check. Looks great, the test is good!
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.
one smol nit then lgtm
return Err(alloy_rlp::Error::Custom( | ||
"Buffer did not consume exactly payload_length bytes", | ||
)); |
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.
Let's use RlpError::UnexpectedLength, we've used it in other places where we check the consumed bytes vs the payload length
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.
Done.
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.
looks good to me now, thanks!
close #7278