Skip to content
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

Merged
merged 5 commits into from Mar 25, 2024

Conversation

AbnerZheng
Copy link
Contributor

close #7278

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 {
Copy link
Contributor Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this looks redundant

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@AbnerZheng AbnerZheng marked this pull request as ready for review March 22, 2024 04:45
Copy link
Member

@Rjected Rjected left a 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!

@AbnerZheng AbnerZheng requested a review from Rjected March 23, 2024 04:05
Copy link
Member

@Rjected Rjected left a 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

Comment on lines 481 to 483
return Err(alloy_rlp::Error::Custom(
"Buffer did not consume exactly payload_length bytes",
));
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@Rjected Rjected left a 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!

@Rjected Rjected added this pull request to the merge queue Mar 25, 2024
Merged via the queue into paradigmxyz:main with commit 074af7b Mar 25, 2024
27 checks passed
@AbnerZheng AbnerZheng deleted the issue-7278 branch March 25, 2024 17:39
Ruteri pushed a commit to Ruteri/reth that referenced this pull request Apr 17, 2024
Ruteri pushed a commit to Ruteri/reth that referenced this pull request Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check RequestPair payload length during decoding
3 participants