BurntSushi / rust-snappy

Snappy compression implemented in Rust (including the Snappy frame format).
BSD 3-Clause "New" or "Revised" License
444 stars 43 forks source link

Unexpected Chunk Type Byte 224 #47

Closed kshammer closed 2 years ago

kshammer commented 2 years ago

Rust Edition: 2021 Snap Version 1 OS Win 10

When reading a valid snappy compressed byte getting the error

snappy: corrupt input (expected stream header but got unexpected chunk type byte 224)

The byte in question is 0xe0 which should not raise the error in https://github.com/BurntSushi/rust-snappy/blob/c391f5d0617851b7bf29b7e2834058f9bdd8b0e8/src/read.rs#L133

full bytes

b"\xe0\x04\xf0c\rg~_E\x10\x8d\xc6\x06\x18\x81\xa3\x03"\xd0\x04"\xcd\x04\x08\xba\x9e\xe4\xae\x16\x10\x16\x18\x02";\n\x1bnpc_dota_hero_dragon_knight\x12\x0eArchon Forever\x18\x00 \xb7\xf9\x8b\x96\x90\x80\x80\x88\x01(\x02"8\n\x1fnpc_do\x11=\x80abyssal_underlord\x12\x07VERSACE\x18\x00 \xb6\xea\xa5\xbe\x19:\x00\x126w\x00\x80lich\x12\x14Professor Impossible\x18\x00 \xcb\xa3\x86\xb2\x11:\x08>\n 6:\x00\x98ancient_apparition\x12\x0c#2parasite#2\x18\x00 \xc3\xec\x92\x8c\x11@\x08/\n\x136@\x00<slark\x12\nLogicalAp\x01q\x14\xd3\x90\xcb\xd8\x93\x80\t\xe5\x083\n\x1c:1\x00hpirit_breaker\x12\x05Lunch\x18\x00 \x93\xcf\xc0\xa0\tf\x10\x03"2\n\x1865\x00hjuggernaut\x12\x08Alnasty-\x18\x00 \xec\xb0\x93\xc3\x114\x008>4\x00\x80tidehunter\x12\x0eThelastmailman\x18\x00 \xd6\xc1\xf8\x8f\x11:\x006>\xa3\x00Xcrystal_maiden\x12\x08kshamme!\xc0\x0c\xbd\xc1\xef\xa7\x118\x00<>r\x00\xccwindrunner\x12\x12[M] StrawberryKiwi\x18\x00 \xc4\xf3\x84\xa1\x90\x80\x80\x88\x01(\x03(\x00X\xe6\xff\x9c\x85\x06"

code

    let mut buf:Vec<u8, Global> = vec![];
    let x = FrameDecoder::new(peek.message.reader()).read(&mut buf);
    println!("{}", x.unwrap());
    println!("{:#x?}", buf); 

struct Peek {
    tick: u32,
    message_type: u32,
    tell: u64,
    size: u32,
    message: Bytes,
    compression: bool,
}

I am able to decompress this set of bytes in python and I am struggling to figure out why it isn't working with this library. All help is appreciated and if you have any other questions please let me know.

kshammer commented 2 years ago

Nvm, I realized that my bytes did not follow the frame format and that I needed to use Raw.