|
1 | 1 | package magic
|
2 | 2 |
|
| 3 | +import "bytes" |
| 4 | + |
3 | 5 | var (
|
4 | 6 | // AVIF matches an AV1 Image File Format still or animated.
|
5 | 7 | // Wikipedia page seems outdated listing image/avif-sequence for animations.
|
|
37 | 39 | // Nero Digital AAC Audio
|
38 | 40 | []byte("NDAS"),
|
39 | 41 | )
|
40 |
| - // QuickTime matches a QuickTime File Format file. |
41 |
| - QuickTime = ftyp([]byte("qt "), []byte("moov")) |
42 | 42 | // Mqv matches a Sony / Mobile QuickTime file.
|
43 | 43 | Mqv = ftyp([]byte("mqt "))
|
44 | 44 | // M4a matches an audio M4A file.
|
|
55 | 55 | HeifSequence = ftyp([]byte("msf1"), []byte("hevm"), []byte("hevs"), []byte("avcs"))
|
56 | 56 | // TODO: add support for remaining video formats at ftyps.com.
|
57 | 57 | )
|
| 58 | + |
| 59 | +// QuickTime matches a QuickTime File Format file. |
| 60 | +// https://www.loc.gov/preservation/digital/formats/fdd/fdd000052.shtml |
| 61 | +// https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap1/qtff1.html#//apple_ref/doc/uid/TP40000939-CH203-38190 |
| 62 | +// https://github.com/apache/tika/blob/0f5570691133c75ac4472c3340354a6c4080b104/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml#L7758-L7777 |
| 63 | +func QuickTime(raw []byte, _ uint32) bool { |
| 64 | + if len(raw) < 12 { |
| 65 | + return false |
| 66 | + } |
| 67 | + // First 4 bytes represent the size of the atom as unsigned int. |
| 68 | + // Next 4 bytes are the type of the atom. |
| 69 | + // For `ftyp` atoms check if first byte in size is 0, otherwise, a text file |
| 70 | + // which happens to contain 'ftypqt ' at index 4 will trigger a false positive. |
| 71 | + if bytes.Equal(raw[4:12], []byte("ftypqt ")) || |
| 72 | + bytes.Equal(raw[4:12], []byte("ftypmoov")) { |
| 73 | + return raw[0] == 0x00 |
| 74 | + } |
| 75 | + basicAtomTypes := [][]byte{ |
| 76 | + []byte("moov\x00"), |
| 77 | + []byte("mdat\x00"), |
| 78 | + []byte("free\x00"), |
| 79 | + []byte("skip\x00"), |
| 80 | + []byte("pnot\x00"), |
| 81 | + } |
| 82 | + for _, a := range basicAtomTypes { |
| 83 | + if bytes.Equal(raw[4:9], a) { |
| 84 | + return true |
| 85 | + } |
| 86 | + } |
| 87 | + return bytes.Equal(raw[:8], []byte("\x00\x00\x00\x08wide")) |
| 88 | +} |
0 commit comments