Diagnose a SCALE decoder that breaks at length 64
A vector that decodes for every small test can break at exactly 64 elements. SCALE’s compact length prefix changes mode at this boundary.
Reproduce the boundary with the reference codec
In a Rust project with parity-scale-codec, run these encoding checks. The low two bits of the compact encoding select its mode. At 63 the length fits in one byte. At 64 it uses two bytes. The third assertion shows the ordinary fixed-width u32 representation of the same number.
use parity_scale_codec::{Compact, Encode};
fn main() {
assert_eq!(Compact(63u32).encode(), vec![0xfc]);
assert_eq!(Compact(64u32).encode(), vec![0x01, 0x01]);
assert_eq!(64u32.encode(), vec![0x40, 0, 0, 0]);
}
Use the declared element layout after the prefix
A Vec<u16> with 64 entries begins with 01 01, followed by 128 payload bytes. A parser that consumes only the first length byte will read each element at the wrong offset. A fixed array of 64 u16 values has a different schema and carries no vector length prefix.
Add fixtures on both sides of each mode transition that the application supports, and verify the number of bytes consumed. SCALE needs the expected type supplied by the decoder.