Browse Source

Import upstream version 5.30

Christos Zoulas 2 years ago
parent
commit
5a0995994c

+ 25 - 1
ChangeLog

@@ -1,6 +1,30 @@
+2017-02-10  12:24  Christos Zoulas <christos@zoulas.com>
+
+	* release 5.30
+
+2017-02-07  23:27  Christos Zoulas <christos@zoulas.com>
+
+	* If we exceeded the offset in a search return no match
+	  (Christoph Biedl)
+	* Be more lenient on corrupt CDF files (Christoph Biedl)
+
+2017-02-04  16:46  Christos Zoulas <christos@zoulas.com>
+
+	* pacify ubsan sign extension (oss-fuzz/524)
+
+2017-02-01  12:42  Christos Zoulas <christos@zoulas.com>
+
+	* off by one in cdf parsing (PR/593)
+	* report debugging sections in elf (PR/591)
+
+2016-11-06  10:52  Christos Zoulas <christos@zoulas.com>
+
+	* Allow @@@ in extensions
+	* Add missing overflow check in der magic (Jonas Wagner)
+
 2016-10-25  10:40  Christos Zoulas <christos@zoulas.com>
 	
-	* release 5.28
+	* release 5.29
 
 2016-10-24  11:20  Christos Zoulas <christos@zoulas.com>
 

+ 10 - 10
configure

@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for file 5.29.
+# Generated by GNU Autoconf 2.69 for file 5.30.
 #
 # Report bugs to <christos@astron.com>.
 #
@@ -590,8 +590,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='file'
 PACKAGE_TARNAME='file'
-PACKAGE_VERSION='5.29'
-PACKAGE_STRING='file 5.29'
+PACKAGE_VERSION='5.30'
+PACKAGE_STRING='file 5.30'
 PACKAGE_BUGREPORT='christos@astron.com'
 PACKAGE_URL=''
 
@@ -1328,7 +1328,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures file 5.29 to adapt to many kinds of systems.
+\`configure' configures file 5.30 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1398,7 +1398,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of file 5.29:";;
+     short | recursive ) echo "Configuration of file 5.30:";;
    esac
   cat <<\_ACEOF
 
@@ -1509,7 +1509,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-file configure 5.29
+file configure 5.30
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2165,7 +2165,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by file $as_me 5.29, which was
+It was created by file $as_me 5.30, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -3031,7 +3031,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='file'
- VERSION='5.29'
+ VERSION='5.30'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -15075,7 +15075,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by file $as_me 5.29, which was
+This file was extended by file $as_me 5.30, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -15141,7 +15141,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-file config.status 5.29
+file config.status 5.30
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 

+ 1 - 1
configure.ac

@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-AC_INIT([file],[5.29],[christos@astron.com])
+AC_INIT([file],[5.30],[christos@astron.com])
 AM_INIT_AUTOMAKE([subdir-objects foreign])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 

+ 9 - 12
doc/file.man

@@ -1,4 +1,4 @@
-.\" $File: file.man,v 1.124 2016/10/19 20:52:45 christos Exp $
+.\" $File: file.man,v 1.125 2017/01/03 11:24:46 christos Exp $
 .Dd October 19, 2016
 .Dt FILE __CSECTION__
 .Os
@@ -238,8 +238,8 @@ or at least one filename argument must be present;
 to test the standard input, use
 .Sq -
 as a filename argument.
-Please note that 
-.Ar namefile 
+Please note that
+.Ar namefile
 is unwrapped and the enclosed filenames are processed when this option is
 encountered and before any further options processing is done.
 This allows one to process multiple lists of files with different command line
@@ -411,10 +411,10 @@ and
 .Fl h
 options.
 .Sh SEE ALSO
-.Xr magic __FSECTION__ ,
 .Xr hexdump 1 ,
 .Xr od 1 ,
 .Xr strings 1 ,
+.Xr magic __FSECTION__
 .Sh STANDARDS CONFORMANCE
 This program is believed to exceed the System V Interface Definition
 of FILE(CMD), as near as one can determine from the vague language
@@ -530,16 +530,15 @@ John Gilmore revised the code extensively, making it better than
 the first version.
 Geoff Collyer found several inadequacies
 and provided some magic file entries.
-Contributions by the
+Contributions of the
 .Sq \*[Am]
 operator by Rob McMahon, 
 .Aq cudcv@warwick.ac.uk ,
 1989.
 .Pp
-Guy Harris, 
+Guy Harris,
 .Aq guy@netapp.com ,
 made many changes from 1993 to the present.
-1989.
 .Pp
 Primary development and maintenance from 1990 to the present by
 Christos Zoulas
@@ -587,7 +586,6 @@ program, and are not covered by the above license.
 .Nm
 returns 0 on success, and non-zero on error.
 .Sh BUGS
-.Pp
 Please report bugs and send patches to the bug tracker at
 .Pa http://bugs.gw.com/
 or the mailing list at
@@ -596,7 +594,6 @@ or the mailing list at
 .Pa http://mx.gw.com/mailman/listinfo/file
 first to subscribe).
 .Sh TODO
-.Pp
 Fix output so that tests for MIME and APPLE flags are not needed all
 over the place, and actual output is only done in one place.
 This needs a design.
@@ -645,16 +642,16 @@ Fix
 .Dq name
 and
 .Dq use
-to check for consistency at compile time (duplicate 
+to check for consistency at compile time (duplicate
 .Dq name ,
 .Dq use
 pointing to undefined
 .Dq name
 ).
-Make 
+Make
 .Dq name
 /
-.Dq use 
+.Dq use
 more efficient by keeping a sorted list of names.
 Special-case ^ to flip endianness in the parser so that it does not
 have to be escaped, and document it.

+ 14 - 8
doc/magic.man

@@ -1,5 +1,5 @@
-.\" $File: magic.man,v 1.88 2016/07/27 09:42:49 rrt Exp $
-.Dd July 20, 2016
+.\" $File: magic.man,v 1.90 2017/02/08 21:52:03 christos Exp $
+.Dd February 8, 2017
 .Dt MAGIC __FSECTION__
 .Os
 .\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems.
@@ -7,7 +7,7 @@
 .Nm magic
 .Nd file command's magic pattern file
 .Sh DESCRIPTION
-This manual page documents the format of the magic file as
+This manual page documents the format of magic files as
 used by the
 .Xr file __CSECTION__
 command, version __VERSION__.
@@ -17,13 +17,19 @@ command identifies the type of a file using,
 among other tests,
 a test for whether the file contains certain
 .Dq "magic patterns" .
-The file
-.Pa __MAGIC__
-specifies what patterns are to be tested for, what message or
+The database of these
+.Dq "magic patterns"
+is usually located in a binary file in
+.Pa __MAGIC__.mgc
+or a directory of source text magic pattern fragment files in
+.Pa __MAGIC__ .
+The database specifies what patterns are to be tested for, what message or
 MIME type to print if a particular pattern is found,
 and additional information to extract from the file.
 .Pp
-Each line of the file specifies a test to be performed.
+The format of the source fragment files that are used to build this database
+is as follows:
+Each line of a fragment file specifies a test to be performed.
 A test compares the data starting at a particular offset
 in the file with a byte value, a string or a numeric value.
 If the test succeeds, a message is printed.
@@ -651,7 +657,7 @@ start of the main indirect offset.
 \*[Gt]\*[Gt]\*[Gt]\*[Gt](\*[Am]0xe.l+(-4)) string       PK\e3\e4 \eb, ZIP self-extracting archive
 .Ed
 .Pp
-If you have a list of known avalues at a particular continuation level,
+If you have a list of known values at a particular continuation level,
 and you want to provide a switch-like default case:
 .Bd -literal -offset indent
 # clear that continuation level match

+ 7 - 5
magic/Magdir/animation

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: animation,v 1.58 2016/07/03 14:13:11 christos Exp $
+# $File: animation,v 1.59 2017/01/21 16:07:14 christos Exp $
 # animation:  file(1) magic for animation/movie formats
 #
 # animation formats
@@ -855,10 +855,12 @@
 
 # X3D (Extensible 3D) [http://www.web3d.org/specifications/x3d-3.0.dtd]
 # From Michel Briand <michelbriand@free.fr>
-0	string/t		\<?xml\ version="
-!:strength +1
->20	search/1000/cw  \<!DOCTYPE\ X3D		X3D (Extensible 3D) model xml text
-!:mime model/x3d
+# mimetype from https://www.iana.org/assignments/media-types/model/x3d+xml
+# Example http://www.web3d.org/x3d/content/examples/Basic/course/CreateX3DFromStringRandomSpheres.x3d
+0	string/w	\<?xml\ version=
+!:strength + 5
+>20	search/1000/w	\<!DOCTYPE\ X3D		X3D (Extensible 3D) model xml text
+!:mime model/x3d+xml
 
 #---------------------------------------------------------------------------
 # HVQM4: compressed movie format designed by Hudson for Nintendo GameCube

+ 11 - 1
magic/Magdir/archive

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: archive,v 1.103 2016/05/05 17:07:40 christos Exp $
+# $File: archive,v 1.104 2017/02/10 14:03:22 christos Exp $
 # archive:  file(1) magic for archive formats (see also "msdos" for self-
 #           extracting compressed archives)
 #
@@ -908,7 +908,17 @@
 >>>4	byte		0x0a		\b, at least v1.0 to extract
 >>>4	byte		0x0b		\b, at least v1.1 to extract
 >>>4	byte		0x14		\b, at least v2.0 to extract
+>>>4	byte		0x15		\b, at least v2.1 to extract
+>>>4	byte		0x19		\b, at least v2.5 to extract
+>>>4	byte		0x1b		\b, at least v2.7 to extract
 >>>4	byte		0x2d		\b, at least v4.5 to extract
+>>>4	byte		0x2e		\b, at least v4.6 to extract
+>>>4	byte		0x32		\b, at least v5.0 to extract
+>>>4	byte		0x33		\b, at least v5.1 to extract
+>>>4	byte		0x34		\b, at least v5.2 to extract
+>>>4	byte		0x3d		\b, at least v6.1 to extract
+>>>4	byte		0x3e		\b, at least v6.2 to extract
+>>>4	byte		0x3f		\b, at least v6.3 to extract
 >>>0x161	string		WINZIP		\b, WinZIP self-extracting
 
 # StarView Metafile

+ 3 - 1
magic/Magdir/audio

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: audio,v 1.75 2016/02/08 17:30:11 christos Exp $
+# $File: audio,v 1.76 2016/11/02 23:06:32 christos Exp $
 # audio:  file(1) magic for sound formats (see also "iff")
 #
 # Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com),
@@ -469,6 +469,8 @@
 >>20	byte&0xe		0xc		\b, 7 channels
 >>20	byte&0xe		0xe		\b, 8 channels
 # some common sample rates
+>>17	belong&0xfffff0		0x2ee000	\b, 192 kHz
+>>17	belong&0xfffff0		0x158880	\b, 88.2 kHz
 >>17	belong&0xfffff0		0x0ac440	\b, 44.1 kHz
 >>17	belong&0xfffff0		0x0bb800	\b, 48 kHz
 >>17	belong&0xfffff0		0x07d000	\b, 32 kHz

+ 98 - 10
magic/Magdir/console

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: console,v 1.26 2016/06/12 15:20:37 christos Exp $
+# $File: console,v 1.29 2017/02/08 21:53:06 christos Exp $
 # Console game magic
 # Toby Deshane <hac@shoelace.digivill.net>
 
@@ -9,17 +9,19 @@
 # References:
 # - http://wiki.nesdev.com/w/index.php/INES
 # - http://wiki.nesdev.com/w/index.php/NES_2.0
-0	string		NES\x1A		iNES ROM image
+
+# Common header for iNES, NES 2.0, and Wii U iNES.
+0	name		nes-rom-image-ines
 >7	byte&0x0C	=0x8		(NES 2.0)
 >4	byte		x		\b: %ux16k PRG
->5	byte		x		\b, %ux16k CHR
+>5	byte		x		\b, %ux8k CHR
 >6	byte&0x08	=0x8		[4-Scr]
 >6	byte&0x09	=0x0		[H-mirror]
 >6	byte&0x09	=0x1		[V-mirror]
 >6	byte&0x02	=0x2		[SRAM]
 >6	byte&0x04	=0x4		[Trainer]
 >7	byte&0x03	=0x2		[PC10]
->7	byte&0x03	=0x1		[VS
+>7	byte&0x03	=0x1		[VS]
 >>7	byte&0x0C	=0x8
 # NES 2.0: VS PPU
 >>>13	byte&0x0F	=0x0		\b, RP2C03B
@@ -43,17 +45,24 @@
 >>12	byte&0x03	=0x1		[PAL]
 >>12	byte&0x02	=0x2		[NTSC+PAL]
 
+# Standard iNES ROM header.
+0	string		NES\x1A		NES ROM image (iNES)
+>0	use		nes-rom-image-ines
+
+# Wii U Virtual Console iNES ROM header.
+0	belong		0x4E455300	NES ROM image (Wii U Virtual Console)
+>0	use		nes-rom-image-ines
+
 #------------------------------------------------------------------------------
 # unif: file(1) magic for UNIF-format Nintendo Entertainment System ROM images
 # Reference: http://wiki.nesdev.com/w/index.php/UNIF
 # From: David Korth <gerbilsoft@gerbilsoft.com>
-# TODO commit on 2016/03/21
 #
 # NOTE: The UNIF format uses chunks instead of a fixed header,
 # so most of the data isn't easily parseable.
 #
 0	string	UNIF
->4	lelong	<16	UNIF v%d format NES ROM image
+>4	lelong	<16	NES ROM image (UNIF v%d format)
 
 #------------------------------------------------------------------------------
 # fds: file(1) magic for Famciom Disk System disk images
@@ -63,25 +72,40 @@
 
 # Disk info block. (block 1)
 0	name	nintendo-fds-disk-info-block
->1	string	*NINTENDO-HVC*	Famicom Disk System disk image:
 >23	byte	!1		FMC-
 >23	byte	1		FSC-
 >16	string	x		\b%.3s
->15	byte	x		\b, mfr 0x%02X
+>15	byte	x		\b, mfr %02X
 >20	byte	x		(Rev.%02u)
 
 # Headered version.
 0	string	FDS\x1A
->0x11	string	*NINTENDO-HVC*
+>0x11	string	*NINTENDO-HVC*	Famicom Disk System disk image:
 >>0x10	use	nintendo-fds-disk-info-block
 >4	byte	1	(%u side)
 >4	byte	!1	(%u sides)
 
 # Unheadered version.
-1	string	*NINTENDO-HVC*
+1	string	*NINTENDO-HVC*	Famicom Disk System disk image:
 >0	use	nintendo-fds-disk-info-block
 
 #------------------------------------------------------------------------------
+# tnes: file(1) magic for TNES-format Nintendo Entertainment System ROM images
+# Used by Nintendo 3DS NES Virtual Console games.
+# From: David Korth <gerbilsoft@gerbilsoft.com>
+#
+0		string	TNES	NES ROM image (Nintendo 3DS Virtual Console)
+>4		byte	100	\b: FDS,
+>>0x2010	use	nintendo-fds-disk-info-block
+>4		byte	!100	\b: TNES mapper %u
+>>5	byte		x		\b, %ux8k PRG
+>>6	byte		x		\b, %ux8k CHR
+>>7	byte&0x08	=1		[WRAM]
+>>8	byte&0x09	=1		[H-mirror]
+>>8	byte&0x09	=2		[V-mirror]
+>>8	byte&0x02	=3		[VRAM]
+
+#------------------------------------------------------------------------------
 # gameboy: file(1) magic for the Nintendo (Color) Gameboy raw ROM format
 # Reference: http://gbdev.gg8.se/wiki/articles/The_Cartridge_Header
 #
@@ -491,6 +515,10 @@
 >3	byte		x	version %d,
 >4	byte		x	%d tracks
 
+# IPS Patch Files from: From: Thomas Klausner <tk@giga.or.at>
+# see http://zerosoft.zophar.net/ips.php
+0	string	PATCH			IPS patch file
+
 # Playstations Patch Files from: From: Thomas Klausner <tk@giga.or.at>
 0	string	PPF30			Playstation Patch File version 3.0
 >5	byte	0			\b, PPF 1.0 patch
@@ -617,6 +645,52 @@
 >0x218	belong	0x5D1C9EA3	Nintendo Wii disc image (WBFS format):
 >>0x200	use	nintendo-gcn-disc-common
 
+# Type: Nintendo GameCube/Wii disc image (CISO format)
+# NOTE: This is NOT the same as Compact ISO or PSP CISO,
+# though it has the same magic number.
+0		string	CISO
+# Other fields are used to determine what type of CISO this is:
+# - 0x04 == 0x00200000: GameCube/Wii CISO (block_size)
+# - 0x10 == 0x00000800: PSP CISO (ISO-9660 sector size)
+# - None of the above: Compact ISO.
+>4		lelong	0x200000
+>>8		byte	1
+>>>0x801C	belong	0xC2339F3D	Nintendo GameCube disc image (CISO format):
+>>>>0x8000	use	nintendo-gcn-disc-common
+>>>0x8018	belong	0x5D1C9EA3	Nintendo Wii disc image (CISO format):
+>>>>0x8000	use	nintendo-gcn-disc-common
+
+# Type: Nintendo GameCube/Wii disc image (GCZ format)
+# Due to zlib compression, we can't get the actual disc information.
+0	lelong	0xB10BC001
+>4	lelong	0		Nintendo GameCube disc image (GCZ format)
+>4	lelong	1		Nintendo Wii disc image (GCZ format)
+>4	lelong	>1		Nintendo GameCube/Wii disc image (GCZ format)
+
+# Type: Nintendo GameCube/Wii disc image (WDF format)
+0		string	WII\001DISC
+>8		belong	1
+# WDFv1
+>>0x54		belong	0xC2339F3D	Nintendo GameCube disc image (WDFv1 format):
+>>>0x38		use	nintendo-gcn-disc-common
+>>0x58		belong	0x5D1C9EA3	Nintendo Wii disc image (WDFv1 format):
+>>>0x38		use	nintendo-gcn-disc-common
+>8		belong	2
+# WDFv2
+>>(12.L+0x1C)	belong	0xC2339F3D	Nintendo GameCube disc image (WDFv2 format):
+>>>(12.L)	use	nintendo-gcn-disc-common
+>>(12.L+0x18)	belong	0x5D1C9EA3	Nintendo Wii disc image (WDFv2 format):
+>>>(12.L)	use	nintendo-gcn-disc-common
+
+# Type: Nintendo GameCube/Wii disc image (WIA format)
+0	string	WIA\001	Nintendo
+>0x48	belong	0	GameCube/Wii
+>0x48	belong	1	GameCube
+>0x48	belong	2	Wii
+>0x48	belong	>2	GameCube/Wii
+>0x48	belong	x	disc image (WIA format):
+>>0x58	use	nintendo-gcn-disc-common
+
 #------------------------------------------------------------------------------
 # Nintendo 3DS file formats.
 #
@@ -750,3 +824,17 @@
 #
 0	string	g\ GCE	Vectrex ROM image
 >0x11	string	>\0	\b: "%.16s"
+
+#------------------------------------------------------------------------------
+# amiibo: file(1) magic for Nintendo amiibo NFC dumps.
+# From: David Korth <gerbilsoft@gerbilsoft.com>
+# Reference: https://www.3dbrew.org/wiki/Amiibo
+0x00		byte	0x04
+>0x0A		beshort	0x0FE0
+>>0x0C		belong	0xF110FFEE
+>>>0x208	beshort	0x0100
+>>>>0x020A	byte	0x0F
+>>>>>0x020C	bequad	0x000000045F000000
+>>>>>>0x5B	byte	0x02
+>>>>>>>0x54	belong	x	Nintendo amiibo NFC dump - amiibo ID: %08X-
+>>>>>>>0x58	belong	x	\b%08X

+ 21 - 2
magic/Magdir/filesystems

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: filesystems,v 1.114 2016/09/05 08:34:25 christos Exp $
+# $File: filesystems,v 1.116 2017/01/03 11:25:37 christos Exp $
 # filesystems:  file(1) magic for different filesystems
 #
 0	name	partid  
@@ -1949,7 +1949,19 @@
 >0	use cdrom
 
 # .cso files
-0    string    CISO	Compressed ISO CD image
+# Reference: http://pismotec.com/ciso/ciso.h
+# NOTE: There are two other formats with the same magic but
+# completely incompatible specifications:
+# - GameCube/Wii CISO: https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/DiscIO/CISOBlob.h
+# - PSP CISO: https://github.com/jamie/ciso/blob/master/ciso.h
+0    string    CISO
+# Other fields are used to determine what type of CISO this is:
+# - 0x04 == 0x00200000: GameCube/Wii CISO (block_size)
+# - 0x10 == 0x00000800: PSP CISO (ISO-9660 sector size)
+# - None of the above: Compact ISO.
+>4	lelong	!0
+>>4	lelong	!0x200000
+>>>0x10	lelong	!0x800		Compressed ISO CD image
 
 # cramfs filesystem - russell@coker.com.au
 0       lelong    0x28cd3d45      Linux Compressed ROM File System data, little endian
@@ -2041,6 +2053,13 @@
 >29	byte	16		\bBlackfin,
 >29	byte	17		\bAVR32,
 >29	byte	18		\bSTMicroelectronics ST200,
+>29	byte	19		\bSandbox architecture,
+>29	byte	20		\bANDES Technology NDS32,
+>29	byte	21		\bOpenRISC 1000,
+>29	byte	22		\bARM 64-bit,
+>29	byte	23		\bDesignWare ARC,
+>29	byte	24		\bx86_64,
+>29	byte	25		\bXtensa,
 >30	byte	0		Invalid Image
 >30	byte	1		Standalone Program
 >30	byte	2		OS Kernel Image

+ 37 - 15
magic/Magdir/flash

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: flash,v 1.11 2014/05/02 00:26:49 christos Exp $
+# $File: flash,v 1.12 2017/02/07 23:25:26 christos Exp $
 # flash:	file(1) magic for Macromedia Flash file format
 #
 # See
@@ -11,22 +11,44 @@
 #
 
 0   name        swf-details
->0	string		F		Macromedia Flash data
-!:mime	application/x-shockwave-flash
->0	string		C		Macromedia Flash data (compressed)
-!:mime	application/x-shockwave-flash
->0	string		Z		Macromedia Flash data (lzma compressed)
-!:mime	application/x-shockwave-flash
->3   byte        x      \b, version %d
 
-1   string      WS
->4  lelong      !0
->>3 byte        255 Suspicious
->>>0    use     swf-details
+>0      string      F
+>>8     byte&0xfd   0x08    Macromedia Flash data
+!:mime  application/x-shockwave-flash
+>>>3    byte        x       \b, version %d
+>>8     byte&0xfe   0x10    Macromedia Flash data
+!:mime  application/x-shockwave-flash
+>>>3    byte        x       \b, version %d
+>>8     byte        0x18    Macromedia Flash data
+!:mime  application/x-shockwave-flash
+>>>3    byte        x       \b, version %d
+>>8     beshort&ff87 0x2000 Macromedia Flash data
+!:mime  application/x-shockwave-flash
+>>>3    byte        x       \b, version %d
+>>8     beshort&ffe0 0x3000 Macromedia Flash data
+!:mime  application/x-shockwave-flash
+>>>3    byte        x       \b, version %d
+>>8     byte&0x7    0
+>>>8    ubyte       >0x2f
+>>>>9   ubyte       <0x20   Macromedia Flash data
+!:mime  application/x-shockwave-flash
+>>>>>3  byte        x       \b, version %d
+
+>0      string      C
+>>8     byte        0x78    Macromedia Flash data (compressed)
+!:mime  application/x-shockwave-flash
+>>>3    byte        x       \b, version %d
+
+>0      string      Z
+>>8     byte        0x5d    Macromedia Flash data (lzma compressed)
+!:mime  application/x-shockwave-flash
+>>>3    byte        x      \b, version %d
 
->>3 ubyte       <32
->>>3 ubyte      !0
->>>>0   use     swf-details
+
+1   string      WS
+>4  ulelong     >14
+>>3 ubyte       !0
+>>>0   use      swf-details
 
 # From: Cal Peake <cp@absolutedigital.net>
 0	string		FLV\x01		Macromedia Flash Video

+ 6 - 4
magic/Magdir/fonts

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: fonts,v 1.33 2016/09/14 01:26:26 christos Exp $
+# $File: fonts,v 1.34 2016/12/01 15:30:33 christos Exp $
 # fonts:  file(1) magic for font data
 #
 0	search/1	FONT		ASCII vfont text
@@ -100,9 +100,11 @@
 
 # X11 fonts, from Daniel Quinlan (quinlan@yggdrasil.com)
 # PCF must come before SGI additions ("MIPSEL MIPS-II COFF" collides)
-0	string		\001fcp			X11 Portable Compiled Font data
->12	byte		0x02			\b, LSB first
->12	byte		0x0a			\b, MSB first
+0	string		\001fcp			X11 Portable Compiled Font data,
+>12	lelong		^0x08			bit: LSB,
+>12	lelong		&0x08			bit: MSB,
+>12	lelong		^0x04			byte: LSB first
+>12	lelong		&0x04			byte: MSB first
 0	string		D1.0\015		X11 Speedo font data
 
 #------------------------------------------------------------------------------

+ 16 - 0
magic/Magdir/gpu

@@ -0,0 +1,16 @@
+
+#------------------------------------------------------------------------------
+# $File: gpu,v 1.1 2016/11/09 18:20:53 christos Exp $
+# gpu: file(1) magic for GPU input files
+
+# Standard Portable Intermediate Representation (SPIR)
+# Documentation: https://www.khronos.org/spir
+# Typical file extension: .spv
+
+0	belong	0x07230203	Khronos SPIR-V binary, big-endian
+>4	belong	x		\b, version 0x%08x
+>8	belong	x		\b, generator 0x%08x
+
+0	lelong	0x07230203      Khronos SPIR-V binary, little-endian
+>4	lelong	x		\b, version 0x%08x
+>8	lelong	x		\b, generator 0x%08x

+ 175 - 12
magic/Magdir/icc

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: icc,v 1.1 2013/01/08 01:43:18 christos Exp $
+# $File: icc,v 1.2 2016/12/02 19:32:15 christos Exp $
 # icc:  file(1) magic for International Color Consortium file formats
 
 #
@@ -11,41 +11,204 @@
 #	http://www.color.org/specification/ICC1v43_2010-12.pdf
 #
 # for Specification ICC.1:2010 (Profile version 4.3.0.0).
+# URL: http://fileformats.archiveteam.org/wiki/ICC_profile
+# Reference: http://www.color.org/iccmax/ICC.2-2016-7.pdf
+# Update: Joerg Jenderek
 #
 # Bytes 36 to 39 contain a generic profile file signature of "acsp";
 # bytes 40 to 43 "may be used to identify the primary platform/operating
 # system framework for which the profile was created".
 #
-# There are other fields that might be worth dumping as well.
-#
+#	check and display ICC/ICM color profile
+0	name	color-profile
+>36	string		acsp		
+# skip ASCII like Cognacspirit.txt by month <= 12
+>>26	ubeshort	<13		
+# platform/operating system. Only 5 mentioned
 
+#
 # This appears to be what's used for Apple ColorSync profiles.
 # Instead of adding that, Apple just changed the generic "acsp" entry
 # to be for "ColorSync ICC Color Profile" rather than "Kodak Color
 # Management System, ICC Profile".
 # Yes, it's "APPL", not "AAPL"; see the spec.
-36	string		acspAPPL	ColorSync ICC Profile
-!:mime	application/vnd.iccprofile
+>>>40	string		APPL		ColorSync
 
 # Microsoft ICM color profile
-36	string		acspMSFT	Microsoft ICM Color Profile
-!:mime	application/vnd.iccprofile
+>>>40	string		MSFT		Microsoft
 
 # Yes, that's a blank after "SGI".
-36	string		acspSGI\ 	SGI ICC Profile
-!:mime	application/vnd.iccprofile
+>>>40	string		SGI\ 		SGI
 
 # XXX - is this what's used for the Sun KCMS or not?  The standard file
 # uses just "acsp" for that, but Apple's file uses it for "ColorSync",
 # and there *is* an identified "primary platform" value of SUNW.
-36	string		acspSUNW	Sun KCMS ICC Profile
+>>>40	string		SUNW		Sun KCMS
+
+# 5th platform
+>>>40	string		TGNT		Taligent
+
+# remaing "l" "e" of "color profile" printed later to avoid error
+>>>40	string		x 		color profi
+#>>>40	string		x		(%.4s)
 !:mime	application/vnd.iccprofile
+# for "ICM" extension only versions 2.x and for Kodak "CC" 2.0 is found
+>>>8	ubyte		=2		
+# do not use empty message text to a avoid error like
+# icc, 82: Warning: Current entry does not yet have a description for adding a EXTENSION type
+# file.exe: could not find any valid magic files!
+>>>>9	ubyte		!0		\ble
+!:ext	icc/icm
+# minor version
+>>>>9	ubyte		=0		\bl
+# Kodak colour management system
+>>>>>4	string		=KCMS		\be
+!:ext	icc/icm/cc
+>>>>>4	string		!KCMS		\be
+!:ext	icc/icm
+>>>8	ubyte		!2		\ble
+!:ext	icc
+# Profile version major.4bit-minor.sub1.sub2 like 4.3.0.0 (04300000h)
+>>>8	ubyte		x		%u
+>>>9	ubyte/16	x		\b.%u
+# reserved and shall be null but 205.205 in umx1220u.icm
+>>>10	ubyte		>0		\b.%u
+>>>>11	ubyte		>0		\b.%u
+# preferred colour management module like appl CCMS KCMS Lino UCCM "Win " "FF  "
+# skip space like in brmsl08f.icm and null like in brmsl09f.icm, brmsl07f.icm
+>>>4	string		>\ 		\b, type %.2s
+>>>>6	string		>\  		\b%.1s
+>>>>>7	string		>\  		\b%.1s
+# colour space "XYZ " "Lab " "RGB " CMYK GRAY ...
+>>>16	string		x		\b, %.3s
+>>>19	string		>\  		\b%.1s
+# Profile Connection Space (PCS) field usually "XYZ " or "Lab " but sometimes
+# null or CMYK like in ISOcoated_v2_to_PSOcoated_v3_DeviceLink.icc
+>>>20	string		>\0		\b/%.3s
+>>>>23	string		>\ 		\b%.1s
+# eleven device classes
+>>>12	string		x		\b-%.4s device
+# skip 00001964h in hpf69000.icc or 0h in XRDC50Q.ICM or " ROT" in brmsl05f.icm
+>>>52	string		>\ 		
+# skip "none" model like in "Trinitron Compatible 9300K G2.2.icm"
+>>>>52	ubelong		!0x6e6f6e65	
+# device manufacturer field like "HP  " "IBM " EPSO
+>>>>>48	string		x		\b, %.2s
+>>>>>50	string		>\  		\b%.1s
+>>>>>51	string		>\  		\b%.1s
+# model like "ADI " "A265" and skip 20000404h in IS330.icm for RICOH RUSSIAN-SC
+>>>>>52	string		>\ \  		\b/%.3s
+>>>>>>55 string		>\  		\b%.1s
+>>>>>52	string		x		model
+# creator (often same as manufacture) like HP SONY XROX or null like in A925A.icm
+>>>80	string		>\0		by %.2s
+>>>>82	string		>\  		\b%.1s
+>>>>>83	string		>\  		\b%.1s
+# profile size
+>>>0	ubelong		x		\b, %u bytes
+# skip invalid date 0 like in linearSRGB.icc
+>>>24	ubequad		!0		
+# datetime dd-mm-yyyy hh:mm:ss
+>>>>28	ubeshort	x		\b, %u
+# month <= 12
+>>>>26	ubeshort	x		\b-%u
+# year
+>>>>24	ubeshort	x		\b-%u
+# do not display midnight time like in CNHP8308.ICC
+>>>>30	ubequad&0xFFffFFffFFff0000	!0
+# hour <= 24
+>>>>>30	ubeshort	x		%u
+# minutes <= 59
+>>>>>32	ubeshort	x		\b:%.2u
+# seconds <= 59
+>>>>>34	ubeshort	x		\b:%.2u
+# vendor specific flags like 2 in HPCLJ5.ICM
+>>>44	ubeshort	>0		\b, 0x%x vendor flags
+# profile flags bits 0-2 of least 16 used by ICC
+#>>>44	ubelong		>0		\b, 0x%x flags
+# icEmbeddedProfileTrue
+>>>44	ubelong		&1		\b, embedded
+# icEmbeddedProfileFalse
+#>>>44	ubelong		^1		\b, not embedded
+# icUseWithEmbeddedDataOnly
+>>>44	ubelong		&2		\b, dependently
+# icUseAnywhere
+#>>>44	ubelong		^2		\b, independently
+>>>44	ubelong		&4		\b, MCS
+#>>>44	ubelong		^4		\b, no MCS
+# vendor specific device attributes 1~srgb.icc
+# E000D00h~CNB7QEDA.ICM C000A00h~CNB5FCAA.ICM 01040401h~CNB25PE3.ICM
+>>>56	ubelong		>0		\b, 0x%x vendor attribute
+# ICC device attributes bits 0-7 used
+#>>>60	ubelong		x		\b, 0x%x attribute
+# http://www.color.org/icc34.h
+>>>60	ubelong		&0x01		\b, transparent
+#>>>60	ubelong		^0x01		\b, reflective
+>>>60	ubelong		&0x02		\b, matte
+#>>>60	ubelong		^0x02		\b, glossy
+>>>60	ubelong		&0x04		\b, negative
+#>>>60	ubelong		^0x04		\b, positive
+>>>60	ubelong		&0x08		\b, black&white
+#>>>60	ubelong		^0x08		\b, colour
+>>>60	ubelong		&0x10		\b, non-paper
+#>>>60	ubelong		^0x10		\b, paper
+>>>60	ubelong		&0x20		\b, non-textured
+#>>>60	ubelong		^0x20		\b, textured
+>>>60	ubelong		&0x40		\b, non-isotropic
+#>>>60	ubelong		^0x40		\b, isotropic
+>>>60	ubelong		&0x80		\b, self-luminous
+#>>>60	ubelong		^0x80		\b, non-self-luminous
+# rendering intent 0-3 but 7AEA5027h in EE051__1.ICM 6CB1BCh in EE061__1.ICM
+>>>64	ubelong		>3		\b, 0x%x rendering intent
+#>>>64	ubelong		=0		\b, perceptual
+>>>64	ubelong		=1		\b, relative colorimetric
+>>>64	ubelong		=2		\b, saturation
+>>>64	ubelong		=3		\b, absolute colorimetric
+# PCS illuminant (3*s15Fixed16Numbers) often 0000f6d6 00010000 0000d32d
+>>>71	ubequad		!0xd6000100000000d3	\b, PCS
+# usually X~0.9642*65536=63189.8112~63190=F6D5h ; but also found
+# often F6D6 in gt5000r.icm, F6B8 in kodakce.icm, F6CA in RSWOP.icm
+>>>>68	ubelong			!0x0000f6d5	X=0x%x
+# usually Y=1.0~00010000h but Y=0 in brmsl07f.icm
+>>>>72	ubelong			!0x00010000	Y=0x%x
+# usually Z~0.8249*65536=54060.6464~54061=D32Dh ; but also found
+# D2F7 in hp1200c.icm, often D32C in A925A.icm, D309 in RSWOP.icm , D2F8 in kodak_dc.icm
+>>>>76	ubelong			!0x0000d32d	Z=0x%x
+# Profile ID. MD5 fingerprinting method as defined in Internet RFC 1321.
+>>>84	ubequad		>0		\b, 0x%llx MD5
+# reserved in older versions should be zero but also found CDCDCDCDCDCDCDCD
+#>>100	ubequad		x		\b 0x%llx reserved
+# tag table
+# 6 <= tags count <= 43
+#>>>128	ubelong		>43		\b, %u tags
+>>>128	ubelong		x		
+# shall contain the profileDescriptionTag "desc" , copyrightTag "cprt"
+# search range = tags count * 12 -8=< maximal tag count * 12 -8= 43 * 12 -8= 508
+>>>>132	search/508	cprt		
+# but no copyright tag in linearSRGB.icc
+# beneath /System/Library/Frameworks/WebKit.framework/
+# Versions/A/Frameworks/WebCore.framework/Versions/A/Resources
+>>>>132	default		x		\b, no copyright tag
+# 1st tag
+#>>>132	string		x		\b, 1st tag %.4s
+#>>>136	ubelong		x		0x%x offset
+#>>>140	ubelong		x		0x%x len
+# 2nd tag,...
+# look also for profileDescriptionTag "desc"
+>>>132	search/508	desc		
+# look further for TextDescriptionType "desc" signature
+>>>>(&0.L)	string		=desc	
+>>>>>&4		pstring/l	x	"%s"
+# look alternative for multiLocalizedUnicodeType "mluc" signature like in VideoPAL.icc
+>>>>(&0.L)	string		=mluc	
+>>>>>&(&8.L)	ubequad		x		
+>>>>>>&4	bestring16	x	'%s'
 
 # Any other profile.
 # XXX - should we use "acsp\0\0\0\0" for "no primary platform" profiles,
 # and use "acsp" for everything else and dump the "primary platform"
 # string in those cases?
-36	string		acsp		ICC Profile
-!:mime	application/vnd.iccprofile
+36	string		acsp		
+>0	use		color-profile
 
 

+ 16 - 2
magic/Magdir/images

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: images,v 1.117 2016/07/05 19:12:21 christos Exp $
+# $File: images,v 1.121 2016/12/01 16:20:13 christos Exp $
 # images:  file(1) magic for image formats (see also "iff", and "c-lang" for
 # XPM bitmaps)
 #
@@ -41,7 +41,11 @@
 >>>>>>3	uleshort		0	
 >>>>>>>0	use		tga-image
 # Color Map
->>>>>1	ubyte			>0	
+>>>>>1	belong&0xfff7ffff	0x01010000
+>>>>>>0		use		tga-image
+>>>>>1	belong&0xfff7ffff	0x00020000
+>>>>>>0		use		tga-image
+>>>>>1	belong&0xfff7ffff	0x00030000
 >>>>>>0		use		tga-image
 #	display tga bitmap image information
 0	name				tga-image
@@ -418,6 +422,7 @@
 #
 0	string		\x89PNG\x0d\x0a\x1a\x0a		PNG image data
 !:mime	image/png
+!:strength +10
 >16	belong		x		\b, %d x
 >20	belong		x		%d,
 >24	byte		x		%d-bit
@@ -1451,3 +1456,12 @@
 >0x10	string	GVRT	Sega GVR image:
 >>0x10	use	sega-gvr-image-header
 >>0x08	belong	x	\b, global index = %u
+
+# Light Field Picture
+# Documentation: http://optics.miloush.net/lytro/TheFileFormat.aspx
+# Typical file extensions: .lfp .lfr .lfx
+
+0	belong	0x894C4650
+>4	belong	0x0D0A1A0A
+>12	belong	0x00000000	Lytro Light Field Picture
+>8	belong	x		\b, version %d

+ 13 - 5
magic/Magdir/make

@@ -1,7 +1,8 @@
 #------------------------------------------------------------------------------
-# $File: make,v 1.2 2015/08/25 07:34:06 christos Exp $
+# $File: make,v 1.3 2016/12/10 14:21:29 christos Exp $
 # make:  file(1) magic for makefiles
 #
+# URL: https://en.wikipedia.org/wiki/Make_(software)
 0	regex/100l	\^CFLAGS	makefile script text
 !:mime	text/x-makefile
 0	regex/100l	\^VPATH		makefile script text
@@ -10,12 +11,19 @@
 !:mime	text/x-makefile
 0	regex/100l	\^all:		makefile script text
 !:mime	text/x-makefile
-0	regex/100l	\^\.PRECIOUS	makefile script text
+0	regex/100l	\^\\.PRECIOUS	makefile script text
 !:mime	text/x-makefile
-0	regex/100l	\^\.BEGIN	BSD makefile script text
+# Update: Joerg Jenderek
+# Reference: https://www.freebsd.org/cgi/man.cgi?make(1)
+# exclude grub-core\lib\libgcrypt\mpi\Makefile.am with "#BEGIN_ASM_LIST"
+# by additional escaping point character
+0	regex/100l	\^\\.BEGIN	BSD makefile script text with "%s"
 !:mime	text/x-makefile
-0	regex/100l	\^\.include	BSD makefile script text
+!:ext	/mk
+# exclude MS Windows help file CoNtenT with ":include FOOBAR.CNT"
+# and NSIS script with "!include" by additional escaping point character
+0	regex/100l	\^\\.include	BSD makefile script text with "%s"
 !:mime	text/x-makefile
-
+!:ext	/mk
 0	regex/100l	\^SUBDIRS	automake makefile script text
 !:mime	text/x-makefile

+ 54 - 3
magic/Magdir/msdos

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: msdos,v 1.111 2016/09/14 01:26:26 christos Exp $
+# $File: msdos,v 1.115 2017/01/18 16:24:56 christos Exp $
 # msdos:  file(1) magic for MS-DOS files
 #
 
@@ -565,10 +565,23 @@
 0	string/b	PO^Q`				Microsoft Word 6.0 Document
 !:mime	application/msword
 #
-0	string/b	\376\067\0\043			Microsoft Office Document
+4   long        0
+>0  belong      0xfe320000      Microsoft Word for Macintosh 1.0
 !:mime	application/msword
-0	string/b	\333\245-\0\0\0			Microsoft Office Document
+!:ext   mcw
+>0  belong      0xfe340000      Microsoft Word for Macintosh 3.0
 !:mime	application/msword
+!:ext   mcw
+>0  belong      0xfe37001c      Microsoft Word for Macintosh 4.0
+!:mime	application/msword
+!:ext   mcw
+>0  belong      0xfe370023      Microsoft Word for Macintosh 5.0
+!:mime	application/msword
+!:ext   mcw
+
+0	string/b	\333\245-\0\0\0			Microsoft Word 2.0 Document
+!:mime	application/msword
+!:ext   doc
 512	string/b	\354\245\301			Microsoft Word Document
 !:mime	application/msword
 
@@ -960,6 +973,7 @@
 # DOS EPS Binary File Header
 # From: Ed Sznyter <ews@Black.Market.NET>
 0	belong		0xC5D0D3C6	DOS EPS Binary File
+!:mime	image/x-eps
 >4	long		>0		Postscript starts at byte %d
 >>8	long		>0		length %d
 >>>12	long		>0		Metafile starts at byte %d
@@ -1106,3 +1120,40 @@
 0	string	MIOPEN		Mallard BASIC Jetsam data
 0	string	Jetsam0		Mallard BASIC Jetsam index data
 
+# DOS backup 2.0 to 3.2
+
+# backupid.@@@
+
+# plausibility check for date
+0x3	ushort	>1979
+>0x5	ubyte-1 <31
+>>0x6	ubyte-1 <12
+# actually 121 nul bytes
+>>>0x7	string	\0\0\0\0\0\0\0\0
+>>>>0x1 ubyte	x	DOS 2.0 backup id file, sequence %d
+!:ext @@@
+>>>>0x0 ubyte	0xff	\b, last disk
+
+# backed up file
+
+# plausibility check for file name length
+0x53	ubyte-1	<80
+# actually 54 nul bytes
+>0x54	string	\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
+>>0x5	string	x	DOS 2.0 backed up file %s,
+>>0	ubyte	0xff	complete file
+>>0	ubyte	!0xff
+>>>1	ushort	x	split file, sequence %d
+
+
+# DOS backup 3.3 to 5.x
+
+# CONTROL.nnn files
+0	string	\x8bBACKUP\x20
+# actually 128 nul bytes
+>0xa	string	\0\0\0\0\0\0\0\0
+>>0x9	ubyte	x	DOS 3.3 backup control file, sequence %d
+>>0x8a	ubyte	0xff	\b, last disk
+
+# NB: The BACKUP.nnn files consist of the files backed up,
+# concatenated.

+ 8 - 8
magic/Magdir/msx

@@ -245,18 +245,18 @@
 0x4000	string/b		AB
 >0x4002	uleshort	>0x400F
 >>0x400A	string		\0\0\0\0\0\0	MSX ROM with nonstandard page order
->>0x4002	uleshort	x			\b, init=0x%04x
->>0x4004	uleshort	>0			\b, stahdl=0x%04x
->>0x4006	uleshort	>0			\b, devhdl=0x%04x
->>0x4008	uleshort	>0			\b, bas=0x%04x
+>>>0x4002	uleshort	x			\b, init=0x%04x
+>>>0x4004	uleshort	>0			\b, stahdl=0x%04x
+>>>0x4006	uleshort	>0			\b, devhdl=0x%04x
+>>>0x4008	uleshort	>0			\b, bas=0x%04x
 
 0x8000	string/b		AB
 >0x8002	uleshort	>0x400F
 >>0x800A	string		\0\0\0\0\0\0	MSX ROM with nonstandard page order
->>0x8002	uleshort	x			\b, init=0x%04x
->>0x8004	uleshort	>0			\b, stahdl=0x%04x
->>0x8006	uleshort	>0			\b, devhdl=0x%04x
->>0x8008	uleshort	>0			\b, bas=0x%04x
+>>>0x8002	uleshort	x			\b, init=0x%04x
+>>>0x8004	uleshort	>0			\b, stahdl=0x%04x
+>>>0x8006	uleshort	>0			\b, devhdl=0x%04x
+>>>0x8008	uleshort	>0			\b, bas=0x%04x
 
 
 0x3C000	string/b		AB

+ 4 - 4
magic/Magdir/pbf

@@ -1,11 +1,11 @@
 
 #------------------------------------------------------------------------------
-# $File: pbf,v 1.1 2013/12/21 14:27:24 christos Exp $
+# $File: pbf,v 1.2 2017/01/18 16:16:21 christos Exp $
 # file(1) magic(5) data for OpenStreetMap
 
 # OpenStreetMap Protocolbuffer Binary Format (.osm.pbf)
 # http://wiki.openstreetmap.org/wiki/PBF_Format
 # From: Markus Heidelberg <markus.heidelberg@web.de>
-0	belong		0x0000000D
->4	beshort		0x0A09
->>6	string		OSMHeader	OpenStreetMap Protocolbuffer Binary Format
+0	belong&0xfffffff0	0
+>4	beshort			0x0A09
+>>6	string			OSMHeader	OpenStreetMap Protocolbuffer Binary Format

+ 4 - 4
magic/Magdir/pgp

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: pgp,v 1.12 2016/10/07 20:22:12 christos Exp $
+# $File: pgp,v 1.13 2017/01/22 21:13:13 christos Exp $
 # pgp:  file(1) magic for Pretty Good Privacy
 # see http://lists.gnupg.org/pipermail/gnupg-devel/1999-September/016052.html
 #
@@ -19,15 +19,15 @@
 #>15	string	SIGNED\040MESSAGE-	signed message
 #>15	string	PGP\040SIGNATURE-	signature
 
-2	string	---BEGIN\ PGP\ PUBLIC\ KEY\ BLOCK-	PGP public key block
+2	string	---BEGIN\040PGP\040PUBLIC\040KEY\040BLOCK-	PGP public key block
 !:mime	application/pgp-keys
 >10	search/100	\n\n
 >>&0	use		pgp
-0	string	-----BEGIN\040PGP\40MESSAGE-		PGP message
+0	string	-----BEGIN\040PGP\040MESSAGE-		PGP message
 !:mime	application/pgp
 >10	search/100	\n\n
 >>&0	use		pgp
-0	string	-----BEGIN\040PGP\40SIGNATURE-		PGP signature
+0	string	-----BEGIN\040PGP\040SIGNATURE-		PGP signature
 !:mime	application/pgp-signature
 >10	search/100	\n\n
 >>&0	use		pgp

+ 9 - 1
magic/Magdir/sgml

@@ -1,4 +1,6 @@
-#------------------------------------------------------------------------------ # $File: sgml,v 1.34 2016/09/11 13:56:42 christos Exp $
+
+#------------------------------------------------------------------------------
+# $File: sgml,v 1.36 2016/12/01 15:40:52 christos Exp $
 # Type:	SVG Vectorial Graphics
 # From:	Noel Torres <tecnico@ejerciciosresueltos.com>
 0	string		\<?xml\ version="
@@ -46,6 +48,12 @@
 !:mime	text/html
 !:strength + 5
 
+# SVG document
+# https://www.w3.org/TR/SVG/single-page.html
+0	search/4096/cWbt	\<!doctype\ svg	SVG XML document
+!:mime  image/svg+xml
+!:strength + 5
+
 0	search/4096/cwt	\<head\>		HTML document text
 !:mime	text/html
 !:strength + 5

+ 17 - 5
magic/Magdir/ssl

@@ -1,8 +1,20 @@
+
+#------------------------------------------------------------------------------
+# $File: ssl,v 1.4 2017/01/22 21:14:25 christos Exp $
+# ssl:  file(1) magic for SSL file formats
+
 # Type: OpenSSL certificates/key files
 # From: Nicolas Collignon <tsointsoin@gmail.com>
 
-0	string	-----BEGIN\ CERTIFICATE-----	PEM certificate
-0	string	-----BEGIN\ CERTIFICATE\ REQ	PEM certificate request
-0	string	-----BEGIN\ RSA\ PRIVATE	PEM RSA private key
-0	string	-----BEGIN\ DSA\ PRIVATE	PEM DSA private key
-0	string	-----BEGIN\ EC\ PRIVATE	PEM EC private key
+0	string	-----BEGIN\040CERTIFICATE-----	PEM certificate
+0	string	-----BEGIN\040CERTIFICATE\040REQ	PEM certificate request
+0	string	-----BEGIN\040RSA\040PRIVATE	PEM RSA private key
+0	string	-----BEGIN\040DSA\040PRIVATE	PEM DSA private key
+0	string	-----BEGIN\040EC\040PRIVATE	PEM EC private key
+0	string	-----BEGIN\040ECDSA\040PRIVATE	PEM ECDSA private key
+
+# From Luc Gommans
+# OpenSSL enc file (recognized by a magic string preceding the password's salt)
+0	string	Salted__	openssl enc'd data with salted password
+# Using the -a or -base64 option, OpenSSL will base64-encode the data.
+0	string U2FsdGVkX19	openssl enc'd data with salted password, base64 encoded

+ 17 - 0
magic/Magdir/yara

@@ -0,0 +1,17 @@
+
+
+#------------------------------------------------------------------------------
+# $File: yara,v 1.1 2016/10/30 00:38:01 christos Exp $
+# yara:  file(1) magic for http://virustotal.github.io/yara/
+#
+
+0	string	YARA
+>4	lelong	>2047
+>8	byte	<20	YARA 3.x compiled rule set
+# version
+>>8	clear
+>>8	byte	6	created with version 3.3.0
+>>8	byte	8	created with version 3.4.0
+>>8	byte	11	created with version 3.5.0
+>>8	default	x
+>>>8	byte	x	development version 0x%02x

+ 3 - 1
magic/Makefile.am

@@ -1,5 +1,5 @@
 #
-# $File: Makefile.am,v 1.120 2016/10/17 19:52:29 christos Exp $
+# $File: Makefile.am,v 1.122 2016/11/09 18:20:53 christos Exp $
 #
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_DIR = $(top_srcdir)/magic
@@ -104,6 +104,7 @@ $(MAGIC_FRAGMENT_DIR)/gnome \
 $(MAGIC_FRAGMENT_DIR)/gnu \
 $(MAGIC_FRAGMENT_DIR)/gnumeric \
 $(MAGIC_FRAGMENT_DIR)/gpt \
+$(MAGIC_FRAGMENT_DIR)/gpu \
 $(MAGIC_FRAGMENT_DIR)/grace \
 $(MAGIC_FRAGMENT_DIR)/graphviz \
 $(MAGIC_FRAGMENT_DIR)/gringotts \
@@ -285,6 +286,7 @@ $(MAGIC_FRAGMENT_DIR)/xenix \
 $(MAGIC_FRAGMENT_DIR)/xilinx \
 $(MAGIC_FRAGMENT_DIR)/xo65 \
 $(MAGIC_FRAGMENT_DIR)/xwindows \
+$(MAGIC_FRAGMENT_DIR)/yara \
 $(MAGIC_FRAGMENT_DIR)/zfs \
 $(MAGIC_FRAGMENT_DIR)/zilog \
 $(MAGIC_FRAGMENT_DIR)/zyxel 

+ 3 - 1
magic/Makefile.in

@@ -273,7 +273,7 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 
 #
-# $File: Makefile.am,v 1.120 2016/10/17 19:52:29 christos Exp $
+# $File: Makefile.am,v 1.122 2016/11/09 18:20:53 christos Exp $
 #
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_DIR = $(top_srcdir)/magic
@@ -376,6 +376,7 @@ $(MAGIC_FRAGMENT_DIR)/gnome \
 $(MAGIC_FRAGMENT_DIR)/gnu \
 $(MAGIC_FRAGMENT_DIR)/gnumeric \
 $(MAGIC_FRAGMENT_DIR)/gpt \
+$(MAGIC_FRAGMENT_DIR)/gpu \
 $(MAGIC_FRAGMENT_DIR)/grace \
 $(MAGIC_FRAGMENT_DIR)/graphviz \
 $(MAGIC_FRAGMENT_DIR)/gringotts \
@@ -557,6 +558,7 @@ $(MAGIC_FRAGMENT_DIR)/xenix \
 $(MAGIC_FRAGMENT_DIR)/xilinx \
 $(MAGIC_FRAGMENT_DIR)/xo65 \
 $(MAGIC_FRAGMENT_DIR)/xwindows \
+$(MAGIC_FRAGMENT_DIR)/yara \
 $(MAGIC_FRAGMENT_DIR)/zfs \
 $(MAGIC_FRAGMENT_DIR)/zilog \
 $(MAGIC_FRAGMENT_DIR)/zyxel 

+ 19 - 6
src/apprentice.c

@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.255 2016/10/24 18:02:17 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.257 2017/02/04 16:46:16 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -2291,7 +2291,7 @@ parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line)
 
 	return parse_extra(ms, me, line,
 	    CAST(off_t, offsetof(struct magic, ext)),
-	    sizeof(m->ext), "EXTENSION", ",!+-/", 0);
+	    sizeof(m->ext), "EXTENSION", ",!+-/@", 0);
 }
 
 /*
@@ -3271,22 +3271,35 @@ file_pstring_get_length(const struct magic *m, const char *ss)
 {
 	size_t len = 0;
 	const unsigned char *s = (const unsigned char *)ss;
+	unsigned int s3, s2, s1, s0;
 
 	switch (m->str_flags & PSTRING_LEN) {
 	case PSTRING_1_LE:
 		len = *s;
 		break;
 	case PSTRING_2_LE:
-		len = (s[1] << 8) | s[0];
+		s0 = s[0];
+		s1 = s[1];
+		len = (s1 << 8) | s0;
 		break;
 	case PSTRING_2_BE:
-		len = (s[0] << 8) | s[1];
+		s0 = s[0];
+		s1 = s[1];
+		len = (s0 << 8) | s1;
 		break;
 	case PSTRING_4_LE:
-		len = (s[3] << 24) | (s[2] << 16) | (s[1] << 8) | s[0];
+		s0 = s[0];
+		s1 = s[1];
+		s2 = s[2];
+		s3 = s[3];
+		len = (s3 << 24) | (s2 << 16) | (s1 << 8) | s0;
 		break;
 	case PSTRING_4_BE:
-		len = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
+		s0 = s[0];
+		s1 = s[1];
+		s2 = s[2];
+		s3 = s[3];
+		len = (s0 << 24) | (s1 << 16) | (s2 << 8) | s3;
 		break;
 	default:
 		abort();	/* Impossible */

+ 7 - 4
src/cdf.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.85 2016/10/24 18:02:17 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.88 2017/02/07 23:21:29 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -527,9 +527,12 @@ cdf_read_long_sector_chain(const cdf_info_t *info, const cdf_header_t *h,
 	ssize_t nr;
 	scn->sst_tab = NULL;
 	scn->sst_len = cdf_count_chain(sat, sid, ss);
-	scn->sst_dirlen = len;
+	scn->sst_dirlen = MAX(h->h_min_size_standard_stream, len);
 	scn->sst_ss = ss;
 
+	if (sid == CDF_SECID_END_OF_CHAIN || len == 0)
+		return cdf_zero_stream(scn);
+
 	if (scn->sst_len == (size_t)-1)
 		goto out;
 
@@ -888,8 +891,8 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
 			DPRINTF(("Wrapped around %p < %p\n", q, p));
 			goto out;
 		}
-		if (q > e) {
-			DPRINTF(("Ran of the end %p > %p\n", q, e));
+		if (q >= e) {
+			DPRINTF(("Ran of the end %p >= %p\n", q, e));
 			goto out;
 		}
 		inp[i].pi_id = CDF_GETUINT32(p, i << 1);

+ 3 - 2
src/compress.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.100 2016/10/24 18:02:17 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.101 2017/01/18 16:33:57 christos Exp $")
 #endif
 
 #include "magic.h"
@@ -62,7 +62,7 @@ typedef void (*sig_t)(int);
 #if defined(HAVE_SYS_TIME_H)
 #include <sys/time.h>
 #endif
-#if defined(HAVE_ZLIB_H)
+#if defined(HAVE_ZLIB_H) && defined(ZLIBSUPPORT)
 #define BUILTIN_DECOMPRESS
 #include <zlib.h>
 #endif
@@ -83,6 +83,7 @@ int tty = -1;
 /*
  * The following python code is not really used because ZLIBSUPPORT is only
  * defined if we have a built-in zlib, and the built-in zlib handles that.
+ * That is not true for android where we have zlib.h and not -lz.
  */
 static const char zlibcode[] =
     "import sys, zlib; sys.stdout.write(zlib.decompress(sys.stdin.read()))";

+ 27 - 9
src/der.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: der.c,v 1.10 2016/10/24 18:02:17 christos Exp $")
+FILE_RCSID("@(#)$File: der.c,v 1.11 2016/11/07 15:51:23 christos Exp $")
 #endif
 #endif
 
@@ -159,31 +159,49 @@ gettag(const uint8_t *c, size_t *p, size_t l)
 	return tag;
 }
 
+/*
+ * Read the length of a DER tag from the input.
+ *
+ * `c` is the input, `p` is an output parameter that specifies how much of the
+ * input we consumed, and `l` is the maximum input length.
+ *
+ * Returns the length, or DER_BAD if the end of the input is reached or the
+ * length exceeds the remaining input.
+ */
 static uint32_t
 getlength(const uint8_t *c, size_t *p, size_t l)
 {
 	uint8_t digits, i;
 	size_t len;
+	int is_onebyte_result;
 
 	if (*p >= l)
 		return DER_BAD;
 
-	digits = c[(*p)++];
+	/*
+	 * Digits can either be 0b0 followed by the result, or 0b1
+	 * followed by the number of digits of the result. In either case,
+	 * we verify that we can read so many bytes from the input.
+	 */
+	is_onebyte_result = (c[*p] & 0x80) == 0;
+	digits = c[(*p)++] & 0x7f;
+	if (*p + digits >= l)
+		return DER_BAD;
 
-        if ((digits & 0x80) == 0)
+	if (is_onebyte_result)
 		return digits;
 
-        digits &= 0x7f;
+	/*
+	 * Decode len. We've already verified that we're allowed to read
+	 * `digits` bytes.
+	 */
 	len = 0;
-
-	if (*p + digits >= l)
-		return DER_BAD;
-
 	for (i = 0; i < digits; i++)
 		len = (len << 8) | c[(*p)++];
+
 	if (*p + len >= l)
 		return DER_BAD;
-        return len;
+	return len;
 }
 
 static const char *

+ 2 - 2
src/funcs.c

@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.90 2016/10/19 20:51:17 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.91 2016/12/01 16:16:14 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -76,7 +76,7 @@ file_vprintf(struct magic_set *ms, const char *fmt, va_list ap)
 	ms->o.buf = buf;
 	return 0;
 out:
-	file_error(ms, errno, "vasprintf failed");
+	fprintf(stderr, "vasprintf failed (%s)", strerror(errno));
 	return -1;
 }
 

+ 12 - 5
src/readelf.c

@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.128 2016/10/04 21:43:10 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.130 2017/01/29 19:34:24 christos Exp $")
 #endif
 
 #ifdef BUILTIN_ELF
@@ -1185,7 +1185,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 {
 	Elf32_Shdr sh32;
 	Elf64_Shdr sh64;
-	int stripped = 1;
+	int stripped = 1, has_debug_info = 1;
 	size_t nbadcap = 0;
 	void *nbuf;
 	off_t noff, coff, name_off;
@@ -1203,8 +1203,9 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 	/* Read offset of name section to be able to read section names later */
 	if (pread(fd, xsh_addr, xsh_sizeof, CAST(off_t, (off + size * strtab)))
 	    < (ssize_t)xsh_sizeof) {
-		file_badread(ms);
-		return -1;
+		if (file_printf(ms, ", missing section headers") == -1)
+			return -1;
+		return 0;
 	}
 	name_off = xsh_offset;
 
@@ -1215,8 +1216,10 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 			return -1;
 		}
 		name[namesize] = '\0';
-		if (strcmp(name, ".debug_info") == 0)
+		if (strcmp(name, ".debug_info") == 0) {
+			has_debug_info = 1;
 			stripped = 0;
+		}
 
 		if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {
 			file_badread(ms);
@@ -1372,6 +1375,10 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 
 	if (file_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1)
 		return -1;
+	if (has_debug_info) {
+		if (file_printf(ms, ", with debug_info") == -1)
+			return -1;
+	}
 	if (cap_hw1) {
 		const cap_desc_t *cdp;
 		switch (mach) {

+ 7 - 6
src/softmagic.c

@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.238 2016/10/24 18:02:17 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.243 2017/02/07 23:27:32 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -1260,7 +1260,8 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
 				if (*dst == '\0') {
 					if (type == FILE_BESTRING16 ?
 					    *(src - 1) != '\0' :
-					    *(src + 1) != '\0')
+					    ((src + 1 < esrc) &&
+					    *(src + 1) != '\0'))
 						*dst = ' ';
 				}
 			}
@@ -1842,14 +1843,14 @@ magiccheck(struct magic_set *ms, struct magic *m)
 		v = 0;
 
 		for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) {
-			if (slen + idx > ms->search.s_len)
-				break;
+			if (slen + idx >= ms->search.s_len)
+				return 0;
 
 			v = file_strncmp(m->value.s, ms->search.s + idx, slen,
 			    m->str_flags);
 			if (v == 0) {	/* found match */
 				ms->search.offset += idx;
-				ms->search.rm_len = m->str_range - idx;
+				ms->search.rm_len = ms->search.s_len - idx;
 				break;
 			}
 		}
@@ -1887,7 +1888,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
 			    copy[--slen] = '\0';
 			    search = copy;
 			} else {
-			    search = ms->search.s;
+			    search = CCAST(char *, "");
 			    copy = NULL;
 			}
 			rc = file_regexec(&rx, (const char *)search,