Browse Source

Import upstream version 5.09

Christos Zoulas 7 years ago
parent
commit
e1cbfbcb1b

+ 17 - 0
ChangeLog

@@ -1,3 +1,20 @@
+2011-09-01  12:12  Christos Zoulas <christos@zoulas.com>
+
+	* Don't wait for any subprocess, just the one we forked.
+
+2011-08-26  16:40  Christos Zoulas <christos@zoulas.com>
+
+	* If the application name is not set in a cdf file, try to see
+	  if it has a directory with the application name on it.
+
+2011-08-17  14:32  Christos Zoulas <christos@zoulas.com>
+
+	* Fix ELF lseek(2) madness. Inspired by PR/134 by Jan Kaluza
+
+2011-08-14  09:03  Christos Zoulas <christos@zoulas.com>
+
+	* Don't use variable string formats.
+
 2011-07-12  12:32  Reuben Thomas <rrt@sc3d.org>
 
 	* Fix detection of Zip files (Mantis #128).

+ 3 - 0
config.h.in

@@ -80,6 +80,9 @@
 /* Define to 1 if you have the `mmap' function. */
 #undef HAVE_MMAP
 
+/* Define to 1 if the system has the type `pid_t'. */
+#undef HAVE_PID_T
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 

+ 21 - 12
configure

@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for file 5.08.
+# Generated by GNU Autoconf 2.68 for file 5.09.
 #
 # Report bugs to <christos@astron.com>.
 #
@@ -709,8 +709,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='file'
 PACKAGE_TARNAME='file'
-PACKAGE_VERSION='5.08'
-PACKAGE_STRING='file 5.08'
+PACKAGE_VERSION='5.09'
+PACKAGE_STRING='file 5.09'
 PACKAGE_BUGREPORT='christos@astron.com'
 PACKAGE_URL=''
 
@@ -1439,7 +1439,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.08 to adapt to many kinds of systems.
+\`configure' configures file 5.09 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1509,7 +1509,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of file 5.08:";;
+     short | recursive ) echo "Configuration of file 5.09:";;
    esac
   cat <<\_ACEOF
 
@@ -1615,7 +1615,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-file configure 5.08
+file configure 5.09
 generated by GNU Autoconf 2.68
 
 Copyright (C) 2010 Free Software Foundation, Inc.
@@ -2319,7 +2319,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.08, which was
+It was created by file $as_me 5.09, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   $ $0 $@
@@ -3134,7 +3134,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='file'
- VERSION='5.08'
+ VERSION='5.09'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -12674,6 +12674,15 @@ $as_echo "#define HAVE_STRUCT_OPTION 1" >>confdefs.h
 fi
 
 
+ac_fn_c_check_type "$LINENO" "pid_t" "ac_cv_type_pid_t" "$ac_includes_default"
+if test "x$ac_cv_type_pid_t" = xyes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_PID_T 1
+_ACEOF
+
+
+fi
 ac_fn_c_check_type "$LINENO" "uint8_t" "ac_cv_type_uint8_t" "$ac_includes_default"
 if test "x$ac_cv_type_uint8_t" = xyes; then :
 
@@ -12778,7 +12787,7 @@ $as_echo "yes" >&6; }
    WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
        -Wmissing-declarations -Wredundant-decls -Wnested-externs \
        -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
-       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter"
+       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
 fi
 else
 
@@ -12788,7 +12797,7 @@ $as_echo "yes" >&6; }
    WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
        -Wmissing-declarations -Wredundant-decls -Wnested-externs \
        -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
-       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter"
+       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
 else
    WARNINGS=
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -13546,7 +13555,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.08, which was
+This file was extended by file $as_me 5.09, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -13612,7 +13621,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.08
+file config.status 5.09
 configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
 

+ 4 - 4
configure.ac

@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-AC_INIT(file, 5.08, christos@astron.com)
+AC_INIT(file, 5.09, christos@astron.com)
 AM_INIT_AUTOMAKE()
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
@@ -100,7 +100,7 @@ AC_TYPE_MBSTATE_T
 
 AC_STRUCT_OPTION_GETOPT_H
 
-AC_CHECK_TYPES([uint8_t, uint16_t, uint32_t, int32_t, uint64_t, int64_t])
+AC_CHECK_TYPES([pid_t, uint8_t, uint16_t, uint32_t, int32_t, uint64_t, int64_t])
 AC_CHECK_SIZEOF(long long)
 AH_BOTTOM([
 #ifndef HAVE_UINT8_T
@@ -142,14 +142,14 @@ else
    WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
        -Wmissing-declarations -Wredundant-decls -Wnested-externs \
        -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
-       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter"
+       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
 fi], [
 if test "$GCC" = yes; then
    AC_MSG_RESULT(yes)
    WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
        -Wmissing-declarations -Wredundant-decls -Wnested-externs \
        -Wsign-compare -Wreturn-type -Wswitch -Wshadow \
-       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter"
+       -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
 else
    WARNINGS=
    AC_MSG_RESULT(no)

+ 59 - 1
magic/Magdir/animation

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: animation,v 1.44 2010/11/25 15:00:12 christos Exp $
+# $File: animation,v 1.45 2011/09/06 11:00:06 christos Exp $
 # animation:  file(1) magic for animation/movie formats
 #
 # animation formats
@@ -835,3 +835,61 @@
 # URL:	http://wiki.multimedia.cx/index.php?title=NUT
 # From:	Adam Buchbinder <adam.buchbinder@gmail.com>
 0	string	nut/multimedia\ container\0	NUT multimedia container
+
+# Type: Nullsoft Video (NSV)
+# URL:  http://wiki.multimedia.cx/index.php?title=Nullsoft_Video
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	NSVf	Nullsoft Video
+
+# Type: REDCode Video
+# URL:  http://www.red.com/ ; http://wiki.multimedia.cx/index.php?title=REDCode
+# From: Mike Melanson <mike@multimedia.cx>
+4	string	RED1	REDCode Video
+
+# Type: MTV Multimedia File
+# URL:  http://wiki.multimedia.cx/index.php?title=MTV
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	AMVS	MTV Multimedia File
+
+# Type: ARMovie
+# URL:  http://wiki.multimedia.cx/index.php?title=ARMovie
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	ARMovie\012	ARMovie
+
+# Type: Interplay MVE Movie
+# URL:  http://wiki.multimedia.cx/index.php?title=Interplay_MVE
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	Interplay\040MVE\040File\032	Interplay MVE Movie
+
+# Type: Windows Television DVR File
+# URL:  http://wiki.multimedia.cx/index.php?title=WTV
+# From: Mike Melanson <mike@mutlimedia.cx>
+# This takes the form of a Windows-style GUID
+0	bequad	0xB7D800203749DA11
+>8	bequad	0xA64E0007E95EAD8D	Windows Television DVR Media
+
+# Type: Sega FILM/CPK Multimedia
+# URL:  http://wiki.multimedia.cx/index.php?title=Sega_FILM
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	FILM	Sega FILM/CPK Multimedia,
+>32	belong	x	%d x
+>28	belong	x	%d
+
+# Type: Nintendo THP Multimedia
+# URL:  http://wiki.multimedia.cx/index.php?title=THP
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	THP\0	Nintendo THP Multimedia
+
+# Type: BBC Dirac Video
+# URL:  http://wiki.multimedia.cx/index.php?title=Dirac
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	BBCD	BBC Dirac Video
+
+# Type: RAD Game Tools Smacker Multimedia
+# URL:  http://wiki.multimedia.cx/index.php?title=Smacker
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	SMK	RAD Game Tools Smacker Multimedia
+>3	byte	x	version %c,
+>4	lelong	x	%d x
+>8	lelong	x	%d,
+>12	lelong	x	%d frames

+ 11 - 1
magic/Magdir/archive

@@ -1,5 +1,5 @@
 #------------------------------------------------------------------------------
-# $File: archive,v 1.67 2011/07/12 11:31:09 rrt Exp $
+# $File: archive,v 1.68 2011/09/07 15:47:51 christos Exp $
 # archive:  file(1) magic for archive formats (see also "msdos" for self-
 #           extracting compressed archives)
 #
@@ -890,3 +890,13 @@
 # ZPAQ: http://mattmahoney.net/dc/zpaq.html
 0	string	zPQ	ZPAQ stream
 >3	byte	x	\b, level %d
+
+# BBeB ebook, unencrypted (LRF format)
+# URL: http://www.sven.de/librie/Librie/LrfFormat
+# From: Adam Buchbinder <adam.buchbinder@gmail.com>
+0	string	L\0R\0F\0\0\0	BBeB ebook data, unencrypted
+>8	beshort	x		\b, version %d
+>36	byte	1		\b, front-to-back
+>36	byte	16		\b, back-to-front
+>42	beshort	x		\b, (%dx,
+>44	beshort	x		%d)

+ 11 - 1
magic/Magdir/audio

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: audio,v 1.62 2011/04/05 20:27:13 christos Exp $
+# $File: audio,v 1.63 2011/09/06 11:00:06 christos Exp $
 # audio:  file(1) magic for sound formats (see also "iff")
 #
 # Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com),
@@ -625,3 +625,13 @@
 # From: Mario Lang <mlang@debian.org>
 0	string	SCgf	SuperCollider3 Synth Definition file,
 >4	belong	x	version %d
+
+# Type: True Audio Lossless Audio
+# URL:  http://wiki.multimedia.cx/index.php?title=True_Audio
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	TTA1	True Audio Lossless Audio
+
+# Type: WavPack Lossless Audio
+# URL:  http://wiki.multimedia.cx/index.php?title=WavPack
+# From: Mike Melanson <mike@multimedia.cx>
+0	string	wvpk	WavPack Lossless Audio

+ 7 - 1
magic/Magdir/database

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: database,v 1.26 2010/12/26 23:10:59 christos Exp $
+# $File: database,v 1.28 2011/09/16 19:40:40 christos Exp $
 # database:  file(1) magic for various databases
 #
 # extracted from header/code files by Graeme Wilford (eep2gw@ee.surrey.ac.uk)
@@ -287,3 +287,9 @@
 # From:	Benoit Sibaud <bsibaud@april.org>
 0	string		ToKyO\ CaBiNeT\n	TokyoCabinet database
 >14	string		x			(version %s)
+
+# From:  Stéphane Blondon http://www.yaal.fr
+# Database file for Zope (done by FileStorage)
+0	string		FS21	Zope Object Database File Storage (data)
+# Cache file for the database of Zope (done by ClientStorage)
+0	string		ZEC3	Zope Object Database Client Cache File (data)

+ 12 - 0
magic/Magdir/fusecompress

@@ -0,0 +1,12 @@
+
+#------------------------------------------------------------------------------
+# $File: fusecompress,v 1.2 2011/08/08 09:05:55 christos Exp $
+# fusecompress:   file(1) magic for fusecompress
+0	string	\037\135\211	FuseCompress(ed) data
+>3	byte	0x00	(none format)
+>3	byte	0x01	(bz2 format)
+>3	byte	0x02	(gz format)
+>3	byte	0x03	(lzo format)
+>3	byte	0x04	(xor format)
+>3	byte	>0x04	(unknown format)
+>4	long	x	uncompressed size: %d

+ 8 - 1
magic/Magdir/iff

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: iff,v 1.12 2009/09/19 16:28:09 christos Exp $
+# $File: iff,v 1.13 2011/09/06 11:00:06 christos Exp $
 # iff:	file(1) magic for Interchange File Format (see also "audio" & "images")
 #
 # Daniel Quinlan (quinlan@yggdrasil.com) -- IFF was designed by Electronic
@@ -52,6 +52,13 @@
 >8	string		AMFF		\b, AMFF AmigaMetaFile format
 >8	string		WZRD		\b, WZRD StormWIZARD resource
 >8	string		DOC\ 		\b, DOC desktop publishing document
+>8	string		WVQA 		\b, Westwood Studios VQA Multimedia,
+>>24	leshort		x		%d video frames,
+>>26	leshort		x		%d x
+>>28	leshort		x		%d
+>8	string		MOVE		\b, Wing Commander III Video
+>>12	string		_PC_		\b, PC version
+>>12	string		3DO_		\b, 3DO version
 
 # These go at the end of the iff rules
 #

+ 28 - 0
magic/Magdir/marc21

@@ -0,0 +1,28 @@
+#--------------------------------------------
+# marc21: file(1) magic for MARC 21 Format
+#
+# Kevin Ford (kefo@loc.gov)
+# 
+# MARC21 formats are for the representation and communication
+# of bibliographic and related information in machine-readable
+# form.  For more info, see http://www.loc.gov/marc/
+
+
+# leader position 20-21 must be 45
+20	string	45	
+
+# leader starts with 5 digits, followed by codes specific to MARC format
+>0	regex/1	(^[0-9]{5})[acdnp][^bhlnqsu-z]	MARC21 Bibliographic
+!:mime	application/marc
+>0	regex/1	(^[0-9]{5})[acdnosx][z]	MARC21 Authority
+!:mime	application/marc
+>0	regex/1	(^[0-9]{5})[cdn][uvxy]	MARC21 Holdings
+!:mime	application/marc
+0	regex/1	(^[0-9]{5})[acdn][w]	MARC21 Classification
+!:mime	application/marc
+>0	regex/1	(^[0-9]{5})[cdn][q]	MARC21 Community
+!:mime	application/marc
+
+# leader position 22-23, should be "00" but is it?
+>0	regex/1	(^.{21})([^0]{2})	(non-conforming)
+!:mime	application/marc

+ 9 - 7
magic/Magdir/msdos

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: msdos,v 1.74 2011/06/06 13:01:41 christos Exp $
+# $File: msdos,v 1.75 2011/08/08 08:56:17 christos Exp $
 # msdos:  file(1) magic for MS-DOS files
 #
 
@@ -638,12 +638,14 @@
 0	lelong		0x08084b50	TurboC Font file
 
 # WARNING: below line conflicts with Infocom game data Z-machine 3
-0	byte		0x03		DBase 3 data file
->0x04	lelong		0		(no records)
->0x04	lelong		>0		(%ld records)
-0	byte		0x83		DBase 3 data file with memo(s)
->0x04	lelong		0		(no records)
->0x04	lelong		>0		(%ld records)
+0	byte		0x03
+>0x02	byte		<0x13		DBase 3 data file
+>>0x04	lelong		0		(no records)
+>>0x04	lelong		>0		(%ld records)
+0	byte		0x83
+>0x02	byte		<0x13		DBase 3 data file with memo(s)
+>>0x04	lelong		0		(no records)
+>>0x04	lelong		>0		(%ld records)
 0	leshort		0x0006		DBase 3 index file
 0	string		PMCC		Windows 3.x .GRP file
 1	string		RDC-meg		MegaDots 

+ 3 - 1
magic/Magdir/riff

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: riff,v 1.21 2011/02/10 01:52:51 christos Exp $
+# $File: riff,v 1.22 2011/09/06 11:00:06 christos Exp $
 # riff:  file(1) magic for RIFF format
 # See
 #
@@ -179,6 +179,8 @@
 # MPEG-1 wrapped in a RIFF, apparently
 >8      string          CDXA            \b, wrapped MPEG-1 (CDXA)
 >8	string		4XMV		\b, 4X Movie file 
+# AMV-type AVI file: http://wiki.multimedia.cx/index.php?title=AMV
+>8	string		AMV\040		\b, AMV 
 
 #
 # XXX - some of the below may only appear in little-endian form.

+ 34 - 0
magic/Magdir/smile

@@ -0,0 +1,34 @@
+
+#------------------------------------------------------------------------------
+# $File: smile,v 1.1 2011/08/17 17:37:18 christos Exp $
+# smile:  file(1) magic for Smile serialization
+#
+# The Smile serialization format uses a 4-byte header:
+#
+#   Constant byte #0: 0x3A (ASCII ':')
+#   Constant byte #1: 0x29 (ASCII ')')
+#   Constant byte #2: 0x0A (ASCII linefeed, '\n')
+#   Variable byte #3, consisting of bits:
+#     Bits 4-7 (4 MSB): 4-bit version number
+#     Bits 3: Reserved
+#     Bit 2 (mask 0x04): Whether raw binary (unescaped 8-bit) values may be present in content
+#     Bit 1 (mask 0x02): Whether shared String value checking was enabled during encoding, default false
+#     Bit 0 (mask 0x01): Whether shared property name checking was enabled during encoding, default true
+#
+# Reference: http://wiki.fasterxml.com/SmileFormatSpec
+# Created by: Pierre-Alexandre Meyer <pierre@mouraf.org>
+
+# Detection
+0	string		:)\n	Smile binary data
+
+# Versioning
+>3	byte&0xF0	x		version %d:
+
+# Properties
+>3	byte&0x04	0x04		binary raw,
+>3	byte&0x04	0x00		binary encoded,
+>3	byte&0x02	0x02		shared String values enabled,
+>3	byte&0x02	0x00		shared String values disabled,
+>3	byte&0x01	0x01		shared field names enabled
+>3	byte&0x01	0x00		shared field names disabled
+

+ 1 - 13
magic/Magdir/sniffer

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: sniffer,v 1.17 2011/07/11 19:42:02 christos Exp $
+# $File: sniffer,v 1.18 2011/08/08 08:49:27 christos Exp $
 # sniffer:  file(1) magic for packet capture files
 #
 # From: guy@alum.mit.edu (Guy Harris)
@@ -250,18 +250,6 @@
 >16	lelong		x		\b, capture length %d)
 
 #
-# "pcapng" capture files.
-# http://www.winpcap.org/ntar/draft/PCAP-DumpFileFormat.html
-#
-0	ubelong		0x0a0d0d0a
->8	ubelong		0x1a2b3c4d	pcapng capture file (big-endian)
->>12	beshort		x		- version %d
->>14	beshort		x		\b.%d
->8	ulelong		0x1a2b3c4d	pcapng capture file (little-endian)
->>12	leshort		x		- version %d
->>14	leshort		x		\b.%d
-
-#
 # "pcap-ng" capture files.
 # http://www.winpcap.org/ntar/draft/PCAP-DumpFileFormat.html
 # Pcap-ng files can contain multiple sections. Printing the endianness,

+ 3 - 1
magic/Magdir/xdelta

@@ -1,6 +1,6 @@
 
 #------------------------------------------------------------------------------
-# $File: xdelta,v 1.4 2009/09/19 16:28:13 christos Exp $
+# $File: xdelta,v 1.5 2011/08/08 09:01:05 christos Exp $
 # file(1) magic(5) data for xdelta  Josh MacDonald <jmacd@CS.Berkeley.EDU>
 #
 0	string	%XDELTA%	XDelta binary patch file 0.14
@@ -9,3 +9,5 @@
 0	string	%XDZ002%	XDelta binary patch file 1.0
 0	string	%XDZ003%	XDelta binary patch file 1.0.4
 0	string	%XDZ004%	XDelta binary patch file 1.1
+
+0	string \xD6\xC3\xC4\x00	VCDIFF binary diff

+ 4 - 1
magic/Makefile.am

@@ -1,5 +1,5 @@
 #
-# $File: Makefile.am,v 1.70 2011/08/03 16:55:40 christos Exp $
+# $File: Makefile.am,v 1.73 2011/09/08 21:58:42 christos Exp $
 #
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_DIR = $(top_srcdir)/magic
@@ -76,6 +76,7 @@ $(MAGIC_FRAGMENT_DIR)/fortran \
 $(MAGIC_FRAGMENT_DIR)/frame \
 $(MAGIC_FRAGMENT_DIR)/freebsd \
 $(MAGIC_FRAGMENT_DIR)/fsav \
+$(MAGIC_FRAGMENT_DIR)/fusecompress \
 $(MAGIC_FRAGMENT_DIR)/games \
 $(MAGIC_FRAGMENT_DIR)/gcc \
 $(MAGIC_FRAGMENT_DIR)/geo \
@@ -118,6 +119,7 @@ $(MAGIC_FRAGMENT_DIR)/macintosh \
 $(MAGIC_FRAGMENT_DIR)/magic \
 $(MAGIC_FRAGMENT_DIR)/mail.news \
 $(MAGIC_FRAGMENT_DIR)/maple \
+$(MAGIC_FRAGMENT_DIR)/marc21 \
 $(MAGIC_FRAGMENT_DIR)/mathcad \
 $(MAGIC_FRAGMENT_DIR)/mathematica \
 $(MAGIC_FRAGMENT_DIR)/matroska \
@@ -191,6 +193,7 @@ $(MAGIC_FRAGMENT_DIR)/sinclair \
 $(MAGIC_FRAGMENT_DIR)/sisu \
 $(MAGIC_FRAGMENT_DIR)/sketch \
 $(MAGIC_FRAGMENT_DIR)/smalltalk \
+$(MAGIC_FRAGMENT_DIR)/smile \
 $(MAGIC_FRAGMENT_DIR)/sniffer \
 $(MAGIC_FRAGMENT_DIR)/softquad \
 $(MAGIC_FRAGMENT_DIR)/spec \

+ 4 - 1
magic/Makefile.in

@@ -196,7 +196,7 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 
 #
-# $File: Makefile.am,v 1.70 2011/08/03 16:55:40 christos Exp $
+# $File: Makefile.am,v 1.73 2011/09/08 21:58:42 christos Exp $
 #
 MAGIC_FRAGMENT_BASE = Magdir
 MAGIC_DIR = $(top_srcdir)/magic
@@ -271,6 +271,7 @@ $(MAGIC_FRAGMENT_DIR)/fortran \
 $(MAGIC_FRAGMENT_DIR)/frame \
 $(MAGIC_FRAGMENT_DIR)/freebsd \
 $(MAGIC_FRAGMENT_DIR)/fsav \
+$(MAGIC_FRAGMENT_DIR)/fusecompress \
 $(MAGIC_FRAGMENT_DIR)/games \
 $(MAGIC_FRAGMENT_DIR)/gcc \
 $(MAGIC_FRAGMENT_DIR)/geo \
@@ -313,6 +314,7 @@ $(MAGIC_FRAGMENT_DIR)/macintosh \
 $(MAGIC_FRAGMENT_DIR)/magic \
 $(MAGIC_FRAGMENT_DIR)/mail.news \
 $(MAGIC_FRAGMENT_DIR)/maple \
+$(MAGIC_FRAGMENT_DIR)/marc21 \
 $(MAGIC_FRAGMENT_DIR)/mathcad \
 $(MAGIC_FRAGMENT_DIR)/mathematica \
 $(MAGIC_FRAGMENT_DIR)/matroska \
@@ -386,6 +388,7 @@ $(MAGIC_FRAGMENT_DIR)/sinclair \
 $(MAGIC_FRAGMENT_DIR)/sisu \
 $(MAGIC_FRAGMENT_DIR)/sketch \
 $(MAGIC_FRAGMENT_DIR)/smalltalk \
+$(MAGIC_FRAGMENT_DIR)/smile \
 $(MAGIC_FRAGMENT_DIR)/sniffer \
 $(MAGIC_FRAGMENT_DIR)/softquad \
 $(MAGIC_FRAGMENT_DIR)/spec \

+ 3 - 3
src/apprentice.c

@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.170 2011/06/10 09:23:28 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.171 2011/09/16 21:04:59 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -1451,8 +1451,8 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 						goto bad;
 					m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF;
 					break;
-				bad:
 				default:
+				bad:
 					if (ms->flags & MAGIC_CHECK)
 						file_magwarn(ms,
 						    "string extension `%c' "
@@ -2085,7 +2085,7 @@ out:
 	*p = '\0';
 	m->vallen = CAST(unsigned char, (p - origp));
 	if (m->type == FILE_PSTRING)
-		m->vallen += file_pstring_length_size(m);
+		m->vallen += (unsigned char)file_pstring_length_size(m);
 	return s;
 }
 

+ 2 - 1
src/apptype.c

@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: apptype.c,v 1.11 2009/02/04 18:24:32 christos Exp $")
+FILE_RCSID("@(#)$File: apptype.c,v 1.13 2011/09/07 21:57:15 christos Exp $")
 #endif /* lint */
 
 #include <stdlib.h>
@@ -72,6 +72,7 @@ file_os2_apptype(struct magic_set *ms, const char *fn, const void *buf,
 		if (fwrite(buf, 1, nb, fp) != nb) {
 			file_error(ms, errno, "cannot write tmp file `%s'",
 			    path);
+			(void)fclose(fp);
 			return -1;
 		}
 		(void)fclose(fp);

+ 43 - 28
src/cdf.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.43 2011/03/30 19:48:13 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.46 2011/09/16 21:23:59 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -57,10 +57,6 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.43 2011/03/30 19:48:13 christos Exp $")
 
 #include "cdf.h"
 
-#ifndef __arraycount
-#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
-#endif
-
 #ifdef CDF_DEBUG
 #define DPRINTF(a) printf a, fflush(stdout)
 #else
@@ -74,28 +70,16 @@ static union {
 
 #define NEED_SWAP	(cdf_bo.u == (uint32_t)0x01020304)
 
-#define CDF_TOLE8(x)	((uint64_t)(NEED_SWAP ? cdf_tole8(x) : (uint64_t)(x)))
-#define CDF_TOLE4(x)	((uint32_t)(NEED_SWAP ? cdf_tole4(x) : (uint32_t)(x)))
-#define CDF_TOLE2(x)	((uint16_t)(NEED_SWAP ? cdf_tole2(x) : (uint16_t)(x)))
+#define CDF_TOLE8(x)	((uint64_t)(NEED_SWAP ? _cdf_tole8(x) : (uint64_t)(x)))
+#define CDF_TOLE4(x)	((uint32_t)(NEED_SWAP ? _cdf_tole4(x) : (uint32_t)(x)))
+#define CDF_TOLE2(x)	((uint16_t)(NEED_SWAP ? _cdf_tole2(x) : (uint16_t)(x)))
 #define CDF_GETUINT32(x, y)	cdf_getuint32(x, y)
 
 /*
- * grab a uint32_t from a possibly unaligned address, and return it in
- * the native host order.
- */
-static uint32_t
-cdf_getuint32(const uint8_t *p, size_t offs)
-{
-	uint32_t rv;
-	(void)memcpy(&rv, p + offs * sizeof(uint32_t), sizeof(rv));
-	return CDF_TOLE4(rv);
-}
-
-/*
  * swap a short
  */
-uint16_t
-cdf_tole2(uint16_t sv)
+static uint16_t
+_cdf_tole2(uint16_t sv)
 {
 	uint16_t rv;
 	uint8_t *s = (uint8_t *)(void *)&sv;
@@ -108,8 +92,8 @@ cdf_tole2(uint16_t sv)
 /*
  * swap an int
  */
-uint32_t
-cdf_tole4(uint32_t sv)
+static uint32_t
+_cdf_tole4(uint32_t sv)
 {
 	uint32_t rv;
 	uint8_t *s = (uint8_t *)(void *)&sv;
@@ -124,8 +108,8 @@ cdf_tole4(uint32_t sv)
 /*
  * swap a quad
  */
-uint64_t
-cdf_tole8(uint64_t sv)
+static uint64_t
+_cdf_tole8(uint64_t sv)
 {
 	uint64_t rv;
 	uint8_t *s = (uint8_t *)(void *)&sv;
@@ -141,11 +125,41 @@ cdf_tole8(uint64_t sv)
 	return rv;
 }
 
+/*
+ * grab a uint32_t from a possibly unaligned address, and return it in
+ * the native host order.
+ */
+static uint32_t
+cdf_getuint32(const uint8_t *p, size_t offs)
+{
+	uint32_t rv;
+	(void)memcpy(&rv, p + offs * sizeof(uint32_t), sizeof(rv));
+	return CDF_TOLE4(rv);
+}
+
 #define CDF_UNPACK(a)	\
     (void)memcpy(&(a), &buf[len], sizeof(a)), len += sizeof(a)
 #define CDF_UNPACKA(a)	\
     (void)memcpy((a), &buf[len], sizeof(a)), len += sizeof(a)
 
+uint16_t
+cdf_tole2(uint16_t sv)
+{
+	return CDF_TOLE2(sv);
+}
+
+uint32_t
+cdf_tole4(uint32_t sv)
+{
+	return CDF_TOLE4(sv);
+}
+
+uint64_t
+cdf_tole8(uint64_t sv)
+{
+	return CDF_TOLE8(sv);
+}
+
 void
 cdf_swap_header(cdf_header_t *h)
 {
@@ -358,7 +372,8 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
 			break;
 
 #define CDF_SEC_LIMIT (UINT32_MAX / (4 * ss))
-	if (h->h_num_sectors_in_master_sat > CDF_SEC_LIMIT / nsatpersec ||
+	if ((nsatpersec > 0 &&
+	    h->h_num_sectors_in_master_sat > CDF_SEC_LIMIT / nsatpersec) ||
 	    i > CDF_SEC_LIMIT) {
 		DPRINTF(("Number of sectors in master SAT too big %u %"
 		    SIZE_T_FORMAT "u\n", h->h_num_sectors_in_master_sat, i));
@@ -1204,7 +1219,7 @@ cdf_dump_summary_info(const cdf_header_t *h, const cdf_stream_t *sst)
 	size_t count;
 
 	(void)&h;
-	if (cdf_unpack_summary_info(sst, &ssi, &info, &count) == -1)
+	if (cdf_unpack_summary_info(sst, h, &ssi, &info, &count) == -1)
 		return;
 	(void)fprintf(stderr, "Endian: %x\n", ssi.si_byte_order);
 	(void)fprintf(stderr, "Os Version %d.%d\n", ssi.si_os_version & 0xff,

+ 4 - 3
src/compress.c

@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.66 2011/03/08 00:39:47 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.67 2011/09/01 12:12:37 christos Exp $")
 #endif
 
 #include "magic.h"
@@ -382,6 +382,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
 {
 	int fdin[2], fdout[2];
 	ssize_t r;
+	pid_t pid;
 
 #ifdef BUILTIN_DECOMPRESS
         /* FIXME: This doesn't cope with bzip2 */
@@ -395,7 +396,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
 		file_error(ms, errno, "cannot create pipe");	
 		return NODATA;
 	}
-	switch (fork()) {
+	switch (pid = fork()) {
 	case 0:	/* child */
 		(void) close(0);
 		if (fd != -1) {
@@ -492,7 +493,7 @@ err:
 			(void) close(fdin[1]);
 		(void) close(fdout[0]);
 #ifdef WNOHANG
-		while (waitpid(-1, NULL, WNOHANG) != -1)
+		while (waitpid(pid, NULL, WNOHANG) != -1)
 			continue;
 #else
 		(void)wait(NULL);

+ 1 - 2
src/elfclass.h

@@ -59,8 +59,7 @@
 		    (off_t)elf_getu(swap, elfhdr.e_shoff),
 		    elf_getu16(swap, elfhdr.e_shnum),
 		    (size_t)elf_getu16(swap, elfhdr.e_shentsize),
-		    &flags,
-		    elf_getu16(swap, elfhdr.e_machine)) == -1)
+		    fsize, &flags, elf_getu16(swap, elfhdr.e_machine)) == -1)
 			return -1;
 		break;
 

+ 5 - 1
src/file.h

@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.133 2011/05/13 22:15:40 christos Exp $
+ * @(#)$File: file.h,v 1.134 2011/09/16 21:23:59 christos Exp $
  */
 
 #ifndef __file_h__
@@ -86,6 +86,10 @@
 #endif
 #define public
 
+#ifndef __arraycount
+#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
+#endif
+
 #ifndef __GNUC_PREREQ__
 #ifdef __GNUC__
 #define	__GNUC_PREREQ__(x, y)						\

+ 4 - 8
src/fsmagic.c

@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef	lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.63 2011/07/12 11:31:59 rrt Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.64 2011/08/14 09:03:12 christos Exp $")
 #endif	/* lint */
 
 #include "magic.h"
@@ -63,22 +63,18 @@ FILE_RCSID("@(#)$File: fsmagic.c,v 1.63 2011/07/12 11:31:59 rrt Exp $")
 private int
 bad_link(struct magic_set *ms, int err, char *buf)
 {
-	const char *errfmt;
 	int mime = ms->flags & MAGIC_MIME;
 	if ((mime & MAGIC_MIME_TYPE) &&
 	    file_printf(ms, "inode/symlink")
 	    == -1)
 		return -1;
 	else if (!mime) {
-		if (err == ELOOP)
-			errfmt = "symbolic link in a loop";
-		else
-			errfmt = "broken symbolic link to `%s'";
 		if (ms->flags & MAGIC_ERROR) {
-			file_error(ms, err, errfmt, buf);
+			file_error(ms, err,
+				   "broken symbolic link to `%s'", buf);
 			return -1;
 		} 
-		if (file_printf(ms, errfmt, buf) == -1)
+		if (file_printf(ms, "broken symbolic link to `%s'", buf) == -1)
 			return -1;
 	}
 	return 1;

+ 2 - 3
src/print.c

@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: print.c,v 1.69 2010/07/21 16:47:18 christos Exp $")
+FILE_RCSID("@(#)$File: print.c,v 1.70 2011/08/14 09:03:12 christos Exp $")
 #endif  /* lint */
 
 #include <string.h>
@@ -51,8 +51,7 @@ file_mdump(struct magic *m)
 {
 	private const char optyp[] = { FILE_OPS };
 
-	(void) fprintf(stderr, "[%u", m->lineno);
-	(void) fprintf(stderr, ">>>>>>>> %u" + 8 - (m->cont_level & 7),
+	(void) fprintf(stderr, "%.*s %u", (m->cont_level & 7) + 1, ">>>>>>>>",
 		       m->offset);
 
 	if (m->flag & INDIR) {

+ 22 - 4
src/readcdf.c

@@ -26,7 +26,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.25 2011/02/10 21:35:05 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.26 2011/08/26 13:38:28 christos Exp $")
 #endif
 
 #include <stdlib.h>
@@ -48,7 +48,7 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
         cdf_timestamp_t tp;
         struct timespec ts;
         char buf[64];
-        const char *str = "vnd.ms-office";
+        const char *str = NULL;
         const char *s;
         int len;
 
@@ -142,8 +142,8 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
                 }
         }
         if (!NOTMIME(ms)) {
-                if (file_printf(ms, "application/%s", str) == -1)
-                        return -1;
+		if (str == NULL)
+			return 0;
         }
         return 1;
 }
@@ -263,6 +263,24 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
 #endif
         if ((i = cdf_file_summary_info(ms, &h, &scn)) == -1)
                 expn = "Can't expand summary_info";
+	if (i == 0) {
+		const char *str = "vnd.ms-office";
+		cdf_directory_t *d;
+		char name[__arraycount(d->d_name)];
+		size_t j, k;
+		for (j = 0; j < dir.dir_len; j++) {
+		    d = &dir.dir_tab[j];
+		    for (k = 0; k < sizeof(name); k++)
+			name[k] = (char)cdf_tole2(d->d_name[k]);
+		    if (strstr(name, "WordDocument") == 0) {
+			str = "msword";
+			break;
+		    }
+		}
+                if (file_printf(ms, "application/%s", str) == -1)
+                        return -1;
+		i = 1;
+	}
         free(scn.sst_tab);
 out4:
         free(sst.sst_tab);

+ 48 - 83
src/readelf.c

@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.88 2011/07/19 18:54:25 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.90 2011/08/23 08:01:12 christos Exp $")
 #endif
 
 #ifdef BUILTIN_ELF
@@ -47,8 +47,8 @@ private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
 #endif
 private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
     off_t, int *, int);
-private int doshn(struct magic_set *, int, int, int, off_t, int, size_t, int *,
-    int);
+private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
+    off_t, int *, int);
 private size_t donote(struct magic_set *, void *, size_t, size_t, int,
     int, size_t, int *);
 
@@ -144,7 +144,7 @@ getu64(int swap, uint64_t value)
 #define xsh_size	(clazz == ELFCLASS32			\
 			 ? elf_getu32(swap, sh32.sh_size)	\
 			 : elf_getu64(swap, sh64.sh_size))
-#define xsh_offset	(clazz == ELFCLASS32			\
+#define xsh_offset	(off_t)(clazz == ELFCLASS32		\
 			 ? elf_getu32(swap, sh32.sh_offset)	\
 			 : elf_getu64(swap, sh64.sh_offset))
 #define xsh_type	(clazz == ELFCLASS32			\
@@ -298,13 +298,6 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 	size_t offset;
 	unsigned char nbuf[BUFSIZ];
 	ssize_t bufsize;
-	off_t savedoffset;
- 	struct stat st;
-
-	if (fstat(fd, &st) < 0) {
-		file_badread(ms);
-		return -1;
-	}
 
 	if (size != xph_sizeof) {
 		if (file_printf(ms, ", corrupted program header size") == -1)
@@ -316,7 +309,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 	 * Loop through all the program headers.
 	 */
 	for ( ; num; num--) {
-		if ((savedoffset = lseek(fd, off, SEEK_SET)) == (off_t)-1) {
+		if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
 			file_badseek(ms);
 			return -1;
 		}
@@ -324,15 +317,13 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 			file_badread(ms);
 			return -1;
 		}
+		off += size;
+
 		if (xph_offset > fsize) {
-			if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
-				file_badseek(ms);
-				return -1;
-			}
+			/* Perhaps warn here */
 			continue;
 		}
 
-		off += size;
 		if (xph_type != PT_NOTE)
 			continue;
 
@@ -851,13 +842,13 @@ static const cap_desc_t cap_desc_386[] = {
 
 private int
 doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
-    size_t size, int *flags, int mach)
+    size_t size, off_t fsize, int *flags, int mach)
 {
 	Elf32_Shdr sh32;
 	Elf64_Shdr sh64;
 	int stripped = 1;
 	void *nbuf;
-	off_t noff;
+	off_t noff, coff;
 	uint64_t cap_hw1 = 0;	/* SunOS 5.x hardware capabilites */
 	uint64_t cap_sf1 = 0;	/* SunOS 5.x software capabilites */
 
@@ -867,16 +858,18 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 		return 0;
 	}
 
-	if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
-		file_badseek(ms);
-		return -1;
-	}
-
 	for ( ; num; num--) {
+		if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
+			file_badseek(ms);
+			return -1;
+		}
 		if (read(fd, xsh_addr, xsh_sizeof) == -1) {
 			file_badread(ms);
 			return -1;
 		}
+		off += size;
+
+		/* Things we can determine before we seek */
 		switch (xsh_type) {
 		case SHT_SYMTAB:
 #if 0
@@ -884,12 +877,17 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 #endif
 			stripped = 0;
 			break;
-		case SHT_NOTE:
-			if ((off = lseek(fd, (off_t)0, SEEK_CUR)) ==
-			    (off_t)-1) {
-				file_badread(ms);
-				return -1;
+		default:
+			if (xsh_offset > fsize) {
+				/* Perhaps warn here */
+				continue;
 			}
+			break;
+		}
+
+		/* Things we can determine when we seek */
+		switch (xsh_type) {
+		case SHT_NOTE:
 			if ((nbuf = malloc((size_t)xsh_size)) == NULL) {
 				file_error(ms, errno, "Cannot allocate memory"
 				    " for note");
@@ -918,24 +916,12 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 				if (noff == 0)
 					break;
 			}
-			if ((lseek(fd, off, SEEK_SET)) == (off_t)-1) {
-				free(nbuf);
-				file_badread(ms);
-				return -1;
-			}
 			free(nbuf);
 			break;
 		case SHT_SUNW_cap:
-		    {
-			off_t coff;
-			if ((off = lseek(fd, (off_t)0, SEEK_CUR)) ==
-			    (off_t)-1) {
-				file_badread(ms);
-				return -1;
-			}
 			if (lseek(fd, (off_t)xsh_offset, SEEK_SET) ==
 			    (off_t)-1) {
-				file_badread(ms);
+				file_badseek(ms);
 				return -1;
 			}
 			coff = 0;
@@ -972,12 +958,10 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 					break;
 				}
 			}
-			if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
-				file_badread(ms);
-				return -1;
-			}
 			break;
-		    }
+
+		default:
+			break;
 		}
 	}
 	if (file_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1)
@@ -1059,13 +1043,6 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 	unsigned char nbuf[BUFSIZ];
 	ssize_t bufsize;
 	size_t offset, align;
-	off_t savedoffset = (off_t)-1;
-	struct stat st;
-
-	if (fstat(fd, &st) < 0) {
-		file_badread(ms);
-		return -1;
-	}
 	
 	if (size != xph_sizeof) {
 		if (file_printf(ms, ", corrupted program header size") == -1)
@@ -1073,37 +1050,20 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 		return 0;
 	}
 
-	if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
-		file_badseek(ms);
-		return -1;
-	}
-
   	for ( ; num; num--) {
-  		if (read(fd, xph_addr, xph_sizeof) == -1) {
-  			file_badread(ms);
+		if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
+			file_badseek(ms);
 			return -1;
 		}
-		if (xph_offset > st.st_size && savedoffset != (off_t)-1) {
-			if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
-				file_badseek(ms);
-				return -1;
-			}
-			continue;
-		}
 
-		if ((savedoffset = lseek(fd, (off_t)0, SEEK_CUR)) == (off_t)-1) {
-  			file_badseek(ms);
+  		if (read(fd, xph_addr, xph_sizeof) == -1) {
+  			file_badread(ms);
 			return -1;
 		}
 
-		if (xph_offset > fsize) {
-			if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
-				file_badseek(ms);
-				return -1;
-			}
-			continue;
-		}
+		off += size;
 
+		/* Things we can determine before we seek */
 		switch (xph_type) {
 		case PT_DYNAMIC:
 			linking_style = "dynamically";
@@ -1111,6 +1071,16 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 		case PT_INTERP:
 			shared_libraries = " (uses shared libs)";
 			break;
+		default:
+			if (xph_offset > fsize) {
+				/* Maybe warn here? */
+				continue;
+			}
+			break;
+		}
+
+		/* Things we can determine when we seek */
+		switch (xph_type) {
 		case PT_NOTE:
 			if ((align = xph_align) & 0x80000000UL) {
 				if (file_printf(ms, 
@@ -1125,8 +1095,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 			 * This is a PT_NOTE section; loop through all the notes
 			 * in the section.
 			 */
-			if (lseek(fd, xph_offset, SEEK_SET)
-			    == (off_t)-1) {
+			if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
 				file_badseek(ms);
 				return -1;
 			}
@@ -1146,10 +1115,6 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 				if (offset == 0)
 					break;
 			}
-			if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
-				file_badseek(ms);
-				return -1;
-			}
 			break;
 		default:
 			break;