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

RLP library doesn't reject some invalid decoding attempts

Open cburgdorf opened this issue 3 years ago • 3 comments

I noticed the rlp library does currently not detect the following cases as errors when decoding

    b'\x00\xab',
    b'\x00\x00\xff',
    b'\x83dogcat',
    b'\xc7\xc0\xc1\xc0\xc3\xc0\xc1\xc0\xff',
    b'\xc7\xc0\xc1\xc0\xc3\xc0\xc1'
    b'\x81\x02',
    b'\x81\x54'

These are taken from pyrlp and while this library does reject some of the invalid cases it does not reject the ones that I listed above.

I was wondering if this is on purpose or if you'd accept patches to the rlp library to raise errors appropriately?

cburgdorf avatar Aug 12 '20 11:08 cburgdorf

Thanks for raising the issue!

I was wondering if this is on purpose or if you'd accept patches to the rlp library to raise errors appropriately?

I'd need to look at the spec, but if this is a bug, we'd definitely accept a patch! :)

ordian avatar Aug 12 '20 11:08 ordian

Although I should note, that we use some of the invalid RLPs for compression purposes (although it might be unrelated to the issue): https://github.com/openethereum/openethereum/blob/3ccfe735aa579f89a1f8de192a7625084a6f530f/util/rlp-compress/src/common.rs

ordian avatar Aug 12 '20 11:08 ordian

Thanks for the quick response and the pointer. It looks like some of these are related to the invalid RLPs used for compression purposes. But others aren't. E.g. this library decodes b'\xc0\x00' to [b'\x00'] where I would assume to either a) decode to just [] (ignoring the invalid extra byte) or return an error.

cburgdorf avatar Aug 13 '20 08:08 cburgdorf