chore: add comments about RAR 4.x and 5.0 signature

This commit is contained in:
ttyS3 2024-11-30 16:09:54 +00:00 committed by João Marcos
parent 8c32d2c31a
commit 22d4e0faf0

View File

@ -98,6 +98,9 @@ pub fn try_infer_extension(path: &Path) -> Option<Extension> {
buf.starts_with(&[0x28, 0xB5, 0x2F, 0xFD])
}
fn is_rar(buf: &[u8]) -> bool {
// ref https://www.rarlab.com/technote.htm#rarsign
// RAR 5.0 8 bytes length signature: 0x52 0x61 0x72 0x21 0x1A 0x07 0x01 0x00
// RAR 4.x 7 bytes length signature: 0x52 0x61 0x72 0x21 0x1A 0x07 0x00
buf.len() >= 7
&& buf.starts_with(&[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07])
&& (buf[6] == 0x00 || (buf.len() >= 8 && buf[6..=7] == [0x01, 0x00]))