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

rlp: handling extra data #773

Open
divagant-martian opened this issue Aug 3, 2023 · 1 comment
Open

rlp: handling extra data #773

divagant-martian opened this issue Aug 3, 2023 · 1 comment

Comments

@divagant-martian
Copy link

divagant-martian commented Aug 3, 2023

Unsure if this a bug or an api shortcoming.

When decoding bytes that have extra data, I would expect one of:

  1. an error on decoding
  2. a way to know the number of bytes that were readed, to externally deal with trailing data

example:

let input = vec![123, 32, 4, 156, 231, 200];
let mut stream = rlp::RlpStream::new();
input.rlp_append(&mut stream);
let bytes = stream.out().freeze();

let mut extra_data = bytes.to_vec();
extra_data.push(23);
extra_data.push(40);

rlp::decode::<Vec<u8>>(&extra_data).expect_err("extra data should not be ignored");
@divagant-martian divagant-martian changed the title rlp: trailling data is not rejected when decoding a list rlp: handling extra data Aug 3, 2023
@divagant-martian
Copy link
Author

rlp seems to accept concatenations of valid rlp data as valid rlp data, I think this is a bug.
Take for example
[193, 75] this is a one element list with payload 75
[193, 75, 248] this as a whole is not valid rlp data. It's also not valid as concatenation of rlp data. This is not rejected
[193, 75, 75] as a whole is also not valid rlp data.
However:
[193, 75, 75] still produces item_count() = 2, and an iter that gives 75 and 75

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

No branches or pull requests

1 participant