Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gabriel-vasile/mimetype
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.4.6
Choose a base ref
...
head repository: gabriel-vasile/mimetype
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.4.7
Choose a head ref
  • 8 commits
  • 216 files changed
  • 2 contributors

Commits on Oct 24, 2024

  1. remove torrent testdata; closes #398 (#597)

    continuing removing excessive testfixures #575 (comment)
    gabriel-vasile authored Oct 24, 2024
    Copy the full SHA
    ff62397 View commit details
  2. add support for CBOR files (#598)

    * add support for CBOR files
    
    * format: gofmt has new formatting rules
    gabriel-vasile authored Oct 24, 2024
    Copy the full SHA
    f4b2ca5 View commit details

Commits on Nov 4, 2024

  1. Remove macho fixtures (#602)

    * formatting: reduce ident size by 1
    
    * testdata cleanup: remove macho fixtures
    
    #575 (comment)
    
    * macho: use signature from stdlib instead of magic signature
    
    * macho: add unit tests
    
    These tests are a replacement for the fixtures from the testdata
    directory.
    gabriel-vasile authored Nov 4, 2024
    Copy the full SHA
    2f8f7d8 View commit details

Commits on Nov 11, 2024

  1. remote most of the files from testdata (#603)

    gabriel-vasile authored Nov 11, 2024
    Copy the full SHA
    4ade0f9 View commit details
  2. Bump the github-actions group across 1 directory with 3 updates (#599)

    Bumps the github-actions group with 3 updates in the / directory: [actions/checkout](https://github.com/actions/checkout), [actions/setup-go](https://github.com/actions/setup-go) and [github/codeql-action](https://github.com/github/codeql-action).
    
    
    Updates `actions/checkout` from 4.2.1 to 4.2.2
    - [Release notes](https://github.com/actions/checkout/releases)
    - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
    - [Commits](actions/checkout@v4.2.1...v4.2.2)
    
    Updates `actions/setup-go` from 5.0.2 to 5.1.0
    - [Release notes](https://github.com/actions/setup-go/releases)
    - [Commits](actions/setup-go@v5.0.2...v5.1.0)
    
    Updates `github/codeql-action` from 3.26.12 to 3.27.0
    - [Release notes](https://github.com/github/codeql-action/releases)
    - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
    - [Commits](github/codeql-action@v3.26.12...v3.27.0)
    
    ---
    updated-dependencies:
    - dependency-name: actions/checkout
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: github-actions
    - dependency-name: actions/setup-go
      dependency-type: direct:production
      update-type: version-update:semver-minor
      dependency-group: github-actions
    - dependency-name: github/codeql-action
      dependency-type: direct:production
      update-type: version-update:semver-minor
      dependency-group: github-actions
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 11, 2024
    Copy the full SHA
    50af98b View commit details
  3. Bump golang.org/x/net from 0.30.0 to 0.31.0 in the gomod group (#605)

    Bumps the gomod group with 1 update: [golang.org/x/net](https://github.com/golang/net).
    
    
    Updates `golang.org/x/net` from 0.30.0 to 0.31.0
    - [Commits](golang/net@v0.30.0...v0.31.0)
    
    ---
    updated-dependencies:
    - dependency-name: golang.org/x/net
      dependency-type: direct:production
      update-type: version-update:semver-minor
      dependency-group: gomod
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 11, 2024
    Copy the full SHA
    bd7617a View commit details
  4. rename application/javascript to text/javascript (#604)

    In accordance with latest IANA specification and with what go sdtlib is
    doing.
    https://www.iana.org/assignments/media-types/text/javascript
    gabriel-vasile authored Nov 11, 2024
    Copy the full SHA
    4c93ad3 View commit details
  5. Bump github/codeql-action in the github-actions group (#606)

    Bumps the github-actions group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).
    
    
    Updates `github/codeql-action` from 3.27.0 to 3.27.1
    - [Release notes](https://github.com/github/codeql-action/releases)
    - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
    - [Commits](github/codeql-action@v3.27.0...v3.27.1)
    
    ---
    updated-dependencies:
    - dependency-name: github/codeql-action
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: github-actions
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Nov 11, 2024
    Copy the full SHA
    575b761 View commit details
Showing with 410 additions and 8,051 deletions.
  1. +3 −3 .github/workflows/benchmark.yml
  2. +3 −3 .github/workflows/codeql.yml
  3. +4 −4 .github/workflows/go.yml
  4. +1 −1 go.mod
  5. +2 −2 go.sum
  6. +18 −15 internal/magic/binary.go
  7. +89 −65 internal/magic/magic_test.go
  8. +281 −290 mimetype_test.go
  9. +4 −3 supported_mimes.md
  10. BIN testdata/3g2.3g2
  11. BIN testdata/3gp.3gp
  12. +0 −39 testdata/3mf.3mf
  13. BIN testdata/7z.7z
  14. BIN testdata/a.a
  15. BIN testdata/aac.aac
  16. BIN testdata/aaf.aaf
  17. BIN testdata/accdb.accdb
  18. BIN testdata/aiff.aiff
  19. +0 −109 testdata/amf.amf
  20. BIN testdata/amr.amr
  21. BIN testdata/ape.ape
  22. BIN testdata/apng.png
  23. BIN testdata/asf.asf
  24. +0 −17 testdata/atom.atom
  25. BIN testdata/au.au
  26. BIN testdata/audio.mp4
  27. BIN testdata/avi.avi
  28. BIN testdata/avif.avif
  29. BIN testdata/avifsequence.avif
  30. BIN testdata/bad.dbf
  31. BIN testdata/bmp.bmp
  32. BIN testdata/bpg.bpg
  33. BIN testdata/bz2.bz2
  34. BIN testdata/cab.cab
  35. BIN testdata/cab.is.cab
  36. BIN testdata/class.class
  37. BIN testdata/cpio.cpio
  38. BIN testdata/crx.crx
  39. +0 −6 testdata/csv.csv
  40. +0 −198 testdata/dae.dae
  41. BIN testdata/dbf.dbf
  42. BIN testdata/dcm.dcm
  43. BIN testdata/deb.deb
  44. BIN testdata/djvu.djvu
  45. BIN testdata/doc.doc
  46. BIN testdata/drpm.rpm
  47. BIN testdata/dwg.1.dwg
  48. BIN testdata/dwg.dwg
  49. BIN testdata/elfobject
  50. BIN testdata/eot.eot
  51. BIN testdata/epub.epub
  52. +0 −17 testdata/fdf.fdf
  53. BIN testdata/fits.1.fits
  54. BIN testdata/fits.fits
  55. BIN testdata/flac.flac
  56. BIN testdata/flv.flv
  57. +0 −2 testdata/foobar.fb
  58. BIN testdata/gbr.gbr
  59. +0 −1 testdata/geojson.1.geojson
  60. +0 −10 testdata/geojson.geojson
  61. BIN testdata/gif.gif
  62. BIN testdata/glb.glb
  63. +0 −16 testdata/gml.gml
  64. +0 −27 testdata/gpx.gpx
  65. BIN testdata/gz.gz
  66. +0 −163 testdata/har.har
  67. BIN testdata/hdr.hdr
  68. BIN testdata/heic.single.heic
  69. BIN testdata/heif.heif
  70. +0 −12 testdata/html.html
  71. +0 −59 testdata/html.iso88591.html
  72. +0 −20 testdata/html.svg.html
  73. +0 −20 testdata/html.usascii.html
  74. +0 −13 testdata/html.utf8.html
  75. +0 −23 testdata/html.utf8bom.html
  76. +0 −24 testdata/html.utf8bomdetect.html
  77. +0 −24 testdata/html.utf8bomws.html
  78. +0 −14 testdata/html.withbr.html
  79. BIN testdata/icns.icns
  80. BIN testdata/ico.ico
  81. +0 −13 testdata/ics.dos.ics
  82. +0 −13 testdata/ics.ics
  83. +0 −2 testdata/iso88591.txt
  84. BIN testdata/jp2.jp2
  85. BIN testdata/jpf.jpf
  86. BIN testdata/jpg.jpg
  87. BIN testdata/jpm.jpm
  88. +0 −3 testdata/js.js
  89. +0 −1 testdata/json.float.txt
  90. +0 −1 testdata/json.int.txt
  91. +0 −29 testdata/json.json
  92. +0 −2 testdata/json.lowascii.json
  93. +0 −1 testdata/json.string.txt
  94. BIN testdata/jxl.jxl
  95. BIN testdata/jxr.jxr
  96. +0 −915 testdata/kml.kml
  97. BIN testdata/lit.lit
  98. BIN testdata/lnk.lnk
  99. +0 −8 testdata/lua.lua
  100. BIN testdata/lz.lz
  101. +0 −7 testdata/m3u.m3u
  102. BIN testdata/m4a.m4a
  103. BIN testdata/macho.macho
  104. BIN testdata/mdb.mdb
  105. BIN testdata/midi.midi
  106. BIN testdata/mkv.mkv
  107. BIN testdata/mobi.mobi
  108. BIN testdata/mov.mov
  109. BIN testdata/mp3.mp3
  110. BIN testdata/mp3.v1.notag.mp3
  111. BIN testdata/mp3.v2.5.notag.mp3
  112. BIN testdata/mp3.v2.notag.mp3
  113. BIN testdata/mp4.1.mp4
  114. BIN testdata/mp4.mp4
  115. BIN testdata/mpc.mpc
  116. BIN testdata/mpeg.mpeg
  117. BIN testdata/mqv.mqv
  118. +0 −1 testdata/mrc.mrc
  119. BIN testdata/msg.msg
  120. BIN testdata/msi.msi
  121. +0 −4 testdata/ndjson.ndjson
  122. +0 −231 testdata/ndjson.xl.ndjson
  123. BIN testdata/nes.nes
  124. BIN testdata/odc.odc
  125. BIN testdata/odf.odf
  126. BIN testdata/odg.odg
  127. BIN testdata/odp.odp
  128. BIN testdata/ods.ods
  129. BIN testdata/odt.odt
  130. BIN testdata/ogg.oga
  131. BIN testdata/ogg.ogv
  132. BIN testdata/ogg.spx.oga
  133. BIN testdata/otf.otf
  134. BIN testdata/otg.otg
  135. BIN testdata/otp.otp
  136. BIN testdata/ots.ots
  137. BIN testdata/ott.ott
  138. +0 −31 testdata/owl2.owl
  139. BIN testdata/p7s_der.p7s
  140. +0 −9 testdata/p7s_pem.p7s
  141. BIN testdata/parquet.parquet
  142. BIN testdata/pat.pat
  143. BIN testdata/pdf.pdf
  144. +0 −2 testdata/php.php
  145. +0 −2 testdata/pl.pl
  146. BIN testdata/png.png
  147. BIN testdata/ppt.ppt
  148. BIN testdata/pptx.pptx
  149. BIN testdata/ps.ps
  150. BIN testdata/psd.psd
  151. BIN testdata/pub.pub
  152. +0 −2 testdata/py.py
  153. BIN testdata/qcp.qcp
  154. BIN testdata/rar.rar
  155. BIN testdata/rmvb.rmvb
  156. BIN testdata/rpm.rpm
  157. +0 −18 testdata/rss.rss
  158. +0 −468 testdata/rtf.rtf
  159. BIN testdata/sample32.macho
  160. BIN testdata/sample64.macho
  161. BIN testdata/shp.shp
  162. BIN testdata/shx.shx
  163. BIN testdata/so.so
  164. BIN testdata/sqlite.sqlite
  165. +0 −20 testdata/srt.srt
  166. +0 −7 testdata/svg.1.svg
  167. +0 −47 testdata/svg.svg
  168. BIN testdata/swf.swf
  169. BIN testdata/sxc.sxc
  170. BIN testdata/tar.gnu.tar
  171. BIN testdata/tar.oldgnu.tar
  172. BIN testdata/tar.posix.tar
  173. BIN testdata/tar.star.tar
  174. BIN testdata/tar.tar
  175. BIN testdata/tar.ustar.tar
  176. BIN testdata/tar.v7-gnu.tar
  177. BIN testdata/tar.v7.tar
  178. +0 −2 testdata/tcl.tcl
  179. +0 −4,082 testdata/tcx.tcx
  180. BIN testdata/tiff.tiff
  181. BIN testdata/torrent.torrent
  182. +0 −39 testdata/tsv.tsv
  183. BIN testdata/ttc.ttc
  184. BIN testdata/ttf.ttf
  185. BIN testdata/utf16bebom.txt
  186. BIN testdata/utf16lebom.txt
  187. BIN testdata/utf32bebom.txt
  188. BIN testdata/utf32lebom.txt
  189. +0 −3 testdata/utf8ctrlchars
  190. +0 −15 testdata/vcf.dos.vcf
  191. +0 −15 testdata/vcf.vcf
  192. BIN testdata/voc.voc
  193. +0 −1 testdata/vtt.eof.vtt
  194. +0 −1 testdata/vtt.space.vtt
  195. +0 −1 testdata/vtt.tab.vtt
  196. +0 −45 testdata/vtt.vtt
  197. +0 −18 testdata/warc.warc
  198. BIN testdata/wasm.wasm
  199. BIN testdata/wav.wav
  200. BIN testdata/webm.webm
  201. BIN testdata/webp.webp
  202. BIN testdata/woff.woff
  203. BIN testdata/woff2.woff2
  204. +0 −15 testdata/x3d.x3d
  205. BIN testdata/xar.xar
  206. BIN testdata/xcf.xcf
  207. +0 −11 testdata/xfdf.xfdf
  208. +0 −35 testdata/xlf.xlf
  209. BIN testdata/xls.xls
  210. +0 −8 testdata/xml.withbr.xml
  211. +0 −7 testdata/xml.xml
  212. +0 −712 testdata/xpm.xpm
  213. BIN testdata/xz.xz
  214. BIN testdata/zip.zip
  215. BIN testdata/zst.zst
  216. +5 −4 tree.go
6 changes: 3 additions & 3 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -12,11 +12,11 @@ jobs:
steps:
# Base for comparison is master branch.
- name: Checkout code
uses: actions/checkout@v4.2.1
uses: actions/checkout@v4.2.2
with:
ref: master
- name: Install Go
uses: actions/setup-go@v5.0.2
uses: actions/setup-go@v5.1.0
with:
go-version-file: 'go.mod'

@@ -25,7 +25,7 @@ jobs:
# runner is in a shared environment and CPU and mem would be affected by others. (or so I think)
- run: go test -run=none -bench=. -count=30 -benchtime=100ms -timeout=20m > /tmp/prev
- name: Checkout code
uses: actions/checkout@v4.2.1
uses: actions/checkout@v4.2.2
- run: go test -run=none -bench=. -count=30 -benchtime=100ms -timeout=20m > /tmp/curr

- run: go install golang.org/x/perf/cmd/benchstat@latest
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -20,13 +20,13 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v4.2.1
uses: actions/checkout@v4.2.2

- name: Initialize CodeQL
uses: github/codeql-action/init@v3.26.12
uses: github/codeql-action/init@v3.27.1
with:
languages: go
queries: security-and-quality

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3.26.12
uses: github/codeql-action/analyze@v3.27.1
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4.2.1
uses: actions/checkout@v4.2.2
- name: Install Go
uses: actions/setup-go@v5.0.2
uses: actions/setup-go@v5.1.0
with:
go-version-file: 'go.mod'
- name: Run linters
@@ -27,10 +27,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4.2.1
uses: actions/checkout@v4.2.2
- name: Install Go
if: success()
uses: actions/setup-go@v5.0.2
uses: actions/setup-go@v5.1.0
with:
go-version-file: 'go.mod'
- run: go test -race ./...
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ module github.com/gabriel-vasile/mimetype

go 1.20

require golang.org/x/net v0.30.0
require golang.org/x/net v0.31.0

// v1.4.4 had a test file detected as malicious by antivirus software. #575
retract v1.4.4
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
33 changes: 18 additions & 15 deletions internal/magic/binary.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ var (
Torrent = prefix([]byte("d8:announce"))
// PAR1 matches a parquet file.
Par1 = prefix([]byte{0x50, 0x41, 0x52, 0x31})
// CBOR matches a Concise Binary Object Representation https://cbor.io/
CBOR = prefix([]byte{0xD9, 0xD9, 0xF7})
)

// Java bytecode and Mach-O binaries share the same magic number.
@@ -34,7 +36,7 @@ func classOrMachOFat(in []byte) bool {
return false
}

return bytes.HasPrefix(in, []byte{0xCA, 0xFE, 0xBA, 0xBE})
return binary.BigEndian.Uint32(in) == macho.MagicFat
}

// Class matches a java class file.
@@ -44,7 +46,7 @@ func Class(raw []byte, limit uint32) bool {

// MachO matches Mach-O binaries format.
func MachO(raw []byte, limit uint32) bool {
if classOrMachOFat(raw) && raw[7] < 20 {
if classOrMachOFat(raw) && raw[7] < 0x14 {
return true
}

@@ -156,11 +158,11 @@ func Marc(raw []byte, limit uint32) bool {
// the GL transmission Format (glTF).
// GLB uses little endian and its header structure is as follows:
//
// <-- 12-byte header -->
// | magic | version | length |
// | (uint32) | (uint32) | (uint32) |
// | \x67\x6C\x54\x46 | \x01\x00\x00\x00 | ... |
// | g l T F | 1 | ... |
// <-- 12-byte header -->
// | magic | version | length |
// | (uint32) | (uint32) | (uint32) |
// | \x67\x6C\x54\x46 | \x01\x00\x00\x00 | ... |
// | g l T F | 1 | ... |
//
// Visit [glTF specification] and [IANA glTF entry] for more details.
//
@@ -172,14 +174,15 @@ var Glb = prefix([]byte("\x67\x6C\x54\x46\x02\x00\x00\x00"),
// TzIf matches a Time Zone Information Format (TZif) file.
// See more: https://tools.ietf.org/id/draft-murchison-tzdist-tzif-00.html#rfc.section.3
// Its header structure is shown below:
// +---------------+---+
// | magic (4) | <-+-- version (1)
// +---------------+---+---------------------------------------+
// | [unused - reserved for future use] (15) |
// +---------------+---------------+---------------+-----------+
// | isutccnt (4) | isstdcnt (4) | leapcnt (4) |
// +---------------+---------------+---------------+
// | timecnt (4) | typecnt (4) | charcnt (4) |
//
// +---------------+---+
// | magic (4) | <-+-- version (1)
// +---------------+---+---------------------------------------+
// | [unused - reserved for future use] (15) |
// +---------------+---------------+---------------+-----------+
// | isutccnt (4) | isstdcnt (4) | leapcnt (4) |
// +---------------+---------------+---------------+
// | timecnt (4) | typecnt (4) | charcnt (4) |
func TzIf(raw []byte, limit uint32) bool {
// File is at least 44 bytes (header size).
if len(raw) < 44 {
154 changes: 89 additions & 65 deletions internal/magic/magic_test.go
Original file line number Diff line number Diff line change
@@ -13,76 +13,100 @@ func TestMagic(t *testing.T) {
raw string
limit uint32
res bool
}{
{
name: "incomplete JSON, limit 0",
detector: JSON,
raw: `["an incomplete JSON array`,
limit: 0,
res: false,
},
{
name: "incomplete JSON, limit 10",
detector: JSON,
raw: `["an incomplete JSON array`,
limit: 10,
res: true,
},
{
name: "basic JSON data type null",
detector: JSON,
raw: `null`,
limit: 10,
res: false,
},
{
name: "basic JSON data type string",
detector: JSON,
raw: `"abc"`,
limit: 10,
res: false,
},
{
name: "basic JSON data type integer",
detector: JSON,
raw: `120`,
limit: 10,
res: false,
},
{
name: "basic JSON data type float",
detector: JSON,
raw: `.120`,
limit: 10,
res: false,
},
{
name: "NdJSON with basic data types",
detector: NdJSON,
raw: "1\nnull\n\"foo\"\n0.1",
limit: 10,
res: false,
},
{
name: "NdJSON with basic data types and empty object",
detector: NdJSON,
raw: "1\n2\n3\n{}",
limit: 10,
res: true,
},
{
name: "NdJSON with empty objects types",
detector: NdJSON,
raw: "{}\n{}\n{}",
limit: 10,
res: true,
},
}
}{{
name: "incomplete JSON, limit 0",
detector: JSON,
raw: `["an incomplete JSON array`,
limit: 0,
res: false,
}, {
name: "incomplete JSON, limit 10",
detector: JSON,
raw: `["an incomplete JSON array`,
limit: 10,
res: true,
}, {
name: "basic JSON data type null",
detector: JSON,
raw: `null`,
limit: 10,
res: false,
}, {
name: "basic JSON data type string",
detector: JSON,
raw: `"abc"`,
limit: 10,
res: false,
}, {
name: "basic JSON data type integer",
detector: JSON,
raw: `120`,
limit: 10,
res: false,
}, {
name: "basic JSON data type float",
detector: JSON,
raw: `.120`,
limit: 10,
res: false,
}, {
name: "NdJSON with basic data types",
detector: NdJSON,
raw: "1\nnull\n\"foo\"\n0.1",
limit: 10,
res: false,
}, {
name: "NdJSON with basic data types and empty object",
detector: NdJSON,
raw: "1\n2\n3\n{}",
limit: 10,
res: true,
}, {
name: "NdJSON with empty objects types",
detector: NdJSON,
raw: "{}\n{}\n{}",
limit: 10,
res: true,
}, {
name: "MachO class or Fat but last byte > \\x14",
detector: MachO,
raw: "\xCA\xFE\xBA\xBE \x15",
res: false,
}, {
name: "MachO class or Fat and last byte < \\x14",
detector: MachO,
raw: "\xCA\xFE\xBA\xBE \x13",
res: true,
}, {
name: "MachO BE Magic32",
detector: MachO,
raw: "\xFE\xED\xFA\xCE",
res: true,
}, {
name: "MachO LE Magic32",
detector: MachO,
raw: "\xCE\xFA\xED\xFE",
res: true,
}, {
name: "MachO BE Magic64",
detector: MachO,
raw: "\xFE\xED\xFA\xCF",
res: true,
}, {
name: "MachO LE Magic64",
detector: MachO,
raw: "\xCF\xFA\xED\xFE",
res: true,
}}
for _, tt := range tCases {
t.Run(tt.name, func(t *testing.T) {
if got := tt.detector([]byte(tt.raw), tt.limit); got != tt.res {
t.Errorf("expected: %t; got: %t", tt.res, got)
}
// Empty inputs should not pass as anything.
if got := tt.detector(nil, 0); got != false {
t.Errorf("empty input: expected: %t; got: %t", false, got)
}
})
}
}
Loading