Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add InstallShield Cabinet archive file (.cab) support #274

Merged
merged 2 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/magic/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
}, 8)
// Warc matches a Web ARChive file.
Warc = prefix([]byte("WARC/1.0"), []byte("WARC/1.1"))
// Cab matches a Cabinet archive file.
// Cab matches a Microsoft Cabinet archive file.
Cab = prefix([]byte("MSCF\x00\x00\x00\x00"))
// Xz matches an xz compressed stream based on https://tukaani.org/xz/xz-file-format.txt.
Xz = prefix([]byte{0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00})
Expand All @@ -43,6 +43,14 @@ var (
RAR = prefix([]byte("Rar!\x1A\x07\x00"), []byte("Rar!\x1A\x07\x01\x00"))
)

// InstallShieldCab matches an InstallShield Cabinet archive file.
func InstallShieldCab(raw []byte, _ uint32) bool {
return len(raw) > 7 &&
bytes.Equal(raw[0:4], []byte("ISc(")) &&
raw[6] == 0 &&
(raw[7] == 1 || raw[7] == 2 || raw[7] == 4)
}

// Zstd matches a Zstandard archive file.
func Zstd(raw []byte, limit uint32) bool {
return len(raw) >= 4 &&
Expand Down
158 changes: 78 additions & 80 deletions mimetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,86 +18,84 @@ const testDataDir = "testdata"

// test files sorted by the file name in alphabetical order.
var files = map[string]string{
"3g2.3g2": "video/3gpp2",
"3gp.3gp": "video/3gpp",
"3mf.3mf": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
"7z.7z": "application/x-7z-compressed",
"a.a": "application/x-archive",
"aac.aac": "audio/aac",
"aaf.aaf": "application/octet-stream",
"accdb.accdb": "application/x-msaccess",
"aiff.aiff": "audio/aiff",
"amf.amf": "application/x-amf",
"amr.amr": "audio/amr",
"ape.ape": "audio/ape",
"apng.png": "image/vnd.mozilla.apng",
"asf.asf": "video/x-ms-asf",
"atom.atom": "application/atom+xml",
"au.au": "audio/basic",
"avi.avi": "video/x-msvideo",
"avif.avif": "image/avif",
"avifsequence.avif": "image/avif",
"bmp.bmp": "image/bmp",
"bpg.bpg": "image/bpg",
"bz2.bz2": "application/x-bzip2",
"cab.cab": "application/vnd.ms-cab-compressed",
"class.class": "application/x-java-applet",
"crx.crx": "application/x-chrome-extension",
"csv.csv": "text/csv",
"cpio.cpio": "application/x-cpio",
"dae.dae": "model/vnd.collada+xml",
"dbf.dbf": "application/x-dbf",
"dcm.dcm": "application/dicom",
"deb.deb": "application/vnd.debian.binary-package",
"djvu.djvu": "image/vnd.djvu",
"doc.doc": "application/msword",
"docx.1.docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"docx.docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"drpm.rpm": "application/x-rpm",
"dwg.1.dwg": "image/vnd.dwg",
"dwg.dwg": "image/vnd.dwg",
"eot.eot": "application/vnd.ms-fontobject",
"epub.epub": "application/epub+zip",
"exe.exe": "application/vnd.microsoft.portable-executable",
"fdf.fdf": "application/vnd.fdf",
"fits.fits": "application/fits",
"flac.flac": "audio/flac",
"flv.flv": "video/x-flv",
"gbr.gbr": "image/x-gimp-gbr",
"geojson.1.geojson": "application/geo+json",
"geojson.geojson": "application/geo+json",
"gif.gif": "image/gif",
"glb.glb": "model/gltf-binary",
"gml.gml": "application/gml+xml",
"gpx.gpx": "application/gpx+xml",
"gz.gz": "application/gzip",
"har.har": "application/json",
"hdr.hdr": "image/vnd.radiance",
"heic.single.heic": "image/heic",
"heif.heif": "image/heif",
"html.html": "text/html; charset=utf-8",
"html.iso88591.html": "text/html; charset=iso-8859-1",
"html.svg.html": "text/html; charset=utf-8",
"html.usascii.html": "text/html; charset=us-ascii",
"html.utf8.html": "text/html; charset=utf-8",
"html.utf8bom.html": "text/html; charset=utf-8",
"html.utf8bomws.html": "text/html; charset=utf-8",
"html.utf8bomdetect.html": "text/html; charset=utf-8",
"html.withbr.html": "text/html; charset=utf-8",
"ico.ico": "image/x-icon",
"ics.dos.ics": "text/calendar",
"ics.ics": "text/calendar",
"iso88591.txt": "text/plain; charset=iso-8859-1",
"jar.jar": "application/jar",
"jp2.jp2": "image/jp2",
"jpf.jpf": "image/jpx",
"jpg.jpg": "image/jpeg",
"jpm.jpm": "image/jpm",
"jxl.jxl": "image/jxl",
"xpm.xpm": "image/x-xpixmap",
"js.js": "application/javascript",
"json.json": "application/json",
"json.lowascii.json": "application/json",
"3g2.3g2": "video/3gpp2",
"3gp.3gp": "video/3gpp",
"3mf.3mf": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
"7z.7z": "application/x-7z-compressed",
"a.a": "application/x-archive",
"aac.aac": "audio/aac",
"aaf.aaf": "application/octet-stream",
"accdb.accdb": "application/x-msaccess",
"aiff.aiff": "audio/aiff",
"amf.amf": "application/x-amf",
"amr.amr": "audio/amr",
"ape.ape": "audio/ape",
"apng.png": "image/vnd.mozilla.apng",
"asf.asf": "video/x-ms-asf",
"atom.atom": "application/atom+xml",
"au.au": "audio/basic",
"avi.avi": "video/x-msvideo",
"avif.avif": "image/avif",
"avifsequence.avif": "image/avif",
"bmp.bmp": "image/bmp",
"bpg.bpg": "image/bpg",
"bz2.bz2": "application/x-bzip2",
"cab.cab": "application/vnd.ms-cab-compressed",
"cab.is.cab": "application/x-installshield",
"class.class": "application/x-java-applet",
"crx.crx": "application/x-chrome-extension",
"csv.csv": "text/csv",
"cpio.cpio": "application/x-cpio",
"dae.dae": "model/vnd.collada+xml",
"dbf.dbf": "application/x-dbf",
"dcm.dcm": "application/dicom",
"deb.deb": "application/vnd.debian.binary-package",
"djvu.djvu": "image/vnd.djvu",
"doc.doc": "application/msword",
"docx.1.docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"docx.docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"drpm.rpm": "application/x-rpm",
"dwg.1.dwg": "image/vnd.dwg",
"dwg.dwg": "image/vnd.dwg",
"eot.eot": "application/vnd.ms-fontobject",
"epub.epub": "application/epub+zip",
"exe.exe": "application/vnd.microsoft.portable-executable",
"fdf.fdf": "application/vnd.fdf",
"fits.fits": "application/fits",
"flac.flac": "audio/flac",
"flv.flv": "video/x-flv",
"gbr.gbr": "image/x-gimp-gbr",
"geojson.1.geojson": "application/geo+json",
"geojson.geojson": "application/geo+json",
"gif.gif": "image/gif",
"glb.glb": "model/gltf-binary",
"gml.gml": "application/gml+xml",
"gpx.gpx": "application/gpx+xml",
"gz.gz": "application/gzip",
"har.har": "application/json",
"hdr.hdr": "image/vnd.radiance",
"heic.single.heic": "image/heic",
"heif.heif": "image/heif",
"html.html": "text/html; charset=utf-8",
"html.iso88591.html": "text/html; charset=iso-8859-1",
"html.svg.html": "text/html; charset=utf-8",
"html.usascii.html": "text/html; charset=us-ascii",
"html.utf8.html": "text/html; charset=utf-8",
"html.withbr.html": "text/html; charset=utf-8",
"ico.ico": "image/x-icon",
"ics.dos.ics": "text/calendar",
"ics.ics": "text/calendar",
"iso88591.txt": "text/plain; charset=iso-8859-1",
"jar.jar": "application/jar",
"jp2.jp2": "image/jp2",
"jpf.jpf": "image/jpx",
"jpg.jpg": "image/jpeg",
"jpm.jpm": "image/jpm",
"jxl.jxl": "image/jxl",
"xpm.xpm": "image/x-xpixmap",
"js.js": "application/javascript",
"json.json": "application/json",
"json.lowascii.json": "application/json",
// json.{int,float,string}.txt contain a single JSON value. They are valid JSON
// documents, but they should not be detected as application/json. This mimics
// the behaviour of the file utility and seems the correct thing to do.
Expand Down
3 changes: 2 additions & 1 deletion supported_mimes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 170 Supported MIME types
## 171 Supported MIME types
This file is automatically generated when running tests. Do not edit manually.

Extension | MIME type | Aliases
Expand Down Expand Up @@ -138,6 +138,7 @@ Extension | MIME type | Aliases
**.gbr** | image/x-gimp-gbr | -
**.glb** | model/gltf-binary | -
**.avif** | image/avif | -
**.cab** | application/x-installshield | -
**.txt** | text/plain | -
**.html** | text/html | -
**.svg** | image/svg+xml | -
Expand Down
Binary file added testdata/cab.is.cab
Binary file not shown.
3 changes: 2 additions & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var root = newMIME("application/octet-stream", "",
gzip, class, swf, crx, ttf, woff, woff2, otf, ttc, eot, wasm, shx, dbf, dcm, rar,
djvu, mobi, lit, bpg, sqlite3, dwg, nes, lnk, macho, qcp, icns, heic,
heicSeq, heif, heifSeq, hdr, mrc, mdb, accdb, zstd, cab, rpm, xz, lzip,
torrent, cpio, tzif, xcf, pat, gbr, glb, avif,
torrent, cpio, tzif, xcf, pat, gbr, glb, avif, cabIS,
// Keep text last because it is the slowest check
text,
)
Expand Down Expand Up @@ -243,6 +243,7 @@ var (
accdb = newMIME("application/x-msaccess", ".accdb", magic.MsAccessAce)
zstd = newMIME("application/zstd", ".zst", magic.Zstd)
cab = newMIME("application/vnd.ms-cab-compressed", ".cab", magic.Cab)
cabIS = newMIME("application/x-installshield", ".cab", magic.InstallShieldCab)
lzip = newMIME("application/lzip", ".lz", magic.Lzip).alias("application/x-lzip")
torrent = newMIME("application/x-bittorrent", ".torrent", magic.Torrent)
cpio = newMIME("application/x-cpio", ".cpio", magic.Cpio)
Expand Down