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

fix: infinite loop while decoding a list of transactions #432

Merged
merged 1 commit into from
Mar 31, 2024

Conversation

Brechtpd
Copy link
Contributor

@Brechtpd Brechtpd commented Mar 31, 2024

In network_decode the decoded bytes are not correctly consumed in the buffer which makes decoding break for anything that requires more decoding afterwards, and also makes it possible for the decoding to hang.

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

right, we never advanced the input buffer.

this now ensures that the input buffer is consumed

@prestwich
Copy link
Member

    #[inline]
    fn advance(&mut self, cnt: usize) {
        if self.len() < cnt {
            panic_advance(cnt, self.len());
        }

        *self = &self[cnt..];
    }

https://docs.rs/bytes/latest/src/bytes/buf/buf_impl.rs.html#1412-1418

Above is the advance code from impl Buf for &[u8]. Can you explain how calling buf.advance(1) differs in behavior from let buf = &mut &buf[1..];

@prestwich
Copy link
Member

oohhhh I think i see. It's a "list of transactions" i.e. the inner decoding doesn't consume from the buffer passed to it by the outer list decoder 👍

@prestwich prestwich merged commit 64bcd80 into alloy-rs:main Mar 31, 2024
18 checks passed
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.

3 participants