sharksforarms / deku

Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization
Apache License 2.0
1.13k stars 55 forks source link

Offset in from_bytes() causes panic in reader.rs if the bytes are greater than 128 #500

Open Josteniok opened 3 hours ago

Josteniok commented 3 hours ago

At some point after 0.16 my code started crashing when I was using an offset in from_bytes() where the input bits total more than 128 bytes. So if I have something like this, for example:

 match AccuracyDescriptionRecord::from_bytes((&data, 1032)) {
    Ok((_remaining_data, acc_desc_record)) => acc_desc_record.print(),
    Err(error) => panic!("Error getting Accuracy Description Record from data: {error}"),
}

The error looks like:

thread 'main' panicked at /Users/justin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deku-0.18.1/src/reader.rs:258:63: range end index 434 out of range for slice of length 128

This seems to be happening because from_bytes() is limiting the input offset to the MAX_BITS_AMT in the reader.

wcampbell0x2a commented 2 hours ago

Oh, I wonder if the addition of seek_bits would solve this, I'll take a look at the source sometime to fix this for from_bytes