paritytech / parity-scale-codec

Lightweight, efficient, binary serialization and deserialization codec
Apache License 2.0
243 stars 95 forks source link

Fix PrefixInput read #582

Closed kalaninja closed 4 months ago

kalaninja commented 4 months ago

The current implementation of PrefixInput seems to be inconsistent. It checks for the buffer being empty, but only after the prefix is taken, so trying to read with an zero-length buffer discards the prefix and it cannot be read any longer.

Though the behavior can be fixed for the empty buffer case, I think it is better just to remove the check completely and add a "note" comment, since this is an internal mechanism used to parse compacts only and the buffer is always allocated properly.