From f9744e6ea773a90f4a4c761398eff90b0cac2f17 Mon Sep 17 00:00:00 2001 From: ttyS3 Date: Sat, 30 Nov 2024 16:09:54 +0000 Subject: [PATCH] chore: add comments about RAR 4.x and 5.0 signature --- src/utils/fs.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/fs.rs b/src/utils/fs.rs index 1d5790f8..d33411ad 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -98,6 +98,9 @@ pub fn try_infer_extension(path: &Path) -> Option { 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]))