Browse Source

Import upstream version 4.21

Christos Zoulas 17 years ago
parent
commit
ccd48cd962

+ 21 - 0
ChangeLog

@@ -1,3 +1,24 @@
+2007-05-24 10:00 Christos Zoulas <christos@zoulas.com>
+
+	* Fix another integer overflow (Colin Percival)
+
+2007-03-26 13:58 Christos Zoulas <christos@zoulas.com>
+
+	* make sure that all of struct magic_set is initialized appropriately
+	  (Brett)
+
+2007-03-25 17:44 Christos Zoulas <christos@zoulas.com>
+
+	* reset left bytes in the buffer (Dmitry V. Levin)
+
+	* compilation failed with COMPILE_ONLY and ENABLE_CONDITIONALS
+	  (Peter Avalos)
+
+2007-03-15 10:51 Christos Zoulas <christos@zoulas.com>
+
+	* fix fortran and nroff reversed tests (Dmitry V. Levin)
+	
+	* fix exclude option (Dmitry V. Levin)
 
 
 2007-02-08 17:30 Christos Zoulas <christos@zoulas.com>
 2007-02-08 17:30 Christos Zoulas <christos@zoulas.com>
 
 

+ 3 - 0
config.h.in

@@ -27,6 +27,9 @@
 /* Define to 1 if you have the `z' library (-lz). */
 /* Define to 1 if you have the `z' library (-lz). */
 #undef HAVE_LIBZ
 #undef HAVE_LIBZ
 
 
+/* Define to 1 if you have the <limits.h> header file. */
+#undef HAVE_LIMITS_H
+
 /* Define to 1 if you have the <locale.h> header file. */
 /* Define to 1 if you have the <locale.h> header file. */
 #undef HAVE_LOCALE_H
 #undef HAVE_LOCALE_H
 
 

+ 3 - 2
configure

@@ -1808,7 +1808,7 @@ fi
 
 
 # Define the identity of the package.
 # Define the identity of the package.
  PACKAGE=file
  PACKAGE=file
- VERSION=4.20
+ VERSION=4.21
 
 
 
 
 cat >>confdefs.h <<_ACEOF
 cat >>confdefs.h <<_ACEOF
@@ -20670,7 +20670,8 @@ done
 
 
 
 
 
 
-for ac_header in utime.h wchar.h wctype.h
+
+for ac_header in utime.h wchar.h wctype.h limits.h
 do
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 if eval "test \"\${$as_ac_Header+set}\" = set"; then
 if eval "test \"\${$as_ac_Header+set}\" = set"; then

+ 2 - 2
configure.in

@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 dnl Process this file with autoconf to produce a configure script.
 AC_INIT
 AC_INIT
 AC_CONFIG_SRCDIR([src/file.c])
 AC_CONFIG_SRCDIR([src/file.c])
-AM_INIT_AUTOMAKE(file, 4.20)
+AM_INIT_AUTOMAKE(file, 4.21)
 AM_CONFIG_HEADER([config.h])
 AM_CONFIG_HEADER([config.h])
 AM_MAINTAINER_MODE
 AM_MAINTAINER_MODE
 
 
@@ -80,7 +80,7 @@ AC_HEADER_MAJOR
 AC_HEADER_SYS_WAIT
 AC_HEADER_SYS_WAIT
 AC_HEADER_STDINT
 AC_HEADER_STDINT
 AC_CHECK_HEADERS(fcntl.h locale.h stdint.h inttypes.h unistd.h getopt.h)
 AC_CHECK_HEADERS(fcntl.h locale.h stdint.h inttypes.h unistd.h getopt.h)
-AC_CHECK_HEADERS(utime.h wchar.h wctype.h)
+AC_CHECK_HEADERS(utime.h wchar.h wctype.h limits.h)
 AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h)
 AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h)
 
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 dnl Checks for typedefs, structures, and compiler characteristics.

+ 1 - 1
doc/libmagic.man

@@ -140,7 +140,7 @@ no error.
 The
 The
 .Fn magic_errno
 .Fn magic_errno
 function returns the last operating system error number
 function returns the last operating system error number
-.Pq .Xr errno 2
+.Pq Xr errno 2
 that was encountered by a system call.
 that was encountered by a system call.
 .Pp
 .Pp
 The
 The

+ 74 - 70
doc/magic.man

@@ -1,4 +1,4 @@
-.\" $File: magic.man,v 1.36 2007/01/10 22:56:49 christos Exp $
+.\" $File: magic.man,v 1.38 2007/01/27 00:52:08 ljt Exp $
 .Dd January 10, 2007
 .Dd January 10, 2007
 .Dt MAGIC __FSECTION__
 .Dt MAGIC __FSECTION__
 .Os
 .Os
@@ -49,7 +49,7 @@ An eight-byte value (on most systems) in this machine's native byte order.
 A string of bytes.
 A string of bytes.
 The string type specification can be optionally followed
 The string type specification can be optionally followed
 by /[Bbc]*.
 by /[Bbc]*.
-The 
+The
 .Dq B
 .Dq B
 flag compacts whitespace in the target, which must
 flag compacts whitespace in the target, which must
 contain at least one whitespace character.
 contain at least one whitespace character.
@@ -58,7 +58,7 @@ If the magic has
 consecutive blanks, the target needs at least
 consecutive blanks, the target needs at least
 .Dv n
 .Dv n
 consecutive blanks to match.
 consecutive blanks to match.
-The 
+The
 .Dq b
 .Dq b
 flag treats every blank in the target as an optional blank.
 flag treats every blank in the target as an optional blank.
 Finally the
 Finally the
@@ -69,7 +69,8 @@ targer, whereas upper case characters in the magic, only much uppercase
 characters in the target.
 characters in the target.
 .It Dv pstring
 .It Dv pstring
 A pascal style string where the first byte is interpreted as the an
 A pascal style string where the first byte is interpreted as the an
-unsigned length. The string is not NUL terminated.
+unsigned length.
+The string is not NUL terminated.
 .It Dv date
 .It Dv date
 A four-byte value interpreted as a UNIX date.
 A four-byte value interpreted as a UNIX date.
 .It Dv qdate
 .It Dv qdate
@@ -137,7 +138,7 @@ than UTC.
 A regular expression match in extended POSIX regular expression syntax
 A regular expression match in extended POSIX regular expression syntax
 (much like egrep).
 (much like egrep).
 The type specification can be optionally followed by /[cse]*.
 The type specification can be optionally followed by /[cse]*.
-The 
+The
 .Dq c
 .Dq c
 flag makes the match case insensitive, while the
 flag makes the match case insensitive, while the
 .Dq s
 .Dq s
@@ -158,14 +159,15 @@ and
 will match the beginning and end of individual lines, respectively,
 will match the beginning and end of individual lines, respectively,
 not beginning and end of file.
 not beginning and end of file.
 .It Dv search
 .It Dv search
-A literal string search starting at the given offset. It must be followed by
-.Dv /<number>
+A literal string search starting at the given offset.
+It must be followed by
+.Dv \*[Lt]number\*[Gt]
 which specifies how many matches shall be attempted (the range).
 which specifies how many matches shall be attempted (the range).
 This is suitable for searching larger binary expressions with variable
 This is suitable for searching larger binary expressions with variable
 offsets, using
 offsets, using
 .Dv \e
 .Dv \e
 escapes for special characters.
 escapes for special characters.
-.It Dv default 
+.It Dv default
 This is intended to be used with the text
 This is intended to be used with the text
 .Dv x
 .Dv x
 (which is always true) and a message that is to be used if there are
 (which is always true) and a message that is to be used if there are
@@ -174,7 +176,7 @@ no other matches.
 .El
 .El
 .Pp
 .Pp
 The numeric types may optionally be followed by
 The numeric types may optionally be followed by
-.Dv &
+.Dv \*[Am]
 and a numeric value,
 and a numeric value,
 to specify that the value is to be AND'ed with the
 to specify that the value is to be AND'ed with the
 numeric value before any comparisons are done.
 numeric value before any comparisons are done.
@@ -194,13 +196,13 @@ may be preceded by a character indicating the operation to be performed.
 It may be
 It may be
 .Dv = ,
 .Dv = ,
 to specify that the value from the file must equal the specified value,
 to specify that the value from the file must equal the specified value,
-.Dv < ,
+.Dv \*[Lt] ,
 to specify that the value from the file must be less than the specified
 to specify that the value from the file must be less than the specified
 value,
 value,
-.Dv > ,
+.Dv \*[Gt] ,
 to specify that the value from the file must be greater than the specified
 to specify that the value from the file must be greater than the specified
 value,
 value,
-.Dv & ,
+.Dv \*[Am] ,
 to specify that the value from the file must have set all of the bits
 to specify that the value from the file must have set all of the bits
 that are set in the specified value,
 that are set in the specified value,
 .Dv ^ ,
 .Dv ^ ,
@@ -215,7 +217,7 @@ If the character is omitted, it is assumed to be
 For all tests except
 For all tests except
 .Em string
 .Em string
 and
 and
-.Em regex,
+.Em regex ,
 operation
 operation
 .Dv !
 .Dv !
 specifies that the line matches if the test does
 specifies that the line matches if the test does
@@ -234,25 +236,25 @@ For string values, the byte string from the
 file must match the specified byte string.
 file must match the specified byte string.
 The operators
 The operators
 .Dv = ,
 .Dv = ,
-.Dv <
+.Dv \*[Lt]
 and
 and
-.Dv >
+.Dv \*[Gt]
 (but not
 (but not
-.Dv & )
+.Dv \*[Am] )
 can be applied to strings.
 can be applied to strings.
 The length used for matching is that of the string argument
 The length used for matching is that of the string argument
 in the magic file.
 in the magic file.
 This means that a line can match any string, and
 This means that a line can match any string, and
 then presumably print that string, by doing
 then presumably print that string, by doing
-.Em >\e0
+.Em \*[Gt]\e0
 (because all strings are greater than the null string).
 (because all strings are greater than the null string).
 .Pp
 .Pp
 The special test
 The special test
 .Em x
 .Em x
 always evaluates to true.
 always evaluates to true.
 .Dv message
 .Dv message
-The message to be printed if the comparison succeeds.  If the string
-contains a
+The message to be printed if the comparison succeeds.
+If the string contains a
 .Xr printf 3
 .Xr printf 3
 format specification, the value from the file (with any specified masking
 format specification, the value from the file (with any specified masking
 performed) is printed using the message as the format string.
 performed) is printed using the message as the format string.
@@ -265,12 +267,12 @@ Some file formats contain additional information which is to be printed
 along with the file type or need additional tests to determine the true
 along with the file type or need additional tests to determine the true
 file type.
 file type.
 These additional tests are introduced by one or more
 These additional tests are introduced by one or more
-.Em >
+.Em \*[Gt]
 characters preceding the offset.
 characters preceding the offset.
 The number of
 The number of
-.Em >
+.Em \*[Gt]
 on the line indicates the level of the test; a line with no
 on the line indicates the level of the test; a line with no
-.Em >
+.Em \*[Gt]
 at the beginning is considered to be at level 0.
 at the beginning is considered to be at level 0.
 Tests are arranged in a tree-like hierarchy:
 Tests are arranged in a tree-like hierarchy:
 If a the test on a line at level
 If a the test on a line at level
@@ -283,16 +285,16 @@ with level
 (or less) appears.
 (or less) appears.
 For more complex files, one can use empty messages to get just the
 For more complex files, one can use empty messages to get just the
 "if/then" effect, in the following way:
 "if/then" effect, in the following way:
-.Bd -literal -offset indent 
+.Bd -literal -offset indent
 0      string   MZ
 0      string   MZ
->0x18  leshort  <0x40   MS-DOS executable
->0x18  leshort  >0x3f   extended PC executable (e.g., MS Windows)
+\*[Gt]0x18  leshort  \*[Lt]0x40   MS-DOS executable
+\*[Gt]0x18  leshort  \*[Gt]0x3f   extended PC executable (e.g., MS Windows)
 .Ed
 .Ed
 .Pp
 .Pp
 Offsets do not need to be constant, but can also be read from the file
 Offsets do not need to be constant, but can also be read from the file
 being examined.
 being examined.
 If the first character following the last
 If the first character following the last
-.Em >
+.Em \*[Gt]
 is a
 is a
 .Em (
 .Em (
 then the string after the parenthesis is interpreted as an indirect offset.
 then the string after the parenthesis is interpreted as an indirect offset.
@@ -301,11 +303,11 @@ the file.
 The value at that offset is read, and is used again as an offset
 The value at that offset is read, and is used again as an offset
 in the file.
 in the file.
 Indirect offsets are of the form:
 Indirect offsets are of the form:
-.Em (( x [.[bslBSL]][+\-][ y ]).
+.Em (( x [.[bslBSL]][+\-][ y ]) .
 The value of
 The value of
 .Em x
 .Em x
-is used as an offset in the file. A byte, short or long is read at that offset
-depending on the
+is used as an offset in the file.
+A byte, short or long is read at that offset depending on the
 .Em [bslBSLm]
 .Em [bslBSLm]
 type specifier.
 type specifier.
 The capitalized types interpret the number as a big endian
 The capitalized types interpret the number as a big endian
@@ -320,14 +322,14 @@ is added and the result is used as an offset in the file.
 The default type if one is not specified is long.
 The default type if one is not specified is long.
 .Pp
 .Pp
 That way variable length structures can be examined:
 That way variable length structures can be examined:
-.Bd -literal -offset indent 
+.Bd -literal -offset indent
 # MS Windows executables are also valid MS-DOS executables
 # MS Windows executables are also valid MS-DOS executables
 0           string  MZ
 0           string  MZ
->0x18       leshort <0x40   MZ executable (MS-DOS)
+\*[Gt]0x18       leshort \*[Lt]0x40   MZ executable (MS-DOS)
 # skip the whole block below if it is not an extended executable
 # skip the whole block below if it is not an extended executable
->0x18       leshort >0x3f
->>(0x3c.l)  string  PE\e0\e0  PE executable (MS-Windows)
->>(0x3c.l)  string  LX\e0\e0  LX executable (OS/2)
+\*[Gt]0x18       leshort \*[Gt]0x3f
+\*[Gt]\*[Gt](0x3c.l)  string  PE\e0\e0  PE executable (MS-Windows)
+\*[Gt]\*[Gt](0x3c.l)  string  LX\e0\e0  LX executable (OS/2)
 .Ed
 .Ed
 .Pp
 .Pp
 This strategy of examining has one drawback: You must make sure that
 This strategy of examining has one drawback: You must make sure that
@@ -336,79 +338,84 @@ there is neither PE\e0\e0 nor LE\e0\e0 in the above example)
 .Pp
 .Pp
 If this indirect offset cannot be used as-is, there are simple calculations
 If this indirect offset cannot be used as-is, there are simple calculations
 possible: appending
 possible: appending
-.Em [+-*/%&|^]<number>
+.Em [+-*/%\*[Am]|^]\*[Lt]number\*[Gt]
 inside parentheses allows one to modify
 inside parentheses allows one to modify
 the value read from the file before it is used as an offset:
 the value read from the file before it is used as an offset:
-.Bd -literal -offset indent 
+.Bd -literal -offset indent
 # MS Windows executables are also valid MS-DOS executables
 # MS Windows executables are also valid MS-DOS executables
 0           string  MZ
 0           string  MZ
 # sometimes, the value at 0x18 is less that 0x40 but there's still an
 # sometimes, the value at 0x18 is less that 0x40 but there's still an
 # extended executable, simply appended to the file
 # extended executable, simply appended to the file
->0x18       leshort <0x40
->>(4.s*512) leshort 0x014c  COFF executable (MS-DOS, DJGPP)
->>(4.s*512) leshort !0x014c MZ executable (MS-DOS)
+\*[Gt]0x18       leshort \*[Lt]0x40
+\*[Gt]\*[Gt](4.s*512) leshort 0x014c  COFF executable (MS-DOS, DJGPP)
+\*[Gt]\*[Gt](4.s*512) leshort !0x014c MZ executable (MS-DOS)
 .Ed
 .Ed
 .Pp
 .Pp
 Sometimes you do not know the exact offset as this depends on the length or
 Sometimes you do not know the exact offset as this depends on the length or
-position (when indirection was used before) of preceding fields. You can
-specify an offset relative to the end of the last up-level field using
-.Sq &
+position (when indirection was used before) of preceding fields.
+You can specify an offset relative to the end of the last up-level
+field using
+.Sq \*[Am]
 as a prefix to the offset:
 as a prefix to the offset:
-.Bd -literal -offset indent 
+.Bd -literal -offset indent
 0           string  MZ
 0           string  MZ
->0x18       leshort >0x3f
->>(0x3c.l)  string  PE\e0\e0    PE executable (MS-Windows)
+\*[Gt]0x18       leshort \*[Gt]0x3f
+\*[Gt]\*[Gt](0x3c.l)  string  PE\e0\e0    PE executable (MS-Windows)
 # immediately following the PE signature is the CPU type
 # immediately following the PE signature is the CPU type
->>>&0       leshort 0x14c     for Intel 80386
->>>&0       leshort 0x184     for DEC Alpha
+\*[Gt]\*[Gt]\*[Gt]\*[Am]0       leshort 0x14c     for Intel 80386
+\*[Gt]\*[Gt]\*[Gt]\*[Am]0       leshort 0x184     for DEC Alpha
 .Ed
 .Ed
 .Pp
 .Pp
 Indirect and relative offsets can be combined:
 Indirect and relative offsets can be combined:
-.Bd -literal -offset indent 
+.Bd -literal -offset indent
 0             string  MZ
 0             string  MZ
->0x18         leshort <0x40
->>(4.s*512)   leshort !0x014c MZ executable (MS-DOS)
+\*[Gt]0x18         leshort \*[Lt]0x40
+\*[Gt]\*[Gt](4.s*512)   leshort !0x014c MZ executable (MS-DOS)
 # if it's not COFF, go back 512 bytes and add the offset taken
 # if it's not COFF, go back 512 bytes and add the offset taken
 # from byte 2/3, which is yet another way of finding the start
 # from byte 2/3, which is yet another way of finding the start
 # of the extended executable
 # of the extended executable
->>>&(2.s-514) string  LE      LE executable (MS Windows VxD driver)
+\*[Gt]\*[Gt]\*[Gt]\*[Am](2.s-514) string  LE      LE executable (MS Windows VxD driver)
 .Ed
 .Ed
 .Pp
 .Pp
 Or the other way around:
 Or the other way around:
-.Bd -literal -offset indent 
+.Bd -literal -offset indent
 0                 string  MZ
 0                 string  MZ
->0x18             leshort >0x3f
->>(0x3c.l)        string  LE\e0\e0  LE executable (MS-Windows)
+\*[Gt]0x18             leshort \*[Gt]0x3f
+\*[Gt]\*[Gt](0x3c.l)        string  LE\e0\e0  LE executable (MS-Windows)
 # at offset 0x80 (-4, since relative offsets start at the end
 # at offset 0x80 (-4, since relative offsets start at the end
 # of the up-level match) inside the LE header, we find the absolute
 # of the up-level match) inside the LE header, we find the absolute
 # offset to the code area, where we look for a specific signature
 # offset to the code area, where we look for a specific signature
->>>(&0x7c.l+0x26) string  UPX     \eb, UPX compressed
+\*[Gt]\*[Gt]\*[Gt](\*[Am]0x7c.l+0x26) string  UPX     \eb, UPX compressed
 .Ed
 .Ed
 .Pp
 .Pp
 Or even both!
 Or even both!
-.Bd -literal -offset indent 
+.Bd -literal -offset indent
 0                string  MZ
 0                string  MZ
->0x18            leshort >0x3f
->>(0x3c.l)       string  LE\e0\e0 LE executable (MS-Windows)
+\*[Gt]0x18            leshort \*[Gt]0x3f
+\*[Gt]\*[Gt](0x3c.l)       string  LE\e0\e0 LE executable (MS-Windows)
 # at offset 0x58 inside the LE header, we find the relative offset
 # at offset 0x58 inside the LE header, we find the relative offset
 # to a data area where we look for a specific signature
 # to a data area where we look for a specific signature
->>>&(&0x54.l-3)  string  UNACE  \eb, ACE self-extracting archive
+\*[Gt]\*[Gt]\*[Gt]\*[Am](\*[Am]0x54.l-3)  string  UNACE  \eb, ACE self-extracting archive
 .Ed
 .Ed
 .Pp
 .Pp
 Finally, if you have to deal with offset/length pairs in your file, even the
 Finally, if you have to deal with offset/length pairs in your file, even the
 second value in a parenthesized expression can be taken from the file itself,
 second value in a parenthesized expression can be taken from the file itself,
-using another set of parentheses. Note that this additional indirect offset
-is always relative to the start of the main indirect offset.
-.Bd -literal -offset indent 
+using another set of parentheses.
+Note that this additional indirect offset is always relative to the
+start of the main indirect offset.
+.Bd -literal -offset indent
 0                 string       MZ
 0                 string       MZ
->0x18             leshort      >0x3f
->>(0x3c.l)        string       PE\e0\e0 PE executable (MS-Windows)
+\*[Gt]0x18             leshort      \*[Gt]0x3f
+\*[Gt]\*[Gt](0x3c.l)        string       PE\e0\e0 PE executable (MS-Windows)
 # search for the PE section called ".idata"...
 # search for the PE section called ".idata"...
->>>&0xf4          search/0x140 .idata
+\*[Gt]\*[Gt]\*[Gt]\*[Am]0xf4          search/0x140 .idata
 # ...and go to the end of it, calculated from start+length;
 # ...and go to the end of it, calculated from start+length;
 # these are located 14 and 10 bytes after the section name
 # these are located 14 and 10 bytes after the section name
->>>>(&0xe.l+(-4)) string       PK\e3\e4 \eb, ZIP self-extracting archive
+\*[Gt]\*[Gt]\*[Gt]\*[Gt](\*[Am]0xe.l+(-4)) string       PK\e3\e4 \eb, ZIP self-extracting archive
 .Ed
 .Ed
+.Sh SEE ALSO
+.Xr file __CSECTION__
+\- the command that reads this file.
 .Sh BUGS
 .Sh BUGS
 The formats
 The formats
 .Dv long ,
 .Dv long ,
@@ -430,9 +437,6 @@ are system-dependent; perhaps they should be specified as a number
 of bytes (2B, 4B, etc),
 of bytes (2B, 4B, etc),
 since the files being recognized typically come from
 since the files being recognized typically come from
 a system on which the lengths are invariant.
 a system on which the lengths are invariant.
-.Sh SEE ALSO
-.Xr file __CSECTION__
-\- the command that reads this file.
 .\"
 .\"
 .\" From: guy@sun.uucp (Guy Harris)
 .\" From: guy@sun.uucp (Guy Harris)
 .\" Newsgroups: net.bugs.usg
 .\" Newsgroups: net.bugs.usg
@@ -446,4 +450,4 @@ a system on which the lengths are invariant.
 .\" the changes I posted to the S5R2 version.
 .\" the changes I posted to the S5R2 version.
 .\"
 .\"
 .\" Modified for Ian Darwin's version of the file command.
 .\" Modified for Ian Darwin's version of the file command.
-.\" @(#)$Id: magic.man,v 1.37 2007/01/12 17:38:27 christos Exp $
+.\" @(#)$Id: magic.man,v 1.38 2007/01/27 00:52:08 ljt Exp $

+ 8 - 0
magic/Magdir/archive

@@ -723,3 +723,11 @@
 >14	byte	0x54		end slice
 >14	byte	0x54		end slice
 >14	beshort	0x4e4e		multi-part
 >14	beshort	0x4e4e		multi-part
 >14	beshort	0x4e53		multi-part, with -S
 >14	beshort	0x4e53		multi-part, with -S
+
+# Symbian installation files
+#  http://www.thouky.co.uk/software/psifs/sis.html
+#  http://developer.symbian.com/main/downloads/papers/SymbianOSv91/softwareinstallsis.pdf
+8	lelong	0x10000419	Symbian installation file
+>4	lelong	0x1000006D	(EPOC release 3/4/5)
+>4	lelong	0x10003A12	(EPOC release 6)
+0	lelong	0x10201A7A	Symbian installation file (Symbian OS 9.x)

+ 4 - 0
magic/Magdir/audio

@@ -552,3 +552,7 @@
 # http://download.ncl.ie/doc/api/ie/ncl/media/music/IMelody.html
 # http://download.ncl.ie/doc/api/ie/ncl/media/music/IMelody.html
 # http://www.wx800.com/msg/download/irda/iMelody.pdf
 # http://www.wx800.com/msg/download/irda/iMelody.pdf
 0	string	BEGIN:IMELODY	iMelody Ringtone Format
 0	string	BEGIN:IMELODY	iMelody Ringtone Format
+
+# From: Matthew Flaschen <matthew.flaschen@gatech.edu>
+0	string	#EXTM3U 	M3U playlist text
+

+ 23 - 0
magic/Magdir/console

@@ -168,3 +168,26 @@
 # From Gürkan Sengün <gurkan@linuks.mine.nu>, www.linuks.mine.nu
 # From Gürkan Sengün <gurkan@linuks.mine.nu>, www.linuks.mine.nu
 0	string		GBS		Nintendo Gameboy Music/Audio Data
 0	string		GBS		Nintendo Gameboy Music/Audio Data
 12	string		GameBoy\ Music\ Module	Nintendo Gameboy Music Module
 12	string		GameBoy\ Music\ Module	Nintendo Gameboy Music Module
+
+# 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
+>5	byte	1			\b, PPF 2.0 patch
+>5	byte	2			\b, PPF 3.0 patch
+>>56	byte	0			\b, Imagetype BIN (any)
+>>56	byte	1			\b, Imagetype GI (PrimoDVD)
+>>57	byte	0			\b, Blockcheck disabled
+>>57	byte	1			\b, Blockcheck enabled
+>>58	byte	0			\b, Undo data not available
+>>58	byte	1			\b, Undo data available
+>6	string	x			\b, description: %s
+
+0	string	PPF20			Playstation Patch File version 2.0
+>5	byte	0			\b, PPF 1.0 patch
+>5	byte	1			\b, PPF 2.0 patch
+>>56	lelong	>0			\b, size of file to patch %d
+>6	string	x			\b, description: %s
+
+0	string	PPF10			Playstation Patch File version 1.0
+>5	byte	0			\b, Simple Encoding
+>6	string	x			\b, description: %s

+ 1 - 0
magic/Magdir/elf

@@ -101,6 +101,7 @@
 >>18	leshort		88		Renesas M32R,
 >>18	leshort		88		Renesas M32R,
 >>18	leshort		94		Tensilica Xtensa,
 >>18	leshort		94		Tensilica Xtensa,
 >>18	leshort		97		NatSemi 32k,
 >>18	leshort		97		NatSemi 32k,
+>>18	leshort		106		Analog Devices Blackfin,
 >>18	leshort		0x9026		Alpha (unofficial),
 >>18	leshort		0x9026		Alpha (unofficial),
 >>20	lelong		0		invalid version
 >>20	lelong		0		invalid version
 >>20	lelong		1		version 1
 >>20	lelong		1		version 1

+ 19 - 6
magic/Magdir/filesystems

@@ -1185,15 +1185,28 @@
 >>>>>>>>&0      bedate          =0                      full dump
 >>>>>>>>&0      bedate          =0                      full dump
 >>>>>>>>&0      bedate          !0                      incremental since: %s
 >>>>>>>>&0      bedate          !0                      incremental since: %s
 
 
+#----------------------------------------------------------
 # VMS backup savesets - gerardo.cacciari@gmail.com
 # VMS backup savesets - gerardo.cacciari@gmail.com
-# had to comment out GEM Image and G3 raw data  entries due to conflict
-#0            byte    x
-#>(0.s+16)    string  \x01\x01
-#>>&(&0.b+8)  byte    0x42       OpenVMS backup saveset data
-#>>>40        lelong  x          (block size %d
-#>>>49        string  >\0        original name '%s')
+#
+4            string  \x01\x00\x01\x00\x01\x00
+>(0.s+16)    string  \x01\x01
+>>&(&0.b+8)  byte    0x42       OpenVMS backup saveset data
+>>>40        lelong  x          (block size %d,
+>>>49        string  >\0        original name '%s',
+>>>2         short   1024       VAX generated)
+>>>2         short   2048       AXP generated)
+>>>2         short   4096       I64 generated)
 
 
 # Compaq/HP RILOE floppy image
 # Compaq/HP RILOE floppy image
 # From: Dirk Jagdmann <doj@cubic.org>
 # From: Dirk Jagdmann <doj@cubic.org>
 0	string	CPQRFBLO	Compaq/HP RILOE floppy image
 0	string	CPQRFBLO	Compaq/HP RILOE floppy image
 
 
+#------------------------------------------------------------------------------
+# Files-11 On-Disk Structure (OpenVMS file system) - gerardo.cacciari@gmail.com
+# These bits come from LBN 1 (home block) of ODS-2 and ODS-5 volumes, which is
+# mapped to VBN 2 of [000000]INDEXF.SYS;1
+#
+1008    string          DECFILE11B      Files-11 On-Disk Structure
+>525    byte            x               Level %d
+>525    byte            x               (ODS-%d OpenVMS file system),
+>984    string          x               volume label is '%-12.12s'

+ 3 - 0
magic/Magdir/fonts

@@ -59,3 +59,6 @@
 # Opentype font data from Avi Bercovich
 # Opentype font data from Avi Bercovich
 0	string		OTTO		OpenType font data 
 0	string		OTTO		OpenType font data 
 
 
+# Gürkan Sengün <gurkan@linuks.mine.nu>, www.linuks.mine.nu 
+0	string		SplineFontDB:	Spline Font Database 
+>14	string		x		version %s

+ 4 - 0
magic/Magdir/images

@@ -307,6 +307,10 @@
 >5	byte	0x00		(white background)
 >5	byte	0x00		(white background)
 >5	byte	0xFF		(black background)
 >5	byte	0xFF		(black background)
 
 
+# Gürkan Sengün <gurkan@linuks.mine.nu>, www.linuks.mine.nu
+# http://www.atarimax.com/jindroush.atari.org/afmtatr.html
+0	leshort	0x0296		Atari ATR image
+
 # XXX:
 # XXX:
 # This is bad magic 0x5249 == 'RI' conflicts with RIFF and other
 # This is bad magic 0x5249 == 'RI' conflicts with RIFF and other
 # magic.
 # magic.

+ 10 - 0
magic/Magdir/linux

@@ -236,3 +236,13 @@
 >20	lelong	1			MLS
 >20	lelong	1			MLS
 >24	lelong	x			%d symbols
 >24	lelong	x			%d symbols
 >28	lelong	x			%d ocons
 >28	lelong	x			%d ocons
+
+# LUKS: Linux Unified Key Setup, On-Disk Format, http://luks.endorphin.org/spec
+# Anthon van der Neut (anthon@mnt.org)
+0	string	LUKS\xba\xbe	LUKS encrypted file,
+>6	beshort x		ver %d
+>8	string	x		[%s,
+>40	string	x		%s,
+>72	string	x		%s]
+>168	string	x		UUID: %s
+

+ 8 - 6
magic/Magdir/lisp

@@ -10,12 +10,14 @@
 # lisp files are mainly created on unix system with LF as line end
 # lisp files are mainly created on unix system with LF as line end
 >2	search/2048	!\r		Lisp/Scheme program text
 >2	search/2048	!\r		Lisp/Scheme program text
 >2	search/2048	\r		Windows INF file
 >2	search/2048	\r		Windows INF file
-0	string	(			
->1	string	if\ 			Lisp/Scheme program text
->1	string	setq\ 			Lisp/Scheme program text
->1	string	defvar\ 		Lisp/Scheme program text
->1	string	autoload\ 		Lisp/Scheme program text
->1	string	custom-set-variables	Lisp/Scheme program text
+
+0	search/256	(if\ 			Lisp/Scheme program text
+0	search/256	(setq\ 			Lisp/Scheme program text
+0	search/256	(defvar\ 		Lisp/Scheme program text
+0	search/256	(defparam\ 		Lisp/Scheme program text
+0	search/256	(defun\  		Lisp/Scheme program text
+0	search/256	(autoload\ 		Lisp/Scheme program text
+0	search/256	(custom-set-variables\ 	Lisp/Scheme program text
 
 
 # Emacs 18 - this is always correct, but not very magical.
 # Emacs 18 - this is always correct, but not very magical.
 0	string	\012(			Emacs v18 byte-compiled Lisp data
 0	string	\012(			Emacs v18 byte-compiled Lisp data

+ 7 - 0
magic/Magdir/msdos

@@ -14,6 +14,10 @@
 
 
 # OS/2 batch files are REXX. the second regex is a bit generic, oh well
 # OS/2 batch files are REXX. the second regex is a bit generic, oh well
 # the matched commands seem to be common in REXX and uncommon elsewhere
 # the matched commands seem to be common in REXX and uncommon elsewhere
+100	regex/c =^[\ \t]{0,10}call[\ \t]{1,10}rxfunc OS/2 REXX batch file text
+100	regex/c =^[\ \t]{0,10}say\ ['"]	     OS/2 REXX batch file text
+
+
 100 regex/c =^\\s*call\\s+rxfuncadd.*sysloadfu OS/2 REXX batch file text
 100 regex/c =^\\s*call\\s+rxfuncadd.*sysloadfu OS/2 REXX batch file text
 100 regex/c =^\\s*say\ ['"] OS/2 REXX batch file text
 100 regex/c =^\\s*say\ ['"] OS/2 REXX batch file text
 
 
@@ -558,6 +562,9 @@
 
 
 # Outlook Personal Folders
 # Outlook Personal Folders
 0	lelong	0x4E444221	Microsoft Outlook binary email folder
 0	lelong	0x4E444221	Microsoft Outlook binary email folder
+>10	leshort 0x0e		(Outlook <=2002)
+>10	leshort 0x17		(Outlook >=2003)
+
 
 
 # From: Dirk Jagdmann <doj@cubic.org>
 # From: Dirk Jagdmann <doj@cubic.org>
 0	lelong	0x00035f3f	Windows 3.x help file
 0	lelong	0x00035f3f	Windows 3.x help file

+ 27 - 22
magic/Magdir/os400

@@ -1,6 +1,6 @@
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
 # os400:  file(1) magic for IBM OS/400 files
 # os400:  file(1) magic for IBM OS/400 files
-
+#
 # IBM OS/400 (i5/OS) Save file (SAVF) - gerardo.cacciari@gmail.com
 # IBM OS/400 (i5/OS) Save file (SAVF) - gerardo.cacciari@gmail.com
 # In spite of its quite variable format (due to internal memory page
 # In spite of its quite variable format (due to internal memory page
 # length differences between CISC and RISC versions of the OS) the
 # length differences between CISC and RISC versions of the OS) the
@@ -9,24 +9,29 @@
 # so we must search in a somewhat large area for a particular string
 # so we must search in a somewhat large area for a particular string
 # that represents the EBCDIC encoding of 'QSRDSSPC' (save/restore
 # that represents the EBCDIC encoding of 'QSRDSSPC' (save/restore
 # descriptor space) preceded by a two byte constant.
 # descriptor space) preceded by a two byte constant.
-40	 string		@@@@@@@@
->1089	 search/7394	\x19\xDB\xD8\xE2\xD9\xC4\xE2\xE2\xD7\xC3 IBM OS/400 save file data
->>&212	 byte		0x01			 \b, created with SAVOBJ
->>&212	 byte		0x02			 \b, created with SAVLIB
->>&212	 byte		0x07			 \b, created with SAVCFG
->>&212	 byte		0x0B			 \b, created with SAVDLO
->>&213	 byte		0x43			 \b, at least V5R3 to open
->>&213	 byte		0x42			 \b, at least V5R2 to open
->>&213	 byte		0x41			 \b, at least V5R1 to open
->>&213	 byte		0x40			 \b, at least V4R5 to open
->>&213	 byte		0x3F			 \b, at least V4R4 to open
->>&213	 byte		0x3E			 \b, at least V4R3 to open
->>&213	 byte		0x3C			 \b, at least V4R2 to open
->>&213	 byte		0x3D			 \b, at least V4R1M4 to open
->>&213	 byte		0x3B			 \b, at least V4R1 to open
->>&213	 byte		0x3A			 \b, at least V3R7 to open
->>&213	 byte		0x35			 \b, at least V3R6 to open
->>&213	 byte		0x36			 \b, at least V3R2 to open
->>&213	 byte		0x34			 \b, at least V3R1 to open
->>&213	 byte		0x31			 \b, at least V3R0M5 to open
->>&213	 byte		0x30			 \b, at least V2R3 to open
+#
+1090	 search/7393	\x19\xDB\xD8\xE2\xD9\xC4\xE2\xE2\xD7\xC3 IBM OS/400 save file data
+>&212	 byte		0x01			 \b, created with SAVOBJ
+>&212	 byte		0x02			 \b, created with SAVLIB
+>&212	 byte		0x07			 \b, created with SAVCFG
+>&212	 byte		0x08			 \b, created with SAVSECDTA
+>&212	 byte		0x0A			 \b, created with SAVSECDTA
+>&212	 byte		0x0B			 \b, created with SAVDLO
+>&212	 byte		0x0D			 \b, created with SAVLICPGM
+>&212	 byte		0x11			 \b, created with SAVCHGOBJ
+>&213	 byte		0x44			 \b, at least V5R4 to open
+>&213	 byte		0x43			 \b, at least V5R3 to open
+>&213	 byte		0x42			 \b, at least V5R2 to open
+>&213	 byte		0x41			 \b, at least V5R1 to open
+>&213	 byte		0x40			 \b, at least V4R5 to open
+>&213	 byte		0x3F			 \b, at least V4R4 to open
+>&213	 byte		0x3E			 \b, at least V4R3 to open
+>&213	 byte		0x3C			 \b, at least V4R2 to open
+>&213	 byte		0x3D			 \b, at least V4R1M4 to open
+>&213	 byte		0x3B			 \b, at least V4R1 to open
+>&213	 byte		0x3A			 \b, at least V3R7 to open
+>&213	 byte		0x35			 \b, at least V3R6 to open
+>&213	 byte		0x36			 \b, at least V3R2 to open
+>&213	 byte		0x34			 \b, at least V3R1 to open
+>&213	 byte		0x31			 \b, at least V3R0M5 to open
+>&213	 byte		0x30			 \b, at least V2R3 to open

+ 5 - 1
magic/Magdir/revision

@@ -2,4 +2,8 @@
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
 # file(1) magic for revision control files
 # file(1) magic for revision control files
 # From Hendrik Scholz <hendrik@scholz.net>
 # From Hendrik Scholz <hendrik@scholz.net>
-0   string /1\ :pserver:    cvs password text file
+0	string	/1\ :pserver:	cvs password text file
+
+# Conary changesets
+# From: Jonathan Smith <smithj@rpath.com>
+0	belong	0xea3f81bb	Conary changeset data

+ 4 - 0
magic/magic.mime

@@ -951,3 +951,7 @@
 
 
 # 
 # 
 128	string		DICM		application/dicom
 128	string		DICM		application/dicom
+
+# Symbian installation files
+8	lelong	0x10000419	application/vnd.symbian.install
+0	lelong	0x10201A7A	x-epoc/x-sisx-app

+ 3 - 2
src/apprentice.c

@@ -46,7 +46,7 @@
 #endif
 #endif
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.104 2007/01/19 19:54:39 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.105 2007/05/16 20:51:40 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #define	EATAB {while (isascii((unsigned char) *l) && \
 #define	EATAB {while (isascii((unsigned char) *l) && \
@@ -327,10 +327,11 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
 	if (fn == NULL)
 	if (fn == NULL)
 		fn = MAGIC;
 		fn = MAGIC;
 
 
-	if ((fn = mfn = strdup(fn)) == NULL) {
+	if ((mfn = strdup(fn)) == NULL) {
 		file_oomem(ms, strlen(fn));
 		file_oomem(ms, strlen(fn));
 		return NULL;
 		return NULL;
 	}
 	}
+	fn = mfn;
 
 
 	if ((mlist = malloc(sizeof(*mlist))) == NULL) {
 	if ((mlist = malloc(sizeof(*mlist))) == NULL) {
 		free(mfn);
 		free(mfn);

+ 3 - 3
src/ascmagic.c

@@ -49,7 +49,7 @@
 #include "names.h"
 #include "names.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.49 2007/01/25 21:05:46 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.50 2007/03/15 14:51:00 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 typedef unsigned long unichar;
 typedef unsigned long unichar;
@@ -167,7 +167,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
 	 * I believe Plan 9 troff allows non-ASCII characters in the names
 	 * I believe Plan 9 troff allows non-ASCII characters in the names
 	 * of macros, so this test might possibly fail on such a file.
 	 * of macros, so this test might possibly fail on such a file.
 	 */
 	 */
-	if ((ms->flags & MAGIC_NO_CHECK_TROFF) != 0 && *ubuf == '.') {
+	if ((ms->flags & MAGIC_NO_CHECK_TROFF) == 0 && *ubuf == '.') {
 		unichar *tp = ubuf + 1;
 		unichar *tp = ubuf + 1;
 
 
 		while (ISSPC(*tp))
 		while (ISSPC(*tp))
@@ -184,7 +184,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
 		}
 		}
 	}
 	}
 
 
-	if ((ms->flags & MAGIC_NO_CHECK_FORTRAN) &&
+	if ((ms->flags & MAGIC_NO_CHECK_FORTRAN) == 0 &&
 	    (*buf == 'c' || *buf == 'C') && ISSPC(buf[1])) {
 	    (*buf == 'c' || *buf == 'C') && ISSPC(buf[1])) {
 		subtype_mime = "text/fortran";
 		subtype_mime = "text/fortran";
 		subtype = "fortran program";
 		subtype = "fortran program";

+ 6 - 6
src/compress.c

@@ -55,7 +55,7 @@
 
 
 
 
 #ifndef lint
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.50 2007/03/01 22:14:54 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.51 2007/03/05 02:41:29 christos Exp $")
 #endif
 #endif
 
 
 private struct {
 private struct {
@@ -170,12 +170,12 @@ sread(int fd, void *buf, size_t n, int canbepipe)
 		goto nocheck;
 		goto nocheck;
 
 
 #ifdef FIONREAD
 #ifdef FIONREAD
-	if (canbepipe && (ioctl(fd, FIONREAD, &t) == -1) || (t == 0)) {
+	if ((canbepipe && (ioctl(fd, FIONREAD, &t) == -1)) || (t == 0)) {
 #ifdef FD_ZERO
 #ifdef FD_ZERO
 		for (cnt = 0;; cnt++) {
 		for (cnt = 0;; cnt++) {
 			fd_set check;
 			fd_set check;
 			struct timeval tout = {0, 100 * 1000};
 			struct timeval tout = {0, 100 * 1000};
-			int rv;
+			int selrv;
 
 
 			FD_ZERO(&check);
 			FD_ZERO(&check);
 			FD_SET(fd, &check);
 			FD_SET(fd, &check);
@@ -184,11 +184,11 @@ sread(int fd, void *buf, size_t n, int canbepipe)
 			 * Avoid soft deadlock: do not read if there
 			 * Avoid soft deadlock: do not read if there
 			 * is nothing to read from sockets and pipes.
 			 * is nothing to read from sockets and pipes.
 			 */
 			 */
-			rv = select(fd + 1, &check, NULL, NULL, &tout);
-			if (rv == -1) {
+			selrv = select(fd + 1, &check, NULL, NULL, &tout);
+			if (selrv == -1) {
 				if (errno == EINTR || errno == EAGAIN)
 				if (errno == EINTR || errno == EAGAIN)
 					continue;
 					continue;
-			} else if (rv == 0 && cnt >= 5) {
+			} else if (selrv == 0 && cnt >= 5) {
 				return 0;
 				return 0;
 			} else
 			} else
 				break;
 				break;

+ 9 - 5
src/file.c

@@ -71,7 +71,7 @@
 #include "patchlevel.h"
 #include "patchlevel.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: file.c,v 1.107 2007/01/25 21:05:46 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.111 2007/05/08 14:44:18 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 
 
@@ -128,7 +128,7 @@ main(int argc, char *argv[])
 	char *home, *usermagic;
 	char *home, *usermagic;
 	struct stat sb;
 	struct stat sb;
 	static const char hmagic[] = "/.magic";
 	static const char hmagic[] = "/.magic";
-#define OPTSTRING	"bcCdf:F:hikLm:nNprsvz0"
+#define OPTSTRING	"bcCde:f:F:hikLm:nNprsvz0"
 #ifdef HAVE_GETOPT_LONG
 #ifdef HAVE_GETOPT_LONG
 	int longindex;
 	int longindex;
 	static const struct option long_options[] =
 	static const struct option long_options[] =
@@ -138,7 +138,7 @@ main(int argc, char *argv[])
 		{"brief", 0, 0, 'b'},
 		{"brief", 0, 0, 'b'},
 		{"checking-printout", 0, 0, 'c'},
 		{"checking-printout", 0, 0, 'c'},
 		{"debug", 0, 0, 'd'},
 		{"debug", 0, 0, 'd'},
-		{"exclude", 0, 0, 'e' },
+		{"exclude", 1, 0, 'e' },
 		{"files-from", 1, 0, 'f'},
 		{"files-from", 1, 0, 'f'},
 		{"separator", 1, 0, 'F'},
 		{"separator", 1, 0, 'F'},
 		{"mime", 0, 0, 'i'},
 		{"mime", 0, 0, 'i'},
@@ -358,9 +358,9 @@ main(int argc, char *argv[])
 
 
 private void
 private void
 /*ARGSUSED*/
 /*ARGSUSED*/
-load(const char *m __unused, int flags)
+load(const char *m, int flags)
 {
 {
-	if (magic)
+	if (magic || m == NULL)
 		return;
 		return;
 	magic = magic_open(flags);
 	magic = magic_open(flags);
 	if (magic == NULL) {
 	if (magic == NULL) {
@@ -576,8 +576,12 @@ help(void)
 "  -r, --raw                  don't translate unprintable chars to \\ooo\n"
 "  -r, --raw                  don't translate unprintable chars to \\ooo\n"
 "  -s, --special-files        treat special (block/char devices) files as\n"
 "  -s, --special-files        treat special (block/char devices) files as\n"
 "                             ordinary ones\n"
 "                             ordinary ones\n"
+"or\n"
 "      --help                 display this help and exit\n"
 "      --help                 display this help and exit\n"
+"or\n"
 "      --version              output version information and exit\n"
 "      --version              output version information and exit\n"
+"or\n"
+"  -C, --compile              compile file specified by -m\n"
 );
 );
 	exit(0);
 	exit(0);
 }
 }

+ 1 - 11
src/file.h

@@ -27,7 +27,7 @@
  */
  */
 /*
 /*
  * file.h - definitions for file(1) program
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.89 2007/03/01 22:14:54 christos Exp $
+ * @(#)$File: file.h,v 1.91 2007/03/25 03:13:47 christos Exp $
  */
  */
 
 
 #ifndef __file_h__
 #ifndef __file_h__
@@ -79,14 +79,6 @@
 #endif
 #endif
 #endif
 #endif
 
 
-#ifndef __unused
-#if __GNUC_PREREQ__(2, 7)
-#define	__unused	__attribute__((__unused__))
-#else
-#define	__unused	/* delete */
-#endif
-#endif
-
 #ifndef MIN
 #ifndef MIN
 #define	MIN(a,b)	(((a) < (b)) ? (a) : (b))
 #define	MIN(a,b)	(((a) < (b)) ? (a) : (b))
 #endif
 #endif
@@ -332,9 +324,7 @@ protected void file_showstr(FILE *, const char *, size_t);
 protected size_t file_mbswidth(const char *);
 protected size_t file_mbswidth(const char *);
 protected const char *file_getbuffer(struct magic_set *);
 protected const char *file_getbuffer(struct magic_set *);
 protected ssize_t sread(int, void *, size_t, int);
 protected ssize_t sread(int, void *, size_t, int);
-#ifdef ENABLE_CONDITIONALS
 protected int file_check_mem(struct magic_set *, unsigned int);
 protected int file_check_mem(struct magic_set *, unsigned int);
-#endif
 
 
 #ifndef COMPILE_ONLY
 #ifndef COMPILE_ONLY
 extern const char *file_names[];
 extern const char *file_names[];

+ 37 - 3
src/funcs.c

@@ -26,7 +26,6 @@
  */
  */
 #include "file.h"
 #include "file.h"
 #include "magic.h"
 #include "magic.h"
-#include <assert.h>
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
@@ -37,9 +36,19 @@
 #if defined(HAVE_WCTYPE_H)
 #if defined(HAVE_WCTYPE_H)
 #include <wctype.h>
 #include <wctype.h>
 #endif
 #endif
+#if defined(HAVE_LIMITS_H)
+#include <limits.h>
+#endif
+#ifndef SIZE_T_MAX
+#ifdef __LP64__
+#define SIZE_T_MAX (size_t)0xfffffffffffffffffU
+#else
+#define SIZE_T_MAX (size_t)0xffffffffU
+#endif
+#endif
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.28 2007/03/01 22:14:54 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.32 2007/05/24 17:22:27 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #ifndef HAVE_VSNPRINTF
 #ifndef HAVE_VSNPRINTF
@@ -219,6 +228,7 @@ file_reset(struct magic_set *ms)
 		return -1;
 		return -1;
 	}
 	}
 	ms->o.ptr = ms->o.buf;
 	ms->o.ptr = ms->o.buf;
+	ms->o.left = ms->o.size;
 	ms->haderr = 0;
 	ms->haderr = 0;
 	ms->error = -1;
 	ms->error = -1;
 	return 0;
 	return 0;
@@ -246,8 +256,11 @@ file_getbuffer(struct magic_set *ms)
 
 
 	len = ms->o.size - ms->o.left;
 	len = ms->o.size - ms->o.left;
 	/* * 4 is for octal representation, + 1 is for NUL */
 	/* * 4 is for octal representation, + 1 is for NUL */
+	if (len > (SIZE_T_MAX - 1) / 4) {
+		file_oomem(ms, len);
+		return NULL;
+	}
 	psize = len * 4 + 1;
 	psize = len * 4 + 1;
-	assert(psize > len);
 	if (ms->o.psize < psize) {
 	if (ms->o.psize < psize) {
 		if ((pbuf = realloc(ms->o.pbuf, psize)) == NULL) {
 		if ((pbuf = realloc(ms->o.pbuf, psize)) == NULL) {
 			file_oomem(ms, psize);
 			file_oomem(ms, psize);
@@ -307,6 +320,27 @@ file_getbuffer(struct magic_set *ms)
 	return ms->o.pbuf;
 	return ms->o.pbuf;
 }
 }
 
 
+protected int
+file_check_mem(struct magic_set *ms, unsigned int level)
+{
+	size_t len;
+
+	if (level >= ms->c.len) {
+		len = (ms->c.len += 20) * sizeof(*ms->c.li);
+		ms->c.li = (ms->c.li == NULL) ? malloc(len) :
+		    realloc(ms->c.li, len);
+		if (ms->c.li == NULL) {
+			file_oomem(ms, len);
+			return -1;
+		}
+	}
+	ms->c.li[level].got_match = 0;
+#ifdef ENABLE_CONDITIONALS
+	ms->c.li[level].last_match = 0;
+	ms->c.li[level].last_cond = COND_NONE;
+#endif /* ENABLE_CONDITIONALS */
+	return 0;
+}
 /*
 /*
  * Yes these wrappers suffer from buffer overflows, but if your OS does not
  * Yes these wrappers suffer from buffer overflows, but if your OS does not
  * have the real functions, maybe you should consider replacing your OS?
  * have the real functions, maybe you should consider replacing your OS?

+ 4 - 2
src/magic.c

@@ -63,7 +63,7 @@
 #include "patchlevel.h"
 #include "patchlevel.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: magic.c,v 1.40 2007/03/01 22:14:55 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.41 2007/03/26 17:59:50 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #ifdef __EMX__
 #ifdef __EMX__
@@ -86,7 +86,7 @@ magic_open(int flags)
 {
 {
 	struct magic_set *ms;
 	struct magic_set *ms;
 
 
-	if ((ms = malloc(sizeof(struct magic_set))) == NULL)
+	if ((ms = calloc((size_t)1, sizeof(struct magic_set))) == NULL)
 		return NULL;
 		return NULL;
 
 
 	if (magic_setflags(ms, flags) == -1) {
 	if (magic_setflags(ms, flags) == -1) {
@@ -109,6 +109,8 @@ magic_open(int flags)
 	ms->haderr = 0;
 	ms->haderr = 0;
 	ms->error = -1;
 	ms->error = -1;
 	ms->mlist = NULL;
 	ms->mlist = NULL;
+	ms->file = "unknown";
+	ms->line = 0;
 	return ms;
 	return ms;
 free3:
 free3:
 	free(ms->o.pbuf);
 	free(ms->o.pbuf);

+ 3 - 1
src/names.h

@@ -32,7 +32,7 @@
  * appear at fixed offsets into the file. Don't make HOWMANY
  * appear at fixed offsets into the file. Don't make HOWMANY
  * too high unless you have a very fast CPU.
  * too high unless you have a very fast CPU.
  *
  *
- * $File: names.h,v 1.26 2007/01/12 17:38:28 christos Exp $
+ * $File: names.h,v 1.27 2007/05/08 16:47:03 christos Exp $
  */
  */
 
 
 /*
 /*
@@ -167,6 +167,8 @@ static struct names {
 	{".text",	L_MACH},
 	{".text",	L_MACH},
 	{"clr",		L_MACH},
 	{"clr",		L_MACH},
 	{"(input,",	L_PAS},
 	{"(input,",	L_PAS},
+	{"program",	L_PAS},
+	{"record",	L_PAS},
 	{"dcl",		L_PLI},
 	{"dcl",		L_PLI},
 	{"Received:",	L_MAIL},
 	{"Received:",	L_MAIL},
 	{">From",	L_MAIL},
 	{">From",	L_MAIL},

+ 5 - 2
src/patchlevel.h

@@ -1,11 +1,14 @@
 #define	FILE_VERSION_MAJOR	4
 #define	FILE_VERSION_MAJOR	4
-#define	patchlevel		20
+#define	patchlevel		21
 
 
 /*
 /*
  * Patchlevel file for Ian Darwin's MAGIC command.
  * Patchlevel file for Ian Darwin's MAGIC command.
- * $File: patchlevel.h,v 1.64 2007/03/01 22:14:55 christos Exp $
+ * $File: patchlevel.h,v 1.65 2007/05/24 17:22:27 christos Exp $
  *
  *
  * $Log: patchlevel.h,v $
  * $Log: patchlevel.h,v $
+ * Revision 1.65  2007/05/24 17:22:27  christos
+ * Welcome to 4.21
+ *
  * Revision 1.64  2007/03/01 22:14:55  christos
  * Revision 1.64  2007/03/01 22:14:55  christos
  * welcome to 4.20
  * welcome to 4.20
  *
  *

+ 4 - 4
src/print.c

@@ -41,7 +41,7 @@
 #include <time.h>
 #include <time.h>
 
 
 #ifndef lint
 #ifndef lint
-FILE_RCSID("@(#)$File: print.c,v 1.58 2007/01/16 14:58:48 ljt Exp $")
+FILE_RCSID("@(#)$File: print.c,v 1.59 2007/03/05 02:41:29 christos Exp $")
 #endif  /* lint */
 #endif  /* lint */
 
 
 #define SZOF(a)	(sizeof(a) / sizeof(a[0]))
 #define SZOF(a)	(sizeof(a) / sizeof(a[0]))
@@ -52,8 +52,8 @@ file_mdump(struct magic *m)
 {
 {
 	private const char optyp[] = { FILE_OPS };
 	private const char optyp[] = { FILE_OPS };
 
 
-	(void) fprintf(stderr, "[%zu", m->lineno);
-	(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
+	(void) fprintf(stderr, "[%u", m->lineno);
+	(void) fprintf(stderr, ">>>>>>>> %u" + 8 - (m->cont_level & 7),
 		       m->offset);
 		       m->offset);
 
 
 	if (m->flag & INDIR) {
 	if (m->flag & INDIR) {
@@ -63,7 +63,7 @@ file_mdump(struct magic *m)
 					file_names[m->in_type] : "*bad*");
 					file_names[m->in_type] : "*bad*");
 		if (m->in_op & FILE_OPINVERSE)
 		if (m->in_op & FILE_OPINVERSE)
 			(void) fputc('~', stderr);
 			(void) fputc('~', stderr);
-		(void) fprintf(stderr, "%c%d),",
+		(void) fprintf(stderr, "%c%u),",
 			       ((m->in_op & FILE_OPS_MASK) < SZOF(optyp)) ? 
 			       ((m->in_op & FILE_OPS_MASK) < SZOF(optyp)) ? 
 					optyp[m->in_op & FILE_OPS_MASK] : '?',
 					optyp[m->in_op & FILE_OPS_MASK] : '?',
 				m->in_offset);
 				m->in_offset);

+ 12 - 28
src/softmagic.c

@@ -38,7 +38,7 @@
 
 
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.91 2007/01/18 05:29:33 ljt Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.99 2007/05/08 14:44:18 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 private int match(struct magic_set *, struct magic *, uint32_t,
 private int match(struct magic_set *, struct magic *, uint32_t,
@@ -74,32 +74,6 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
 	return 0;
 	return 0;
 }
 }
 
 
-#ifdef ENABLE_CONDITIONALS
-protected int
-#else
-private int
-#endif
-file_check_mem(struct magic_set *ms, unsigned int level)
-{
-	size_t len;
-
-	if (level >= ms->c.len) {
-		len = (ms->c.len += 20) * sizeof(*ms->c.li);
-		ms->c.li = (ms->c.li == NULL) ? malloc(len) :
-		    realloc(ms->c.li, len);
-		if (ms->c.li == NULL) {
-			file_oomem(ms, len);
-			return -1;
-		}
-	}
-	ms->c.li[level].got_match = 0;
-#ifdef ENABLE_CONDITIONALS
-	ms->c.li[level].last_match = 0;
-	ms->c.li[level].last_cond = COND_NONE;
-#endif /* ENABLE_CONDITIONALS */
-	return 0;
-}
-
 /*
 /*
  * Go through the whole list, stopping if you find a match.  Process all
  * Go through the whole list, stopping if you find a match.  Process all
  * the continuations of that match before returning.
  * the continuations of that match before returning.
@@ -336,7 +310,7 @@ private int32_t
 mprint(struct magic_set *ms, struct magic *m)
 mprint(struct magic_set *ms, struct magic *m)
 {
 {
 	uint64_t v;
 	uint64_t v;
-	int32_t t = 0;
+	int64_t t = 0;
  	char buf[512];
  	char buf[512];
 	union VALUETYPE *p = &ms->ms_value;
 	union VALUETYPE *p = &ms->ms_value;
 
 
@@ -1523,10 +1497,20 @@ magiccheck(struct magic_set *ms, struct magic *m)
 		}
 		}
 		else {
 		else {
 			regmatch_t pmatch[1];
 			regmatch_t pmatch[1];
+#ifndef REG_STARTEND
+#define	REG_STARTEND	0
+			size_t l = ms->search.s_len - 1;
+			char c = ms->search.s[l];
+			((char *)(intptr_t)ms->search.s)[l] = '\0';
+#else
 			pmatch[0].rm_so = 0;
 			pmatch[0].rm_so = 0;
 			pmatch[0].rm_eo = ms->search.s_len;
 			pmatch[0].rm_eo = ms->search.s_len;
+#endif
 			rc = regexec(&rx, (const char *)ms->search.s,
 			rc = regexec(&rx, (const char *)ms->search.s,
 			    1, pmatch, REG_STARTEND);
 			    1, pmatch, REG_STARTEND);
+#if REG_STARTEND == 0
+			((char *)(intptr_t)ms->search.s)[l] = c;
+#endif
 			switch (rc) {
 			switch (rc) {
 			case 0:
 			case 0:
 				ms->search.s += (int)pmatch[0].rm_so;
 				ms->search.s += (int)pmatch[0].rm_so;