Skip to content

Commit

Permalink
mime: fix zstd detect
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Dec 23, 2024
1 parent 4d27a88 commit 147ba5c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/mime/internal/magic/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ func InstallShieldCab(raw []byte, _ uint32) bool {
}

// Zstd matches a Zstandard archive file.
// https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
func Zstd(raw []byte, limit uint32) bool {
return len(raw) >= 4 &&
(0x22 <= raw[0] && raw[0] <= 0x28 || raw[0] == 0x1E) && // Different Zstandard versions.
bytes.HasPrefix(raw[1:], []byte{0xB5, 0x2F, 0xFD})
if len(raw) < 4 {
return false
}
sig := binary.LittleEndian.Uint32(raw)
// Check for Zstandard frames and skippable frames.
return (sig >= 0xFD2FB522 && sig <= 0xFD2FB528) ||
(sig >= 0x184D2A50 && sig <= 0x184D2A5F)
}

// CRX matches a Chrome extension file: a zip archive prepended by a package header.
Expand Down

0 comments on commit 147ba5c

Please sign in to comment.