parity-common icon indicating copy to clipboard operation
parity-common copied to clipboard

rlp: handling extra data

Open divagant-martian opened this issue 11 months ago • 1 comments

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 avatar Aug 03 '23 19:08 divagant-martian