cherry-pick.FILE5_29-38-gafec4e7c.combined.patch 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. Subject: Combined patch of all commits since the 5.29 release
  2. Origin: FILE5_29..FILE5_29-38-gafec4e7c
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Sun Jan 22 22:02:15 2017 +0000
  5. Excluded: a317154a ("compute the search match length correctly (found by oss-fuzzer)"
  6. as it introduces a regression.
  7. --- a/ChangeLog
  8. +++ b/ChangeLog
  9. @@ -1,6 +1,11 @@
  10. +2016-11-06 10:52 Christos Zoulas <christos@zoulas.com>
  11. +
  12. + * Allow @@@ in extensions
  13. + * Add missing overflow check in der magic (Jonas Wagner)
  14. +
  15. 2016-10-25 10:40 Christos Zoulas <christos@zoulas.com>
  16. - * release 5.28
  17. + * release 5.29
  18. 2016-10-24 11:20 Christos Zoulas <christos@zoulas.com>
  19. --- a/doc/file.man
  20. +++ b/doc/file.man
  21. @@ -238,8 +238,8 @@
  22. to test the standard input, use
  23. .Sq -
  24. as a filename argument.
  25. -Please note that
  26. -.Ar namefile
  27. +Please note that
  28. +.Ar namefile
  29. is unwrapped and the enclosed filenames are processed when this option is
  30. encountered and before any further options processing is done.
  31. This allows one to process multiple lists of files with different command line
  32. @@ -411,10 +411,10 @@
  33. .Fl h
  34. options.
  35. .Sh SEE ALSO
  36. -.Xr magic __FSECTION__ ,
  37. .Xr hexdump 1 ,
  38. .Xr od 1 ,
  39. .Xr strings 1 ,
  40. +.Xr magic __FSECTION__
  41. .Sh STANDARDS CONFORMANCE
  42. This program is believed to exceed the System V Interface Definition
  43. of FILE(CMD), as near as one can determine from the vague language
  44. @@ -530,16 +530,15 @@
  45. the first version.
  46. Geoff Collyer found several inadequacies
  47. and provided some magic file entries.
  48. -Contributions by the
  49. +Contributions of the
  50. .Sq \*[Am]
  51. operator by Rob McMahon,
  52. .Aq cudcv@warwick.ac.uk ,
  53. 1989.
  54. .Pp
  55. -Guy Harris,
  56. +Guy Harris,
  57. .Aq guy@netapp.com ,
  58. made many changes from 1993 to the present.
  59. -1989.
  60. .Pp
  61. Primary development and maintenance from 1990 to the present by
  62. Christos Zoulas
  63. @@ -587,7 +586,6 @@
  64. .Nm
  65. returns 0 on success, and non-zero on error.
  66. .Sh BUGS
  67. -.Pp
  68. Please report bugs and send patches to the bug tracker at
  69. .Pa http://bugs.gw.com/
  70. or the mailing list at
  71. @@ -596,7 +594,6 @@
  72. .Pa http://mx.gw.com/mailman/listinfo/file
  73. first to subscribe).
  74. .Sh TODO
  75. -.Pp
  76. Fix output so that tests for MIME and APPLE flags are not needed all
  77. over the place, and actual output is only done in one place.
  78. This needs a design.
  79. @@ -645,16 +642,16 @@
  80. .Dq name
  81. and
  82. .Dq use
  83. -to check for consistency at compile time (duplicate
  84. +to check for consistency at compile time (duplicate
  85. .Dq name ,
  86. .Dq use
  87. pointing to undefined
  88. .Dq name
  89. ).
  90. -Make
  91. +Make
  92. .Dq name
  93. /
  94. -.Dq use
  95. +.Dq use
  96. more efficient by keeping a sorted list of names.
  97. Special-case ^ to flip endianness in the parser so that it does not
  98. have to be escaped, and document it.
  99. --- a/doc/magic.man
  100. +++ b/doc/magic.man
  101. @@ -7,7 +7,7 @@
  102. .Nm magic
  103. .Nd file command's magic pattern file
  104. .Sh DESCRIPTION
  105. -This manual page documents the format of the magic file as
  106. +This manual page documents the format of magic files as
  107. used by the
  108. .Xr file __CSECTION__
  109. command, version __VERSION__.
  110. @@ -17,13 +17,19 @@
  111. among other tests,
  112. a test for whether the file contains certain
  113. .Dq "magic patterns" .
  114. -The file
  115. -.Pa __MAGIC__
  116. -specifies what patterns are to be tested for, what message or
  117. +The database of these
  118. +.Dq "magic patterns"
  119. +is usually located in a binary file in
  120. +.Pa __MAGIC__.mgc
  121. +or a directory of source text magic pattern fragment files in
  122. +.Pa __MAGIC__ .
  123. +The database specifies what patterns are to be tested for, what message or
  124. MIME type to print if a particular pattern is found,
  125. and additional information to extract from the file.
  126. .Pp
  127. -Each line of the file specifies a test to be performed.
  128. +The format of the source fragment files that are used to build this database
  129. +is as follows:
  130. +Each line of a fragment file specifies a test to be performed.
  131. A test compares the data starting at a particular offset
  132. in the file with a byte value, a string or a numeric value.
  133. If the test succeeds, a message is printed.
  134. --- a/magic/Magdir/animation
  135. +++ b/magic/Magdir/animation
  136. @@ -855,10 +855,12 @@
  137. # X3D (Extensible 3D) [http://www.web3d.org/specifications/x3d-3.0.dtd]
  138. # From Michel Briand <michelbriand@free.fr>
  139. -0 string/t \<?xml\ version="
  140. -!:strength +1
  141. ->20 search/1000/cw \<!DOCTYPE\ X3D X3D (Extensible 3D) model xml text
  142. -!:mime model/x3d
  143. +# mimetype from https://www.iana.org/assignments/media-types/model/x3d+xml
  144. +# Example http://www.web3d.org/x3d/content/examples/Basic/course/CreateX3DFromStringRandomSpheres.x3d
  145. +0 string/w \<?xml\ version=
  146. +!:strength + 5
  147. +>20 search/1000/w \<!DOCTYPE\ X3D X3D (Extensible 3D) model xml text
  148. +!:mime model/x3d+xml
  149. #---------------------------------------------------------------------------
  150. # HVQM4: compressed movie format designed by Hudson for Nintendo GameCube
  151. --- a/magic/Magdir/audio
  152. +++ b/magic/Magdir/audio
  153. @@ -469,6 +469,8 @@
  154. >>20 byte&0xe 0xc \b, 7 channels
  155. >>20 byte&0xe 0xe \b, 8 channels
  156. # some common sample rates
  157. +>>17 belong&0xfffff0 0x2ee000 \b, 192 kHz
  158. +>>17 belong&0xfffff0 0x158880 \b, 88.2 kHz
  159. >>17 belong&0xfffff0 0x0ac440 \b, 44.1 kHz
  160. >>17 belong&0xfffff0 0x0bb800 \b, 48 kHz
  161. >>17 belong&0xfffff0 0x07d000 \b, 32 kHz
  162. --- a/magic/Magdir/console
  163. +++ b/magic/Magdir/console
  164. @@ -9,17 +9,19 @@
  165. # References:
  166. # - http://wiki.nesdev.com/w/index.php/INES
  167. # - http://wiki.nesdev.com/w/index.php/NES_2.0
  168. -0 string NES\x1A iNES ROM image
  169. +
  170. +# Common header for iNES, NES 2.0, and Wii U iNES.
  171. +0 name nes-rom-image-ines
  172. >7 byte&0x0C =0x8 (NES 2.0)
  173. >4 byte x \b: %ux16k PRG
  174. ->5 byte x \b, %ux16k CHR
  175. +>5 byte x \b, %ux8k CHR
  176. >6 byte&0x08 =0x8 [4-Scr]
  177. >6 byte&0x09 =0x0 [H-mirror]
  178. >6 byte&0x09 =0x1 [V-mirror]
  179. >6 byte&0x02 =0x2 [SRAM]
  180. >6 byte&0x04 =0x4 [Trainer]
  181. >7 byte&0x03 =0x2 [PC10]
  182. ->7 byte&0x03 =0x1 [VS
  183. +>7 byte&0x03 =0x1 [VS]
  184. >>7 byte&0x0C =0x8
  185. # NES 2.0: VS PPU
  186. >>>13 byte&0x0F =0x0 \b, RP2C03B
  187. @@ -43,17 +45,24 @@
  188. >>12 byte&0x03 =0x1 [PAL]
  189. >>12 byte&0x02 =0x2 [NTSC+PAL]
  190. +# Standard iNES ROM header.
  191. +0 string NES\x1A NES ROM image (iNES)
  192. +>0 use nes-rom-image-ines
  193. +
  194. +# Wii U Virtual Console iNES ROM header.
  195. +0 belong 0x4E455300 NES ROM image (Wii U Virtual Console)
  196. +>0 use nes-rom-image-ines
  197. +
  198. #------------------------------------------------------------------------------
  199. # unif: file(1) magic for UNIF-format Nintendo Entertainment System ROM images
  200. # Reference: http://wiki.nesdev.com/w/index.php/UNIF
  201. # From: David Korth <gerbilsoft@gerbilsoft.com>
  202. -# TODO commit on 2016/03/21
  203. #
  204. # NOTE: The UNIF format uses chunks instead of a fixed header,
  205. # so most of the data isn't easily parseable.
  206. #
  207. 0 string UNIF
  208. ->4 lelong <16 UNIF v%d format NES ROM image
  209. +>4 lelong <16 NES ROM image (UNIF v%d format)
  210. #------------------------------------------------------------------------------
  211. # fds: file(1) magic for Famciom Disk System disk images
  212. @@ -63,25 +72,40 @@
  213. # Disk info block. (block 1)
  214. 0 name nintendo-fds-disk-info-block
  215. ->1 string *NINTENDO-HVC* Famicom Disk System disk image:
  216. >23 byte !1 FMC-
  217. >23 byte 1 FSC-
  218. >16 string x \b%.3s
  219. ->15 byte x \b, mfr 0x%02X
  220. +>15 byte x \b, mfr %02X
  221. >20 byte x (Rev.%02u)
  222. # Headered version.
  223. 0 string FDS\x1A
  224. ->0x11 string *NINTENDO-HVC*
  225. +>0x11 string *NINTENDO-HVC* Famicom Disk System disk image:
  226. >>0x10 use nintendo-fds-disk-info-block
  227. >4 byte 1 (%u side)
  228. >4 byte !1 (%u sides)
  229. # Unheadered version.
  230. -1 string *NINTENDO-HVC*
  231. +1 string *NINTENDO-HVC* Famicom Disk System disk image:
  232. >0 use nintendo-fds-disk-info-block
  233. #------------------------------------------------------------------------------
  234. +# tnes: file(1) magic for TNES-format Nintendo Entertainment System ROM images
  235. +# Used by Nintendo 3DS NES Virtual Console games.
  236. +# From: David Korth <gerbilsoft@gerbilsoft.com>
  237. +#
  238. +0 string TNES NES ROM image (Nintendo 3DS Virtual Console)
  239. +>4 byte 100 \b: FDS,
  240. +>>0x2010 use nintendo-fds-disk-info-block
  241. +>4 byte !100 \b: TNES mapper %u
  242. +>>5 byte x \b, %ux8k PRG
  243. +>>6 byte x \b, %ux8k CHR
  244. +>>7 byte&0x08 =1 [WRAM]
  245. +>>8 byte&0x09 =1 [H-mirror]
  246. +>>8 byte&0x09 =2 [V-mirror]
  247. +>>8 byte&0x02 =3 [VRAM]
  248. +
  249. +#------------------------------------------------------------------------------
  250. # gameboy: file(1) magic for the Nintendo (Color) Gameboy raw ROM format
  251. # Reference: http://gbdev.gg8.se/wiki/articles/The_Cartridge_Header
  252. #
  253. @@ -617,6 +641,52 @@
  254. >0x218 belong 0x5D1C9EA3 Nintendo Wii disc image (WBFS format):
  255. >>0x200 use nintendo-gcn-disc-common
  256. +# Type: Nintendo GameCube/Wii disc image (CISO format)
  257. +# NOTE: This is NOT the same as Compact ISO or PSP CISO,
  258. +# though it has the same magic number.
  259. +0 string CISO
  260. +# Other fields are used to determine what type of CISO this is:
  261. +# - 0x04 == 0x00200000: GameCube/Wii CISO (block_size)
  262. +# - 0x10 == 0x00000800: PSP CISO (ISO-9660 sector size)
  263. +# - None of the above: Compact ISO.
  264. +>4 lelong 0x200000
  265. +>>8 byte 1
  266. +>>>0x801C belong 0xC2339F3D Nintendo GameCube disc image (CISO format):
  267. +>>>>0x8000 use nintendo-gcn-disc-common
  268. +>>>0x8018 belong 0x5D1C9EA3 Nintendo Wii disc image (CISO format):
  269. +>>>>0x8000 use nintendo-gcn-disc-common
  270. +
  271. +# Type: Nintendo GameCube/Wii disc image (GCZ format)
  272. +# Due to zlib compression, we can't get the actual disc information.
  273. +0 lelong 0xB10BC001
  274. +>4 lelong 0 Nintendo GameCube disc image (GCZ format)
  275. +>4 lelong 1 Nintendo Wii disc image (GCZ format)
  276. +>4 lelong >1 Nintendo GameCube/Wii disc image (GCZ format)
  277. +
  278. +# Type: Nintendo GameCube/Wii disc image (WDF format)
  279. +0 string WII\001DISC
  280. +>8 belong 1
  281. +# WDFv1
  282. +>>0x54 belong 0xC2339F3D Nintendo GameCube disc image (WDFv1 format):
  283. +>>>0x38 use nintendo-gcn-disc-common
  284. +>>0x58 belong 0x5D1C9EA3 Nintendo Wii disc image (WDFv1 format):
  285. +>>>0x38 use nintendo-gcn-disc-common
  286. +>8 belong 2
  287. +# WDFv2
  288. +>>(12.L+0x1C) belong 0xC2339F3D Nintendo GameCube disc image (WDFv2 format):
  289. +>>>(12.L) use nintendo-gcn-disc-common
  290. +>>(12.L+0x18) belong 0x5D1C9EA3 Nintendo Wii disc image (WDFv2 format):
  291. +>>>(12.L) use nintendo-gcn-disc-common
  292. +
  293. +# Type: Nintendo GameCube/Wii disc image (WIA format)
  294. +0 string WIA\001 Nintendo
  295. +>0x48 belong 0 GameCube/Wii
  296. +>0x48 belong 1 GameCube
  297. +>0x48 belong 2 Wii
  298. +>0x48 belong >2 GameCube/Wii
  299. +>0x48 belong x disc image (WIA format):
  300. +>>0x58 use nintendo-gcn-disc-common
  301. +
  302. #------------------------------------------------------------------------------
  303. # Nintendo 3DS file formats.
  304. #
  305. @@ -750,3 +820,17 @@
  306. #
  307. 0 string g\ GCE Vectrex ROM image
  308. >0x11 string >\0 \b: "%.16s"
  309. +
  310. +#------------------------------------------------------------------------------
  311. +# amiibo: file(1) magic for Nintendo amiibo NFC dumps.
  312. +# From: David Korth <gerbilsoft@gerbilsoft.com>
  313. +# Reference: https://www.3dbrew.org/wiki/Amiibo
  314. +0x00 byte 0x04
  315. +>0x0A beshort 0x0FE0
  316. +>>0x0C belong 0xF110FFEE
  317. +>>>0x208 beshort 0x0100
  318. +>>>>0x020A byte 0x0F
  319. +>>>>>0x020C bequad 0x000000045F000000
  320. +>>>>>>0x5B byte 0x02
  321. +>>>>>>>0x54 belong x Nintendo amiibo NFC dump - amiibo ID: %08X-
  322. +>>>>>>>0x58 belong x \b%08X
  323. --- a/magic/Magdir/filesystems
  324. +++ b/magic/Magdir/filesystems
  325. @@ -1949,7 +1949,19 @@
  326. >0 use cdrom
  327. # .cso files
  328. -0 string CISO Compressed ISO CD image
  329. +# Reference: http://pismotec.com/ciso/ciso.h
  330. +# NOTE: There are two other formats with the same magic but
  331. +# completely incompatible specifications:
  332. +# - GameCube/Wii CISO: https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/DiscIO/CISOBlob.h
  333. +# - PSP CISO: https://github.com/jamie/ciso/blob/master/ciso.h
  334. +0 string CISO
  335. +# Other fields are used to determine what type of CISO this is:
  336. +# - 0x04 == 0x00200000: GameCube/Wii CISO (block_size)
  337. +# - 0x10 == 0x00000800: PSP CISO (ISO-9660 sector size)
  338. +# - None of the above: Compact ISO.
  339. +>4 lelong !0
  340. +>>4 lelong !0x200000
  341. +>>>0x10 lelong !0x800 Compressed ISO CD image
  342. # cramfs filesystem - russell@coker.com.au
  343. 0 lelong 0x28cd3d45 Linux Compressed ROM File System data, little endian
  344. @@ -2041,6 +2053,13 @@
  345. >29 byte 16 \bBlackfin,
  346. >29 byte 17 \bAVR32,
  347. >29 byte 18 \bSTMicroelectronics ST200,
  348. +>29 byte 19 \bSandbox architecture,
  349. +>29 byte 20 \bANDES Technology NDS32,
  350. +>29 byte 21 \bOpenRISC 1000,
  351. +>29 byte 22 \bARM 64-bit,
  352. +>29 byte 23 \bDesignWare ARC,
  353. +>29 byte 24 \bx86_64,
  354. +>29 byte 25 \bXtensa,
  355. >30 byte 0 Invalid Image
  356. >30 byte 1 Standalone Program
  357. >30 byte 2 OS Kernel Image
  358. --- a/magic/Magdir/fonts
  359. +++ b/magic/Magdir/fonts
  360. @@ -100,9 +100,11 @@
  361. # X11 fonts, from Daniel Quinlan (quinlan@yggdrasil.com)
  362. # PCF must come before SGI additions ("MIPSEL MIPS-II COFF" collides)
  363. -0 string \001fcp X11 Portable Compiled Font data
  364. ->12 byte 0x02 \b, LSB first
  365. ->12 byte 0x0a \b, MSB first
  366. +0 string \001fcp X11 Portable Compiled Font data,
  367. +>12 lelong ^0x08 bit: LSB,
  368. +>12 lelong &0x08 bit: MSB,
  369. +>12 lelong ^0x04 byte: LSB first
  370. +>12 lelong &0x04 byte: MSB first
  371. 0 string D1.0\015 X11 Speedo font data
  372. #------------------------------------------------------------------------------
  373. --- /dev/null
  374. +++ b/magic/Magdir/gpu
  375. @@ -0,0 +1,16 @@
  376. +
  377. +#------------------------------------------------------------------------------
  378. +# $File: images,v 1.118 2016/11/08 02:58:21 christos Exp $
  379. +# gpu: file(1) magic for GPU input files
  380. +
  381. +# Standard Portable Intermediate Representation (SPIR)
  382. +# Documentation: https://www.khronos.org/spir
  383. +# Typical file extension: .spv
  384. +
  385. +0 belong 0x07230203 Khronos SPIR-V binary, big-endian
  386. +>4 belong x \b, version 0x%08x
  387. +>8 belong x \b, generator 0x%08x
  388. +
  389. +0 lelong 0x07230203 Khronos SPIR-V binary, little-endian
  390. +>4 lelong x \b, version 0x%08x
  391. +>8 lelong x \b, generator 0x%08x
  392. --- a/magic/Magdir/icc
  393. +++ b/magic/Magdir/icc
  394. @@ -11,41 +11,204 @@
  395. # http://www.color.org/specification/ICC1v43_2010-12.pdf
  396. #
  397. # for Specification ICC.1:2010 (Profile version 4.3.0.0).
  398. +# URL: http://fileformats.archiveteam.org/wiki/ICC_profile
  399. +# Reference: http://www.color.org/iccmax/ICC.2-2016-7.pdf
  400. +# Update: Joerg Jenderek
  401. #
  402. # Bytes 36 to 39 contain a generic profile file signature of "acsp";
  403. # bytes 40 to 43 "may be used to identify the primary platform/operating
  404. # system framework for which the profile was created".
  405. #
  406. -# There are other fields that might be worth dumping as well.
  407. -#
  408. +# check and display ICC/ICM color profile
  409. +0 name color-profile
  410. +>36 string acsp
  411. +# skip ASCII like Cognacspirit.txt by month <= 12
  412. +>>26 ubeshort <13
  413. +# platform/operating system. Only 5 mentioned
  414. +#
  415. # This appears to be what's used for Apple ColorSync profiles.
  416. # Instead of adding that, Apple just changed the generic "acsp" entry
  417. # to be for "ColorSync ICC Color Profile" rather than "Kodak Color
  418. # Management System, ICC Profile".
  419. # Yes, it's "APPL", not "AAPL"; see the spec.
  420. -36 string acspAPPL ColorSync ICC Profile
  421. -!:mime application/vnd.iccprofile
  422. +>>>40 string APPL ColorSync
  423. # Microsoft ICM color profile
  424. -36 string acspMSFT Microsoft ICM Color Profile
  425. -!:mime application/vnd.iccprofile
  426. +>>>40 string MSFT Microsoft
  427. # Yes, that's a blank after "SGI".
  428. -36 string acspSGI\ SGI ICC Profile
  429. -!:mime application/vnd.iccprofile
  430. +>>>40 string SGI\ SGI
  431. # XXX - is this what's used for the Sun KCMS or not? The standard file
  432. # uses just "acsp" for that, but Apple's file uses it for "ColorSync",
  433. # and there *is* an identified "primary platform" value of SUNW.
  434. -36 string acspSUNW Sun KCMS ICC Profile
  435. +>>>40 string SUNW Sun KCMS
  436. +
  437. +# 5th platform
  438. +>>>40 string TGNT Taligent
  439. +
  440. +# remaing "l" "e" of "color profile" printed later to avoid error
  441. +>>>40 string x color profi
  442. +#>>>40 string x (%.4s)
  443. !:mime application/vnd.iccprofile
  444. +# for "ICM" extension only versions 2.x and for Kodak "CC" 2.0 is found
  445. +>>>8 ubyte =2
  446. +# do not use empty message text to a avoid error like
  447. +# icc, 82: Warning: Current entry does not yet have a description for adding a EXTENSION type
  448. +# file.exe: could not find any valid magic files!
  449. +>>>>9 ubyte !0 \ble
  450. +!:ext icc/icm
  451. +# minor version
  452. +>>>>9 ubyte =0 \bl
  453. +# Kodak colour management system
  454. +>>>>>4 string =KCMS \be
  455. +!:ext icc/icm/cc
  456. +>>>>>4 string !KCMS \be
  457. +!:ext icc/icm
  458. +>>>8 ubyte !2 \ble
  459. +!:ext icc
  460. +# Profile version major.4bit-minor.sub1.sub2 like 4.3.0.0 (04300000h)
  461. +>>>8 ubyte x %u
  462. +>>>9 ubyte/16 x \b.%u
  463. +# reserved and shall be null but 205.205 in umx1220u.icm
  464. +>>>10 ubyte >0 \b.%u
  465. +>>>>11 ubyte >0 \b.%u
  466. +# preferred colour management module like appl CCMS KCMS Lino UCCM "Win " "FF "
  467. +# skip space like in brmsl08f.icm and null like in brmsl09f.icm, brmsl07f.icm
  468. +>>>4 string >\ \b, type %.2s
  469. +>>>>6 string >\ \b%.1s
  470. +>>>>>7 string >\ \b%.1s
  471. +# colour space "XYZ " "Lab " "RGB " CMYK GRAY ...
  472. +>>>16 string x \b, %.3s
  473. +>>>19 string >\ \b%.1s
  474. +# Profile Connection Space (PCS) field usually "XYZ " or "Lab " but sometimes
  475. +# null or CMYK like in ISOcoated_v2_to_PSOcoated_v3_DeviceLink.icc
  476. +>>>20 string >\0 \b/%.3s
  477. +>>>>23 string >\ \b%.1s
  478. +# eleven device classes
  479. +>>>12 string x \b-%.4s device
  480. +# skip 00001964h in hpf69000.icc or 0h in XRDC50Q.ICM or " ROT" in brmsl05f.icm
  481. +>>>52 string >\
  482. +# skip "none" model like in "Trinitron Compatible 9300K G2.2.icm"
  483. +>>>>52 ubelong !0x6e6f6e65
  484. +# device manufacturer field like "HP " "IBM " EPSO
  485. +>>>>>48 string x \b, %.2s
  486. +>>>>>50 string >\ \b%.1s
  487. +>>>>>51 string >\ \b%.1s
  488. +# model like "ADI " "A265" and skip 20000404h in IS330.icm for RICOH RUSSIAN-SC
  489. +>>>>>52 string >\ \ \b/%.3s
  490. +>>>>>>55 string >\ \b%.1s
  491. +>>>>>52 string x model
  492. +# creator (often same as manufacture) like HP SONY XROX or null like in A925A.icm
  493. +>>>80 string >\0 by %.2s
  494. +>>>>82 string >\ \b%.1s
  495. +>>>>>83 string >\ \b%.1s
  496. +# profile size
  497. +>>>0 ubelong x \b, %u bytes
  498. +# skip invalid date 0 like in linearSRGB.icc
  499. +>>>24 ubequad !0
  500. +# datetime dd-mm-yyyy hh:mm:ss
  501. +>>>>28 ubeshort x \b, %u
  502. +# month <= 12
  503. +>>>>26 ubeshort x \b-%u
  504. +# year
  505. +>>>>24 ubeshort x \b-%u
  506. +# do not display midnight time like in CNHP8308.ICC
  507. +>>>>30 ubequad&0xFFffFFffFFff0000 !0
  508. +# hour <= 24
  509. +>>>>>30 ubeshort x %u
  510. +# minutes <= 59
  511. +>>>>>32 ubeshort x \b:%.2u
  512. +# seconds <= 59
  513. +>>>>>34 ubeshort x \b:%.2u
  514. +# vendor specific flags like 2 in HPCLJ5.ICM
  515. +>>>44 ubeshort >0 \b, 0x%x vendor flags
  516. +# profile flags bits 0-2 of least 16 used by ICC
  517. +#>>>44 ubelong >0 \b, 0x%x flags
  518. +# icEmbeddedProfileTrue
  519. +>>>44 ubelong &1 \b, embedded
  520. +# icEmbeddedProfileFalse
  521. +#>>>44 ubelong ^1 \b, not embedded
  522. +# icUseWithEmbeddedDataOnly
  523. +>>>44 ubelong &2 \b, dependently
  524. +# icUseAnywhere
  525. +#>>>44 ubelong ^2 \b, independently
  526. +>>>44 ubelong &4 \b, MCS
  527. +#>>>44 ubelong ^4 \b, no MCS
  528. +# vendor specific device attributes 1~srgb.icc
  529. +# E000D00h~CNB7QEDA.ICM C000A00h~CNB5FCAA.ICM 01040401h~CNB25PE3.ICM
  530. +>>>56 ubelong >0 \b, 0x%x vendor attribute
  531. +# ICC device attributes bits 0-7 used
  532. +#>>>60 ubelong x \b, 0x%x attribute
  533. +# http://www.color.org/icc34.h
  534. +>>>60 ubelong &0x01 \b, transparent
  535. +#>>>60 ubelong ^0x01 \b, reflective
  536. +>>>60 ubelong &0x02 \b, matte
  537. +#>>>60 ubelong ^0x02 \b, glossy
  538. +>>>60 ubelong &0x04 \b, negative
  539. +#>>>60 ubelong ^0x04 \b, positive
  540. +>>>60 ubelong &0x08 \b, black&white
  541. +#>>>60 ubelong ^0x08 \b, colour
  542. +>>>60 ubelong &0x10 \b, non-paper
  543. +#>>>60 ubelong ^0x10 \b, paper
  544. +>>>60 ubelong &0x20 \b, non-textured
  545. +#>>>60 ubelong ^0x20 \b, textured
  546. +>>>60 ubelong &0x40 \b, non-isotropic
  547. +#>>>60 ubelong ^0x40 \b, isotropic
  548. +>>>60 ubelong &0x80 \b, self-luminous
  549. +#>>>60 ubelong ^0x80 \b, non-self-luminous
  550. +# rendering intent 0-3 but 7AEA5027h in EE051__1.ICM 6CB1BCh in EE061__1.ICM
  551. +>>>64 ubelong >3 \b, 0x%x rendering intent
  552. +#>>>64 ubelong =0 \b, perceptual
  553. +>>>64 ubelong =1 \b, relative colorimetric
  554. +>>>64 ubelong =2 \b, saturation
  555. +>>>64 ubelong =3 \b, absolute colorimetric
  556. +# PCS illuminant (3*s15Fixed16Numbers) often 0000f6d6 00010000 0000d32d
  557. +>>>71 ubequad !0xd6000100000000d3 \b, PCS
  558. +# usually X~0.9642*65536=63189.8112~63190=F6D5h ; but also found
  559. +# often F6D6 in gt5000r.icm, F6B8 in kodakce.icm, F6CA in RSWOP.icm
  560. +>>>>68 ubelong !0x0000f6d5 X=0x%x
  561. +# usually Y=1.0~00010000h but Y=0 in brmsl07f.icm
  562. +>>>>72 ubelong !0x00010000 Y=0x%x
  563. +# usually Z~0.8249*65536=54060.6464~54061=D32Dh ; but also found
  564. +# D2F7 in hp1200c.icm, often D32C in A925A.icm, D309 in RSWOP.icm , D2F8 in kodak_dc.icm
  565. +>>>>76 ubelong !0x0000d32d Z=0x%x
  566. +# Profile ID. MD5 fingerprinting method as defined in Internet RFC 1321.
  567. +>>>84 ubequad >0 \b, 0x%llx MD5
  568. +# reserved in older versions should be zero but also found CDCDCDCDCDCDCDCD
  569. +#>>100 ubequad x \b 0x%llx reserved
  570. +# tag table
  571. +# 6 <= tags count <= 43
  572. +#>>>128 ubelong >43 \b, %u tags
  573. +>>>128 ubelong x
  574. +# shall contain the profileDescriptionTag "desc" , copyrightTag "cprt"
  575. +# search range = tags count * 12 -8=< maximal tag count * 12 -8= 43 * 12 -8= 508
  576. +>>>>132 search/508 cprt
  577. +# but no copyright tag in linearSRGB.icc
  578. +# beneath /System/Library/Frameworks/WebKit.framework/
  579. +# Versions/A/Frameworks/WebCore.framework/Versions/A/Resources
  580. +>>>>132 default x \b, no copyright tag
  581. +# 1st tag
  582. +#>>>132 string x \b, 1st tag %.4s
  583. +#>>>136 ubelong x 0x%x offset
  584. +#>>>140 ubelong x 0x%x len
  585. +# 2nd tag,...
  586. +# look also for profileDescriptionTag "desc"
  587. +>>>132 search/508 desc
  588. +# look further for TextDescriptionType "desc" signature
  589. +>>>>(&0.L) string =desc
  590. +>>>>>&4 pstring/l x "%s"
  591. +# look alternative for multiLocalizedUnicodeType "mluc" signature like in VideoPAL.icc
  592. +>>>>(&0.L) string =mluc
  593. +>>>>>&(&8.L) ubequad x
  594. +>>>>>>&4 bestring16 x '%s'
  595. # Any other profile.
  596. # XXX - should we use "acsp\0\0\0\0" for "no primary platform" profiles,
  597. # and use "acsp" for everything else and dump the "primary platform"
  598. # string in those cases?
  599. -36 string acsp ICC Profile
  600. -!:mime application/vnd.iccprofile
  601. +36 string acsp
  602. +>0 use color-profile
  603. --- a/magic/Magdir/images
  604. +++ b/magic/Magdir/images
  605. @@ -41,7 +41,11 @@
  606. >>>>>>3 uleshort 0
  607. >>>>>>>0 use tga-image
  608. # Color Map
  609. ->>>>>1 ubyte >0
  610. +>>>>>1 belong&0xfff7ffff 0x01010000
  611. +>>>>>>0 use tga-image
  612. +>>>>>1 belong&0xfff7ffff 0x00020000
  613. +>>>>>>0 use tga-image
  614. +>>>>>1 belong&0xfff7ffff 0x00030000
  615. >>>>>>0 use tga-image
  616. # display tga bitmap image information
  617. 0 name tga-image
  618. @@ -418,6 +422,7 @@
  619. #
  620. 0 string \x89PNG\x0d\x0a\x1a\x0a PNG image data
  621. !:mime image/png
  622. +!:strength +10
  623. >16 belong x \b, %d x
  624. >20 belong x %d,
  625. >24 byte x %d-bit
  626. @@ -1451,3 +1456,12 @@
  627. >0x10 string GVRT Sega GVR image:
  628. >>0x10 use sega-gvr-image-header
  629. >>0x08 belong x \b, global index = %u
  630. +
  631. +# Light Field Picture
  632. +# Documentation: http://optics.miloush.net/lytro/TheFileFormat.aspx
  633. +# Typical file extensions: .lfp .lfr .lfx
  634. +
  635. +0 belong 0x894C4650
  636. +>4 belong 0x0D0A1A0A
  637. +>12 belong 0x00000000 Lytro Light Field Picture
  638. +>8 belong x \b, version %d
  639. --- a/magic/Magdir/make
  640. +++ b/magic/Magdir/make
  641. @@ -2,6 +2,7 @@
  642. # $File: make,v 1.2 2015/08/25 07:34:06 christos Exp $
  643. # make: file(1) magic for makefiles
  644. #
  645. +# URL: https://en.wikipedia.org/wiki/Make_(software)
  646. 0 regex/100l \^CFLAGS makefile script text
  647. !:mime text/x-makefile
  648. 0 regex/100l \^VPATH makefile script text
  649. @@ -10,12 +11,19 @@
  650. !:mime text/x-makefile
  651. 0 regex/100l \^all: makefile script text
  652. !:mime text/x-makefile
  653. -0 regex/100l \^\.PRECIOUS makefile script text
  654. +0 regex/100l \^\\.PRECIOUS makefile script text
  655. !:mime text/x-makefile
  656. -0 regex/100l \^\.BEGIN BSD makefile script text
  657. +# Update: Joerg Jenderek
  658. +# Reference: https://www.freebsd.org/cgi/man.cgi?make(1)
  659. +# exclude grub-core\lib\libgcrypt\mpi\Makefile.am with "#BEGIN_ASM_LIST"
  660. +# by additional escaping point character
  661. +0 regex/100l \^\\.BEGIN BSD makefile script text with "%s"
  662. +!:mime text/x-makefile
  663. +!:ext /mk
  664. +# exclude MS Windows help file CoNtenT with ":include FOOBAR.CNT"
  665. +# and NSIS script with "!include" by additional escaping point character
  666. +0 regex/100l \^\\.include BSD makefile script text with "%s"
  667. !:mime text/x-makefile
  668. -0 regex/100l \^\.include BSD makefile script text
  669. -!:mime text/x-makefile
  670. -
  671. +!:ext /mk
  672. 0 regex/100l \^SUBDIRS automake makefile script text
  673. !:mime text/x-makefile
  674. --- a/magic/Magdir/msdos
  675. +++ b/magic/Magdir/msdos
  676. @@ -565,10 +565,23 @@
  677. 0 string/b PO^Q` Microsoft Word 6.0 Document
  678. !:mime application/msword
  679. #
  680. -0 string/b \376\067\0\043 Microsoft Office Document
  681. +4 long 0
  682. +>0 belong 0xfe320000 Microsoft Word for Macintosh 1.0
  683. !:mime application/msword
  684. -0 string/b \333\245-\0\0\0 Microsoft Office Document
  685. +!:ext mcw
  686. +>0 belong 0xfe340000 Microsoft Word for Macintosh 3.0
  687. !:mime application/msword
  688. +!:ext mcw
  689. +>0 belong 0xfe37001c Microsoft Word for Macintosh 4.0
  690. +!:mime application/msword
  691. +!:ext mcw
  692. +>0 belong 0xfe370023 Microsoft Word for Macintosh 5.0
  693. +!:mime application/msword
  694. +!:ext mcw
  695. +
  696. +0 string/b \333\245-\0\0\0 Microsoft Word 2.0 Document
  697. +!:mime application/msword
  698. +!:ext doc
  699. 512 string/b \354\245\301 Microsoft Word Document
  700. !:mime application/msword
  701. @@ -960,6 +973,7 @@
  702. # DOS EPS Binary File Header
  703. # From: Ed Sznyter <ews@Black.Market.NET>
  704. 0 belong 0xC5D0D3C6 DOS EPS Binary File
  705. +!:mime image/x-eps
  706. >4 long >0 Postscript starts at byte %d
  707. >>8 long >0 length %d
  708. >>>12 long >0 Metafile starts at byte %d
  709. @@ -1106,3 +1120,40 @@
  710. 0 string MIOPEN Mallard BASIC Jetsam data
  711. 0 string Jetsam0 Mallard BASIC Jetsam index data
  712. +# DOS backup 2.0 to 3.2
  713. +
  714. +# backupid.@@@
  715. +
  716. +# plausibility check for date
  717. +0x3 ushort >1979
  718. +>0x5 ubyte-1 <31
  719. +>>0x6 ubyte-1 <12
  720. +# actually 121 nul bytes
  721. +>>>0x7 string \0\0\0\0\0\0\0\0
  722. +>>>>0x1 ubyte x DOS 2.0 backup id file, sequence %d
  723. +!:ext @@@
  724. +>>>>0x0 ubyte 0xff \b, last disk
  725. +
  726. +# backed up file
  727. +
  728. +# plausibility check for file name length
  729. +0x53 ubyte-1 <80
  730. +# actually 54 nul bytes
  731. +>0x54 string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
  732. +>>0x5 string x DOS 2.0 backed up file %s,
  733. +>>0 ubyte 0xff complete file
  734. +>>0 ubyte !0xff
  735. +>>>1 ushort x split file, sequence %d
  736. +
  737. +
  738. +# DOS backup 3.3 to 5.x
  739. +
  740. +# CONTROL.nnn files
  741. +0 string \x8bBACKUP\x20
  742. +# actually 128 nul bytes
  743. +>0xa string \0\0\0\0\0\0\0\0
  744. +>>0x9 ubyte x DOS 3.3 backup control file, sequence %d
  745. +>>0x8a ubyte 0xff \b, last disk
  746. +
  747. +# NB: The BACKUP.nnn files consist of the files backed up,
  748. +# concatenated.
  749. --- a/magic/Magdir/msx
  750. +++ b/magic/Magdir/msx
  751. @@ -245,18 +245,18 @@
  752. 0x4000 string/b AB
  753. >0x4002 uleshort >0x400F
  754. >>0x400A string \0\0\0\0\0\0 MSX ROM with nonstandard page order
  755. ->>0x4002 uleshort x \b, init=0x%04x
  756. ->>0x4004 uleshort >0 \b, stahdl=0x%04x
  757. ->>0x4006 uleshort >0 \b, devhdl=0x%04x
  758. ->>0x4008 uleshort >0 \b, bas=0x%04x
  759. +>>>0x4002 uleshort x \b, init=0x%04x
  760. +>>>0x4004 uleshort >0 \b, stahdl=0x%04x
  761. +>>>0x4006 uleshort >0 \b, devhdl=0x%04x
  762. +>>>0x4008 uleshort >0 \b, bas=0x%04x
  763. 0x8000 string/b AB
  764. >0x8002 uleshort >0x400F
  765. >>0x800A string \0\0\0\0\0\0 MSX ROM with nonstandard page order
  766. ->>0x8002 uleshort x \b, init=0x%04x
  767. ->>0x8004 uleshort >0 \b, stahdl=0x%04x
  768. ->>0x8006 uleshort >0 \b, devhdl=0x%04x
  769. ->>0x8008 uleshort >0 \b, bas=0x%04x
  770. +>>>0x8002 uleshort x \b, init=0x%04x
  771. +>>>0x8004 uleshort >0 \b, stahdl=0x%04x
  772. +>>>0x8006 uleshort >0 \b, devhdl=0x%04x
  773. +>>>0x8008 uleshort >0 \b, bas=0x%04x
  774. 0x3C000 string/b AB
  775. --- a/magic/Magdir/pbf
  776. +++ b/magic/Magdir/pbf
  777. @@ -6,6 +6,6 @@
  778. # OpenStreetMap Protocolbuffer Binary Format (.osm.pbf)
  779. # http://wiki.openstreetmap.org/wiki/PBF_Format
  780. # From: Markus Heidelberg <markus.heidelberg@web.de>
  781. -0 belong 0x0000000D
  782. ->4 beshort 0x0A09
  783. ->>6 string OSMHeader OpenStreetMap Protocolbuffer Binary Format
  784. +0 belong&0xfffffff0 0
  785. +>4 beshort 0x0A09
  786. +>>6 string OSMHeader OpenStreetMap Protocolbuffer Binary Format
  787. --- a/magic/Magdir/pgp
  788. +++ b/magic/Magdir/pgp
  789. @@ -19,15 +19,15 @@
  790. #>15 string SIGNED\040MESSAGE- signed message
  791. #>15 string PGP\040SIGNATURE- signature
  792. -2 string ---BEGIN\ PGP\ PUBLIC\ KEY\ BLOCK- PGP public key block
  793. +2 string ---BEGIN\040PGP\040PUBLIC\040KEY\040BLOCK- PGP public key block
  794. !:mime application/pgp-keys
  795. >10 search/100 \n\n
  796. >>&0 use pgp
  797. -0 string -----BEGIN\040PGP\40MESSAGE- PGP message
  798. +0 string -----BEGIN\040PGP\040MESSAGE- PGP message
  799. !:mime application/pgp
  800. >10 search/100 \n\n
  801. >>&0 use pgp
  802. -0 string -----BEGIN\040PGP\40SIGNATURE- PGP signature
  803. +0 string -----BEGIN\040PGP\040SIGNATURE- PGP signature
  804. !:mime application/pgp-signature
  805. >10 search/100 \n\n
  806. >>&0 use pgp
  807. --- a/magic/Magdir/sgml
  808. +++ b/magic/Magdir/sgml
  809. @@ -46,6 +46,12 @@
  810. !:mime text/html
  811. !:strength + 5
  812. +# SVG document
  813. +# https://www.w3.org/TR/SVG/single-page.html
  814. +0 search/4096/cWbt \<!doctype\ svg SVG XML document
  815. +!:mime image/svg+xml
  816. +!:strength + 5
  817. +
  818. 0 search/4096/cwt \<head\> HTML document text
  819. !:mime text/html
  820. !:strength + 5
  821. --- a/magic/Magdir/ssl
  822. +++ b/magic/Magdir/ssl
  823. @@ -1,8 +1,20 @@
  824. +
  825. +#------------------------------------------------------------------------------
  826. +# $File: ssl,v 1.3 2017/01/18 14:59:19 christos Exp $
  827. +# ssl: file(1) magic for SSL file formats
  828. +
  829. # Type: OpenSSL certificates/key files
  830. # From: Nicolas Collignon <tsointsoin@gmail.com>
  831. -0 string -----BEGIN\ CERTIFICATE----- PEM certificate
  832. -0 string -----BEGIN\ CERTIFICATE\ REQ PEM certificate request
  833. -0 string -----BEGIN\ RSA\ PRIVATE PEM RSA private key
  834. -0 string -----BEGIN\ DSA\ PRIVATE PEM DSA private key
  835. -0 string -----BEGIN\ EC\ PRIVATE PEM EC private key
  836. +0 string -----BEGIN\040CERTIFICATE----- PEM certificate
  837. +0 string -----BEGIN\040CERTIFICATE\040REQ PEM certificate request
  838. +0 string -----BEGIN\040RSA\040PRIVATE PEM RSA private key
  839. +0 string -----BEGIN\040DSA\040PRIVATE PEM DSA private key
  840. +0 string -----BEGIN\040EC\040PRIVATE PEM EC private key
  841. +0 string -----BEGIN\040ECDSA\040PRIVATE PEM ECDSA private key
  842. +
  843. +# From Luc Gommans
  844. +# OpenSSL enc file (recognized by a magic string preceding the password's salt)
  845. +0 string Salted__ openssl enc'd data with salted password
  846. +# Using the -a or -base64 option, OpenSSL will base64-encode the data.
  847. +0 string U2FsdGVkX19 openssl enc'd data with salted password, base64 encoded
  848. --- /dev/null
  849. +++ b/magic/Magdir/yara
  850. @@ -0,0 +1,17 @@
  851. +
  852. +
  853. +#------------------------------------------------------------------------------
  854. +# $File: map,v 1.4 2015/08/10 05:18:27 christos Exp $
  855. +# yara: file(1) magic for http://virustotal.github.io/yara/
  856. +#
  857. +
  858. +0 string YARA
  859. +>4 lelong >2047
  860. +>8 byte <20 YARA 3.x compiled rule set
  861. +# version
  862. +>>8 clear
  863. +>>8 byte 6 created with version 3.3.0
  864. +>>8 byte 8 created with version 3.4.0
  865. +>>8 byte 11 created with version 3.5.0
  866. +>>8 default x
  867. +>>>8 byte x development version 0x%02x
  868. --- a/magic/Makefile.am
  869. +++ b/magic/Makefile.am
  870. @@ -104,6 +104,7 @@
  871. $(MAGIC_FRAGMENT_DIR)/gnu \
  872. $(MAGIC_FRAGMENT_DIR)/gnumeric \
  873. $(MAGIC_FRAGMENT_DIR)/gpt \
  874. +$(MAGIC_FRAGMENT_DIR)/gpu \
  875. $(MAGIC_FRAGMENT_DIR)/grace \
  876. $(MAGIC_FRAGMENT_DIR)/graphviz \
  877. $(MAGIC_FRAGMENT_DIR)/gringotts \
  878. @@ -285,6 +286,7 @@
  879. $(MAGIC_FRAGMENT_DIR)/xilinx \
  880. $(MAGIC_FRAGMENT_DIR)/xo65 \
  881. $(MAGIC_FRAGMENT_DIR)/xwindows \
  882. +$(MAGIC_FRAGMENT_DIR)/yara \
  883. $(MAGIC_FRAGMENT_DIR)/zfs \
  884. $(MAGIC_FRAGMENT_DIR)/zilog \
  885. $(MAGIC_FRAGMENT_DIR)/zyxel
  886. --- a/src/apprentice.c
  887. +++ b/src/apprentice.c
  888. @@ -2291,7 +2291,7 @@
  889. return parse_extra(ms, me, line,
  890. CAST(off_t, offsetof(struct magic, ext)),
  891. - sizeof(m->ext), "EXTENSION", ",!+-/", 0);
  892. + sizeof(m->ext), "EXTENSION", ",!+-/@", 0);
  893. }
  894. /*
  895. --- a/src/cdf.c
  896. +++ b/src/cdf.c
  897. @@ -530,6 +530,9 @@
  898. scn->sst_dirlen = len;
  899. scn->sst_ss = ss;
  900. + if (sid == CDF_SECID_END_OF_CHAIN || len == 0)
  901. + return cdf_zero_stream(scn);
  902. +
  903. if (scn->sst_len == (size_t)-1)
  904. goto out;
  905. --- a/src/compress.c
  906. +++ b/src/compress.c
  907. @@ -62,7 +62,7 @@
  908. #if defined(HAVE_SYS_TIME_H)
  909. #include <sys/time.h>
  910. #endif
  911. -#if defined(HAVE_ZLIB_H)
  912. +#if defined(HAVE_ZLIB_H) && defined(ZLIBSUPPORT)
  913. #define BUILTIN_DECOMPRESS
  914. #include <zlib.h>
  915. #endif
  916. @@ -83,6 +83,7 @@
  917. /*
  918. * The following python code is not really used because ZLIBSUPPORT is only
  919. * defined if we have a built-in zlib, and the built-in zlib handles that.
  920. + * That is not true for android where we have zlib.h and not -lz.
  921. */
  922. static const char zlibcode[] =
  923. "import sys, zlib; sys.stdout.write(zlib.decompress(sys.stdin.read()))";
  924. --- a/src/der.c
  925. +++ b/src/der.c
  926. @@ -159,31 +159,49 @@
  927. return tag;
  928. }
  929. +/*
  930. + * Read the length of a DER tag from the input.
  931. + *
  932. + * `c` is the input, `p` is an output parameter that specifies how much of the
  933. + * input we consumed, and `l` is the maximum input length.
  934. + *
  935. + * Returns the length, or DER_BAD if the end of the input is reached or the
  936. + * length exceeds the remaining input.
  937. + */
  938. static uint32_t
  939. getlength(const uint8_t *c, size_t *p, size_t l)
  940. {
  941. uint8_t digits, i;
  942. size_t len;
  943. + int is_onebyte_result;
  944. if (*p >= l)
  945. return DER_BAD;
  946. - digits = c[(*p)++];
  947. + /*
  948. + * Digits can either be 0b0 followed by the result, or 0b1
  949. + * followed by the number of digits of the result. In either case,
  950. + * we verify that we can read so many bytes from the input.
  951. + */
  952. + is_onebyte_result = (c[*p] & 0x80) == 0;
  953. + digits = c[(*p)++] & 0x7f;
  954. + if (*p + digits >= l)
  955. + return DER_BAD;
  956. - if ((digits & 0x80) == 0)
  957. + if (is_onebyte_result)
  958. return digits;
  959. - digits &= 0x7f;
  960. + /*
  961. + * Decode len. We've already verified that we're allowed to read
  962. + * `digits` bytes.
  963. + */
  964. len = 0;
  965. -
  966. - if (*p + digits >= l)
  967. - return DER_BAD;
  968. -
  969. for (i = 0; i < digits; i++)
  970. len = (len << 8) | c[(*p)++];
  971. +
  972. if (*p + len >= l)
  973. return DER_BAD;
  974. - return len;
  975. + return len;
  976. }
  977. static const char *
  978. --- a/src/funcs.c
  979. +++ b/src/funcs.c
  980. @@ -76,7 +76,7 @@
  981. ms->o.buf = buf;
  982. return 0;
  983. out:
  984. - file_error(ms, errno, "vasprintf failed");
  985. + fprintf(stderr, "vasprintf failed (%s)", strerror(errno));
  986. return -1;
  987. }
  988. --- a/src/readelf.c
  989. +++ b/src/readelf.c
  990. @@ -1203,8 +1203,9 @@
  991. /* Read offset of name section to be able to read section names later */
  992. if (pread(fd, xsh_addr, xsh_sizeof, CAST(off_t, (off + size * strtab)))
  993. < (ssize_t)xsh_sizeof) {
  994. - file_badread(ms);
  995. - return -1;
  996. + if (file_printf(ms, ", missing section headers") == -1)
  997. + return -1;
  998. + return 0;
  999. }
  1000. name_off = xsh_offset;
  1001. --- a/src/softmagic.c
  1002. +++ b/src/softmagic.c
  1003. @@ -1260,7 +1260,8 @@
  1004. if (*dst == '\0') {
  1005. if (type == FILE_BESTRING16 ?
  1006. *(src - 1) != '\0' :
  1007. - *(src + 1) != '\0')
  1008. + ((src + 1 < esrc) &&
  1009. + *(src + 1) != '\0'))
  1010. *dst = ' ';
  1011. }
  1012. }
  1013. @@ -1887,7 +1888,7 @@
  1014. copy[--slen] = '\0';
  1015. search = copy;
  1016. } else {
  1017. - search = ms->search.s;
  1018. + search = CCAST(char *, "");
  1019. copy = NULL;
  1020. }
  1021. rc = file_regexec(&rx, (const char *)search,