Path: blob/main/website/static/security/patches/EN-15:06/file-10.1.patch
18096 views
Index: contrib/file/ChangeLog1===================================================================2--- contrib/file/ChangeLog (revision 284174)3+++ contrib/file/ChangeLog (working copy)4@@ -1,3 +1,97 @@5+2015-01-02 15:15 Christos Zoulas <[email protected]>6+7+ * release 5.228+9+2015-01-01 12:01 Christos Zoulas <[email protected]>10+11+ * add indirect relative for TIFF/Exif12+13+2014-12-16 18:10 Christos Zoulas <[email protected]>14+15+ * restructure elf note printing to avoid repeated messages16+ * add note limit, suggested by Alexander Cherepanov17+18+2014-12-16 16:53 Christos Zoulas <[email protected]>19+20+ * Bail out on partial pread()'s (Alexander Cherepanov)21+ * Fix incorrect bounds check in file_printable (Alexander Cherepanov)22+23+2014-12-11 20:01 Christos Zoulas <[email protected]>24+25+ * PR/405: ignore SIGPIPE from uncompress programs26+ * change printable -> file_printable and use it in27+ more places for safety28+ * in ELF, instead of "(uses dynamic libraries)" when PT_INTERP29+ is present print the interpreter name.30+31+2014-12-10 20:01 Christos Zoulas <[email protected]>32+33+ * release 5.2134+35+2014-11-27 18:40 Christos Zoulas <[email protected]>36+37+ * Allow setting more parameters from the command line.38+ * Split name/use and indirect magic recursion limits.39+40+2014-11-27 11:12 Christos Zoulas <[email protected]>41+42+ * Adjust ELF parameters and the default recursion43+ level.44+ * Allow setting the recursion level dynamically.45+46+2014-11-24 8:55 Christos Zoulas <[email protected]>47+48+ * The following fixes resulted from Thomas Jarosch's fuzzing49+ tests that revealed severe performance issues on pathological50+ input:51+ - limit number of elf program and sections processing52+ - abort elf note processing quickly53+ - reduce the number of recursion levels from 20 to 1054+ - preserve error messages in indirect magic handling55+56+ This is tracked as CVE-2014-8116 and CVE-2014-811757+58+2014-11-12 10:30 Christos Zoulas <[email protected]>59+60+ * fix bogus free in the user buffer case.61+62+2014-11-11 12:35 Christos Zoulas <[email protected]>63+64+ * fix out of bounds read for pascal strings65+ * fix memory leak (not freeing the head of each mlist)66+67+2014-11-07 10:25 Christos Zoulas <[email protected]>68+69+ * When printing strings from a file, convert them to printable70+ on a byte by byte basis, so that we don't get issues with71+ locale's trying to interpret random byte streams as UTF-8 and72+ having printf error out with EILSEQ.73+74+2014-10-17 11:48 Christos Zoulas <[email protected]>75+76+ * fix bounds in note reading (Francisco Alonso / Red Hat)77+78+2014-10-11 15:02 Christos Zoulas <[email protected]>79+80+ * fix autoconf glue for setlocale and locale_t; some OS's81+ have locale_t in xlocale.h82+83+2014-10-10 15:01 Christos Zoulas <[email protected]>84+85+ * release 5.2086+87+2014-08-17 10:01 Christos Zoulas <[email protected]>88+89+ * recognize encrypted CDF documents90+91+2014-08-04 9:18 Christos Zoulas <[email protected]>92+93+ * add magic_load_buffers from Brooks Davis94+95+2014-07-24 16:40 Christos Zoulas <[email protected]>96+97+ * add thumbs.db support98+992014-06-12 12:28 Christos Zoulas <[email protected]>100101* release 5.19102Index: contrib/file/README103===================================================================104--- contrib/file/README (revision 284174)105+++ contrib/file/README (working copy)106@@ -1,6 +1,6 @@107## README for file(1) Command ##108109- @(#) $File: README,v 1.48 2014/03/07 13:55:30 christos Exp $110+ @(#) $File: README,v 1.49 2015/01/02 20:23:04 christos Exp $111112Mailing List: [email protected]113Mailing List archives: http://mx.gw.com/pipermail/file/114@@ -25,8 +25,8 @@ A public read-only git repository of the same sour115116https://github.com/file/file117118-The major changes for 5.x are CDF file parsing, indirect magic, and119-overhaul in mime and ascii encoding handling.120+The major changes for 5.x are CDF file parsing, indirect magic, name/use121+(recursion) and overhaul in mime and ascii encoding handling.122123The major feature of 4.x is the refactoring of the code into a library,124and the re-write of the file command in terms of that library. The library125@@ -67,33 +67,41 @@ in magic(5) format please, to the maintainer, Chri126COPYING - read this first.127README - read this second (you are currently reading this file).128INSTALL - read on how to install129-130src/apprentice.c - parses /etc/magic to learn magic131+src/asctime_r.c - replacement for OS's that don't have it.132src/apptype.c - used for OS/2 specific application type magic133src/asprintf.c - replacement for OS's that don't have it.134src/ascmagic.c - third & last set of tests, based on hardwired assumptions.135-src/asctime_r.c - for systems that don't have it.136-src/asprintf.c - for systems that don't have it.137-src/cdf.c - parser for Microsoft Compound Document Files138+src/asctime_r.c - replacement for OS's that don't have it.139+src/asprintf.c - replacement for OS's that don't have it.140+src/cdf.[ch] - parser for Microsoft Compound Document Files141src/cdf_time.c - time converter for CDF.142src/compress.c - handles decompressing files to look inside.143-src/ctime_r.c - for systems that don't have it.144+src/ctime_r.c - replacement for OS's that don't have it.145+src/elfclass.h - common code for elf 32/64.146src/encoding.c - handles unicode encodings147src/file.c - the main program148src/file.h - header file149+src/file_opts.h - list of options150+src/fmtcheck.c - replacement for OS's that don't have it.151src/fsmagic.c - first set of tests the program runs, based on filesystem info152src/funcs.c - utilility functions153-src/getopt_long.c - for systems that don't have it.154-src/getline.c - for systems that don't have it.155+src/getline.c - replacement for OS's that don't have it.156+src/getopt_long.c - replacement for OS's that don't have it.157src/is_tar.c, tar.h - knows about tarchives (courtesy John Gilmore).158src/names.h - header file for ascmagic.c159+src/magic.h.in - source file for magic.h160src/magic.c - the libmagic api161+src/pread.c - replacement for OS's that don't have it.162src/print.c - print results, errors, warnings.163src/readcdf.c - CDF wrapper.164src/readelf.[ch] - Stand-alone elf parsing code.165src/softmagic.c - 2nd set of tests, based on /etc/magic166-src/strlcat.c - for systems that don't have it.167-src/strlcpy.c - for systems that don't have it.168+src/mygetopt.h - replacement for OS's that don't have it.169+src/strcasestr.c - replacement for OS's that don't have it.170+src/strlcat.c - replacement for OS's that don't have it.171+src/strlcpy.c - replacement for OS's that don't have it.172+src/tar.h - tar file definitions173src/vasprintf.c - for systems that don't have it.174doc/file.man - man page for the command175doc/magic.man - man page for the magic file, courtesy Guy Harris.176Index: contrib/file/TODO177===================================================================178--- contrib/file/TODO (revision 284174)179+++ contrib/file/TODO (working copy)180@@ -15,3 +15,5 @@ small amount of C is needed (because fast executio181required for soft magic, not the more detailed information given by182hard-wired routines). In this regard, note that hplip, which is183BSD-licensed, has a magic reimplementation in Python.184+185+Read the kerberos magic entry for more ideas.186Index: contrib/file/config.h.in187===================================================================188--- contrib/file/config.h.in (revision 284174)189+++ contrib/file/config.h.in (working copy)190@@ -44,6 +44,9 @@191/* Define to 1 if you have the `fork' function. */192#undef HAVE_FORK193194+/* Define to 1 if you have the `freelocale' function. */195+#undef HAVE_FREELOCALE196+197/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */198#undef HAVE_FSEEKO199200@@ -95,9 +98,15 @@201/* Define to 1 if you have a working `mmap' system call. */202#undef HAVE_MMAP203204+/* Define to 1 if you have the `newlocale' function. */205+#undef HAVE_NEWLOCALE206+207/* Define to 1 if you have the `pread' function. */208#undef HAVE_PREAD209210+/* Define to 1 if you have the `setlocale' function. */211+#undef HAVE_SETLOCALE212+213/* Define to 1 if you have the <stddef.h> header file. */214#undef HAVE_STDDEF_H215216@@ -182,6 +191,9 @@217/* Define to 1 if you have the <unistd.h> header file. */218#undef HAVE_UNISTD_H219220+/* Define to 1 if you have the `uselocale' function. */221+#undef HAVE_USELOCALE222+223/* Define to 1 if you have the `utime' function. */224#undef HAVE_UTIME225226@@ -219,6 +231,9 @@227/* Define to 1 if `vfork' works. */228#undef HAVE_WORKING_VFORK229230+/* Define to 1 if you have the <xlocale.h> header file. */231+#undef HAVE_XLOCALE_H232+233/* Define to 1 if you have the <zlib.h> header file. */234#undef HAVE_ZLIB_H235236Index: contrib/file/configure237===================================================================238--- contrib/file/configure (revision 284174)239+++ contrib/file/configure (working copy)240@@ -1,6 +1,6 @@241#! /bin/sh242# Guess values for system-dependent variables and create Makefiles.243-# Generated by GNU Autoconf 2.69 for file 5.19.244+# Generated by GNU Autoconf 2.69 for file 5.22.245#246# Report bugs to <[email protected]>.247#248@@ -590,8 +590,8 @@ MAKEFLAGS=249# Identity of this package.250PACKAGE_NAME='file'251PACKAGE_TARNAME='file'252-PACKAGE_VERSION='5.19'253-PACKAGE_STRING='file 5.19'254+PACKAGE_VERSION='5.22'255+PACKAGE_STRING='file 5.22'256PACKAGE_BUGREPORT='[email protected]'257PACKAGE_URL=''258259@@ -1327,7 +1327,7 @@ if test "$ac_init_help" = "long"; then260# Omit some internal or obsolete options to make the list less imposing.261# This message is too long to be a string in the A/UX 3.1 sh.262cat <<_ACEOF263-\`configure' configures file 5.19 to adapt to many kinds of systems.264+\`configure' configures file 5.22 to adapt to many kinds of systems.265266Usage: $0 [OPTION]... [VAR=VALUE]...267268@@ -1397,7 +1397,7 @@ fi269270if test -n "$ac_init_help"; then271case $ac_init_help in272- short | recursive ) echo "Configuration of file 5.19:";;273+ short | recursive ) echo "Configuration of file 5.22:";;274esac275cat <<\_ACEOF276277@@ -1507,7 +1507,7 @@ fi278test -n "$ac_init_help" && exit $ac_status279if $ac_init_version; then280cat <<\_ACEOF281-file configure 5.19282+file configure 5.22283generated by GNU Autoconf 2.69284285Copyright (C) 2012 Free Software Foundation, Inc.286@@ -2163,7 +2163,7 @@ cat >config.log <<_ACEOF287This file contains any messages produced by compilers while288running configure, to aid debugging if configure makes a mistake.289290-It was created by file $as_me 5.19, which was291+It was created by file $as_me 5.22, which was292generated by GNU Autoconf 2.69. Invocation command line was293294$ $0 $@295@@ -3029,7 +3029,7 @@ fi296297# Define the identity of the package.298PACKAGE='file'299- VERSION='5.19'300+ VERSION='5.22'301302303cat >>confdefs.h <<_ACEOF304@@ -12785,7 +12785,7 @@ fi305306done307308-for ac_header in getopt.h err.h309+for ac_header in getopt.h err.h xlocale.h310do :311as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`312ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"313@@ -14191,7 +14191,7 @@ fi314fi315316317-for ac_func in strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof318+for ac_func in strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale setlocale319do :320as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`321ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"322@@ -14998,7 +14998,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1323# report actual input values of CONFIG_FILES etc. instead of their324# values after options handling.325ac_log="326-This file was extended by file $as_me 5.19, which was327+This file was extended by file $as_me 5.22, which was328generated by GNU Autoconf 2.69. Invocation command line was329330CONFIG_FILES = $CONFIG_FILES331@@ -15064,7 +15064,7 @@ _ACEOF332cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1333ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"334ac_cs_version="\\335-file config.status 5.19336+file config.status 5.22337configured by $0, generated by GNU Autoconf 2.69,338with options \\"\$ac_cs_config\\"339340Index: contrib/file/configure.ac341===================================================================342--- contrib/file/configure.ac (revision 284174)343+++ contrib/file/configure.ac (working copy)344@@ -1,5 +1,5 @@345dnl Process this file with autoconf to produce a configure script.346-AC_INIT([file],[5.19],[[email protected]])347+AC_INIT([file],[5.22],[[email protected]])348AM_INIT_AUTOMAKE([subdir-objects foreign])349m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])350351@@ -82,7 +82,7 @@ AC_HEADER_MAJOR352AC_HEADER_SYS_WAIT353AC_CHECK_HEADERS(stdint.h fcntl.h locale.h stdint.h inttypes.h unistd.h)354AC_CHECK_HEADERS(stddef.h utime.h wchar.h wctype.h limits.h)355-AC_CHECK_HEADERS(getopt.h err.h)356+AC_CHECK_HEADERS(getopt.h err.h xlocale.h)357AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h)358AC_CHECK_HEADERS(zlib.h)359360@@ -138,7 +138,7 @@ else361fi])362363dnl Checks for functions364-AC_CHECK_FUNCS(strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof)365+AC_CHECK_FUNCS(strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale setlocale)366367dnl Provide implementation of some required functions if necessary368AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r pread strcasestr fmtcheck)369Index: contrib/file/doc/file.man370===================================================================371--- contrib/file/doc/file.man (revision 284174)372+++ contrib/file/doc/file.man (working copy)373@@ -1,5 +1,5 @@374-.\" $File: file.man,v 1.106 2014/03/07 23:11:51 christos Exp $375-.Dd January 30, 2014376+.\" $File: file.man,v 1.111 2014/12/16 23:18:40 christos Exp $377+.Dd December 16, 2014378.Dt FILE __CSECTION__379.Os380.Sh NAME381@@ -16,6 +16,7 @@382.Op Fl F Ar separator383.Op Fl f Ar namefile384.Op Fl m Ar magicfiles385+.Op Fl P Ar name=value386.Ar387.Ek388.Nm389@@ -303,6 +304,16 @@ or390attempt to preserve the access time of files analyzed, to pretend that391.Nm392never read them.393+.It Fl P , Fl Fl parameter Ar name=value394+Set various parameter limits.395+.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent396+.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation"397+.It Li indir Ta 15 Ta recursion limit for indirect magic398+.It Li name Ta 30 Ta use count limit for name/use magic399+.It Li elf_notes Ta 256 Ta max ELF notes processed400+.It Li elf_phnum Ta 128 Ta max ELF program sections processed401+.It Li elf_shnum Ta 32768 Ta max ELF sections processed402+.El403.It Fl r , Fl Fl raw404Don't translate unprintable characters to \eooo.405Normally406@@ -385,6 +396,7 @@ options.407.Xr hexdump 1 ,408.Xr od 1 ,409.Xr strings 1 ,410+.Xr fstyp 8411.Sh STANDARDS CONFORMANCE412This program is believed to exceed the System V Interface Definition413of FILE(CMD), as near as one can determine from the vague language414Index: contrib/file/doc/libmagic.man415===================================================================416--- contrib/file/doc/libmagic.man (revision 284174)417+++ contrib/file/doc/libmagic.man (working copy)418@@ -1,4 +1,4 @@419-.\" $File: libmagic.man,v 1.28 2014/03/02 14:47:16 christos Exp $420+.\" $File: libmagic.man,v 1.34 2014/12/16 23:18:40 christos Exp $421.\"422.\" Copyright (c) Christos Zoulas 2003.423.\" All Rights Reserved.424@@ -25,7 +25,7 @@425.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF426.\" SUCH DAMAGE.427.\"428-.Dd January 6, 2012429+.Dd December 16, 2014430.Dt LIBMAGIC 3431.Os432.Sh NAME433@@ -40,6 +40,9 @@434.Nm magic_compile ,435.Nm magic_list ,436.Nm magic_load ,437+.Nm magic_load_buffers ,438+.Nm magic_setparam ,439+.Nm magic_getparam ,440.Nm magic_version441.Nd Magic number recognition library442.Sh LIBRARY443@@ -71,6 +74,12 @@444.Ft int445.Fn magic_load "magic_t cookie" "const char *filename"446.Ft int447+.Fn magic_load_buffers "magic_t cookie" "void **buffers" "size_t *sizes" "size_t nbuffers"448+.Ft int449+.Fn magic_getparam "magic_t cookie" "int param" "void *value"450+.Ft int451+.Fn magic_setparam "magic_t cookie" "int param" "const void *value"452+.Ft int453.Fn magic_version "void"454.Sh DESCRIPTION455These functions456@@ -253,6 +262,60 @@ adds457to the database filename as appropriate.458.Pp459The460+.Fn magic_load_buffers461+function takes an array of size462+.Fa nbuffers463+of464+.Fa buffers465+with a respective size for each in the array of466+.Fa sizes467+loaded with the contents of the magic databases from the filesystem.468+This function can be used in environment where the magic library does469+not have direct access to the filesystem, but can access the magic470+database via shared memory or other IPC means.471+.Pp472+The473+.Fn magic_getparam474+and475+.Fn magic_setparam476+allow getting and setting various limits related to the the magic477+library.478+.Bl -column "MAGIC_PARAM_ELF_PHNUM_MAX" "size_t" "Default" -offset indent479+.It Sy "Parameter" Ta Sy "Type" Ta Sy "Default"480+.It Li MAGIC_PARAM_INDIR_MAX Ta size_t Ta 15481+.It Li MAGIC_PARAM_NAME_MAX Ta size_t Ta 30482+.It Li MAGIC_PARAM_ELF_NOTES_MAX Ta size_t Ta 256483+.It Li MAGIC_PARAM_ELF_PHNUM_MAX Ta size_t Ta 128484+.It Li MAGIC_PARAM_ELF_SHNUM_MAX Ta size_t Ta 32768485+.El486+.Pp487+The488+.Dv MAGIC_PARAM_INDIR_RECURSION489+parameter controls how many levels of recursion will be followed for490+indirect magic entries.491+.Pp492+The493+.Dv MAGIC_PARAM_NAME_RECURSION494+parameter controls how many levels of recursion will be followed for495+for name/use calls.496+.Pp497+The498+.Dv MAGIC_PARAM_NAME_MAX499+parameter controls the maximum number of calls for name/use.500+.Pp501+The502+.Dv MAGIC_PARAM_NOTES_MAX503+parameter controls how many ELF notes will be processed.504+.Pp505+The506+.Dv MAGIC_PARAM_PHNUM_MAX507+parameter controls how many ELF program sections will be processed.508+.Pp509+The510+.Dv MAGIC_PARAM_SHNUM_MAX511+parameter controls how many ELF sections will be processed.512+.Pp513+The514.Fn magic_version515command returns the version number of this library which is compiled into516the shared library using the constant517Index: contrib/file/doc/magic.man518===================================================================519--- contrib/file/doc/magic.man (revision 284174)520+++ contrib/file/doc/magic.man (working copy)521@@ -1,5 +1,5 @@522-.\" $File: magic.man,v 1.84 2014/06/03 19:01:34 christos Exp $523-.Dd June 3, 2014524+.\" $File: magic.man,v 1.85 2015/01/01 17:07:34 christos Exp $525+.Dd January 1, 2015526.Dt MAGIC __FSECTION__527.Os528.\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems.529@@ -200,6 +200,11 @@ interpreted as a UNIX-style date, but interpreted530than UTC.531.It Dv indirect532Starting at the given offset, consult the magic database again.533+The offset of th534+.Dv indirect535+magic is by default absolute in the file, but one can specify536+.Dv /r537+to indicate that the offset is relative from the beginning of the entry.538.It Dv name539Define a540.Dq named541Index: contrib/file/magic/Magdir/android542===================================================================543--- contrib/file/magic/Magdir/android (revision 284174)544+++ contrib/file/magic/Magdir/android (working copy)545@@ -1,6 +1,6 @@546547#------------------------------------------------------------548-# $File: android,v 1.4 2014/06/03 19:01:34 christos Exp $549+# $File: android,v 1.7 2014/11/10 05:08:23 christos Exp $550# Various android related magic entries551#------------------------------------------------------------552553@@ -15,20 +15,11 @@554>0 regex dey\n[0-9]{2}\0 Dalvik dex file (optimized for host)555>4 string >000 version %s556557-# http://android.stackexchange.com/questions/23357/\558-# is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file/\559-# 23608#23608560-0 string ANDROID\040BACKUP\n Android Backup561->15 string 1\n \b, version 1562->17 string 0\n \b, uncompressed563->17 string 1\n \b, compressed564->19 string none\n \b, unencrypted565->19 string AES-256\n \b, encrypted AES-256566-567# Android bootimg format568# From https://android.googlesource.com/\569# platform/system/core/+/master/mkbootimg/bootimg.h5700 string ANDROID! Android bootimg571+>1024 string LOKI\01 \b, LOKI'd572>8 lelong >0 \b, kernel573>>12 lelong >0 \b (0x%x)574>16 lelong >0 \b, ramdisk575@@ -38,41 +29,7 @@576>36 lelong >0 \b, page size: %d577>38 string >0 \b, name: %s578>64 string >0 \b, cmdline (%s)579-# Dalvik .dex format. http://retrodev.com/android/dexformat.html580-# From <[email protected]> "Mike Fleming"581-# Fixed to avoid regexec 17 errors on some dex files582-# From <[email protected]> "Tim Strazzere"583-0 string dex\n584->0 regex dex\n[0-9]{2}\0 Dalvik dex file585->4 string >000 version %s586-0 string dey\n587->0 regex dey\n[0-9]{2}\0 Dalvik dex file (optimized for host)588->4 string >000 version %s589590-# http://android.stackexchange.com/questions/23357/\591-# is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file/\592-# 23608#23608593-0 string ANDROID\040BACKUP\n Android Backup594->15 string 1\n \b, version 1595->17 string 0\n \b, uncompressed596->17 string 1\n \b, compressed597->19 string none\n \b, unencrypted598->19 string AES-256\n \b, encrypted AES-256599-600-# Android bootimg format601-# From https://android.googlesource.com/\602-# platform/system/core/+/master/mkbootimg/bootimg.h603-0 string ANDROID! Android bootimg604->8 lelong >0 \b, kernel605->>12 lelong >0 \b (0x%x)606->16 lelong >0 \b, ramdisk607->>20 lelong >0 \b (0x%x)608->24 lelong >0 \b, second stage609->>28 lelong >0 \b (0x%x)610->36 lelong >0 \b, page size: %d611->38 string >0 \b, name: %s612->64 string >0 \b, cmdline (%s)613-614# Android Backup archive615# From: Ariel Shkedi616# File extension: .ab617@@ -98,3 +55,85 @@618#>>>>>&1 regex/1l .* \b, PBKDF2 rounds: %s619#>>>>>>&1 regex/1l .* \b, IV: %s620#>>>>>>>&1 regex/1l .* \b, Key: %s621+622+# *.pit files by Joerg Jenderek623+# http://forum.xda-developers.com/showthread.php?p=9122369624+# http://forum.xda-developers.com/showthread.php?t=816449625+# Partition Information Table for Samsung's smartphone with Android626+# used by flash software Odin627+0 ulelong 0x12349876628+# 1st pit entry marker629+>0x01C ulequad&0xFFFFFFFCFFFFFFFC =0x0000000000000000630+# minimal 13 and maximal 18 PIT entries found631+>>4 ulelong <128 Partition Information Table for Samsung smartphone632+>>>4 ulelong x \b, %d entries633+# 1. pit entry634+>>>4 ulelong >0 \b; #1635+>>>0x01C use PIT-entry636+>>>4 ulelong >1 \b; #2637+>>>0x0A0 use PIT-entry638+>>>4 ulelong >2 \b; #3639+>>>0x124 use PIT-entry640+>>>4 ulelong >3 \b; #4641+>>>0x1A8 use PIT-entry642+>>>4 ulelong >4 \b; #5643+>>>0x22C use PIT-entry644+>>>4 ulelong >5 \b; #6645+>>>0x2B0 use PIT-entry646+>>>4 ulelong >6 \b; #7647+>>>0x334 use PIT-entry648+>>>4 ulelong >7 \b; #8649+>>>0x3B8 use PIT-entry650+>>>4 ulelong >8 \b; #9651+>>>0x43C use PIT-entry652+>>>4 ulelong >9 \b; #10653+>>>0x4C0 use PIT-entry654+>>>4 ulelong >10 \b; #11655+>>>0x544 use PIT-entry656+>>>4 ulelong >11 \b; #12657+>>>0x5C8 use PIT-entry658+>>>4 ulelong >12 \b; #13659+>>>>0x64C use PIT-entry660+# 14. pit entry661+>>>4 ulelong >13 \b; #14662+>>>>0x6D0 use PIT-entry663+>>>4 ulelong >14 \b; #15664+>>>0x754 use PIT-entry665+>>>4 ulelong >15 \b; #16666+>>>0x7D8 use PIT-entry667+>>>4 ulelong >16 \b; #17668+>>>0x85C use PIT-entry669+# 18. pit entry670+>>>4 ulelong >17 \b; #18671+>>>0x8E0 use PIT-entry672+673+0 name PIT-entry674+# garbage value implies end of pit entries675+>0x00 ulequad&0xFFFFFFFCFFFFFFFC =0x0000000000000000676+# skip empty partition name677+>>0x24 ubyte !0678+# partition name679+>>>0x24 string >\0 %-.32s680+# flags681+>>>0x0C ulelong&0x00000002 2 \b+RW682+# partition ID:683+# 0~IPL,MOVINAND,GANG;1~PIT,GPT;2~HIDDEN;3~SBL,HIDDEN;4~SBL2,HIDDEN;5~BOOT;6~KENREl,RECOVER,misc;7~RECOVER684+# ;11~MODEM;20~efs;21~PARAM;22~FACTORY,SYSTEM;23~DBDATAFS,USERDATA;24~CACHE;80~BOOTLOADER;81~TZSW685+>>>0x08 ulelong x (0x%x)686+# filename687+>>>0x44 string >\0 "%-.64s"688+#>>>0x18 ulelong >0689+# blocksize in 512 byte units ?690+#>>>>0x18 ulelong x \b, %db691+# partition size in blocks ?692+#>>>>0x22 ulelong x \b*%d693+694+# Android bootimg format695+# From https://android.googlesource.com/\696+# platform/system/core/+/master/libsparse/sparse_format.h697+0 lelong 0xed26ff3a Android sparse image698+>4 leshort x \b, version: %d699+>6 leshort x \b.%d700+>16 lelong x \b, Total of %d701+>12 lelong x \b %d-byte output blocks in702+>20 lelong x \b %d input chunks.703Index: contrib/file/magic/Magdir/animation704===================================================================705--- contrib/file/magic/Magdir/animation (revision 284174)706+++ contrib/file/magic/Magdir/animation (working copy)707@@ -1,6 +1,6 @@708709#------------------------------------------------------------------------------710-# $File: animation,v 1.53 2014/04/30 21:41:02 christos Exp $711+# $File: animation,v 1.56 2014/10/23 23:12:51 christos Exp $712# animation: file(1) magic for animation/movie formats713#714# animation formats715@@ -32,43 +32,155 @@716!:mime application/x-quicktime-player7174 string/W jP JPEG 2000 image718!:mime image/jp2719+# http://www.ftyps.com/ with local additions7204 string ftyp ISO Media721->8 string isom \b, MPEG v4 system, version 1722-!:mime video/mp4723->8 string iso2 \b, MPEG v4 system, part 12 revision724->8 string mp41 \b, MPEG v4 system, version 1725-!:mime video/mp4726->8 string mp42 \b, MPEG v4 system, version 2727-!:mime video/mp4728->8 string mp7t \b, MPEG v4 system, MPEG v7 XML729->8 string mp7b \b, MPEG v4 system, MPEG v7 binary XML730->8 string/W jp2 \b, JPEG 2000731-!:mime image/jp2732+>8 string 3g2 \b, MPEG v4 system, 3GPP2733+!:mime video/3gpp2734+>>11 byte 4 \b v4 (H.263/AMR GSM 6.10)735+>>11 byte 5 \b v5 (H.263/AMR GSM 6.10)736+>>11 byte 6 \b v6 (ITU H.264/AMR GSM 6.10)737+>>11 byte a \b C.S0050-0 V1.0738+>>11 byte b \b C.S0050-0-A V1.0.0739+>>11 byte c \b C.S0050-0-B V1.0740>8 string 3ge \b, MPEG v4 system, 3GPP741!:mime video/3gpp742+>>11 byte 6 \b, Release 6 MBMS Extended Presentations743+>>11 byte 7 \b, Release 7 MBMS Extended Presentations744>8 string 3gg \b, MPEG v4 system, 3GPP745+>11 byte 6 \b, Release 6 General Profile746!:mime video/3gpp747>8 string 3gp \b, MPEG v4 system, 3GPP748+>11 byte 1 \b, Release %d (non existent)749+>11 byte 2 \b, Release %d (non existent)750+>11 byte 3 \b, Release %d (non existent)751+>11 byte 4 \b, Release %d752+>11 byte 5 \b, Release %d753+>11 byte 6 \b, Release %d754+>11 byte 7 \b, Release %d Streaming Servers755!:mime video/3gpp756>8 string 3gs \b, MPEG v4 system, 3GPP757+>11 byte 7 \b, Release %d Streaming Servers758!:mime video/3gpp759->8 string 3g2 \b, MPEG v4 system, 3GPP2760+>8 string avc1 \b, MPEG v4 system, 3GPP JVT AVC [ISO 14496-12:2005]761+!:mime video/mp4762+>8 string/W qt \b, Apple QuickTime movie763+!:mime video/quicktime764+>8 string CAEP \b, Canon Digital Camera765+>8 string caqv \b, Casio Digital Camera766+>8 string CDes \b, Convergent Design767+>8 string da0a \b, DMB MAF w/ MPEG Layer II aud, MOT slides, DLS, JPG/PNG/MNG768+>8 string da0b \b, DMB MAF, ext DA0A, with 3GPP timed text, DID, TVA, REL, IPMP769+>8 string da1a \b, DMB MAF audio with ER-BSAC audio, JPG/PNG/MNG images770+>8 string da1b \b, DMB MAF, ext da1a, with 3GPP timed text, DID, TVA, REL, IPMP771+>8 string da2a \b, DMB MAF aud w/ HE-AAC v2 aud, MOT slides, DLS, JPG/PNG/MNG772+>8 string da2b \b, DMB MAF, ext da2a, with 3GPP timed text, DID, TVA, REL, IPMP773+>8 string da3a \b, DMB MAF aud with HE-AAC aud, JPG/PNG/MNG images774+>8 string da3b \b, DMB MAF, ext da3a w/ BIFS, 3GPP, DID, TVA, REL, IPMP775+>8 string dmb1 \b, DMB MAF supporting all the components defined in the spec776+>8 string dmpf \b, Digital Media Project777+>8 string drc1 \b, Dirac (wavelet compression), encap in ISO base media (MP4)778+>8 string dv1a \b, DMB MAF vid w/ AVC vid, ER-BSAC aud, BIFS, JPG/PNG/MNG, TS779+>8 string dv1b \b, DMB MAF, ext dv1a, with 3GPP timed text, DID, TVA, REL, IPMP780+>8 string dv2a \b, DMB MAF vid w/ AVC vid, HE-AAC v2 aud, BIFS, JPG/PNG/MNG, TS781+>8 string dv2b \b, DMB MAF, ext dv2a, with 3GPP timed text, DID, TVA, REL, IPMP782+>8 string dv3a \b, DMB MAF vid w/ AVC vid, HE-AAC aud, BIFS, JPG/PNG/MNG, TS783+>8 string dv3b \b, DMB MAF, ext dv3a, with 3GPP timed text, DID, TVA, REL, IPMP784+>8 string dvr1 \b, DVB (.DVB) over RTP785+!:mime video/vnd.dvb.file786+>8 string dvt1 \b, DVB (.DVB) over MPEG-2 Transport Stream787+!:mime video/vnd.dvb.file788+>8 string F4V \b, Video for Adobe Flash Player 9+ (.F4V)789+!:mime video/mp4790+>8 string F4P \b, Protected Video for Adobe Flash Player 9+ (.F4P)791+!:mime video/mp4792+>8 string F4A \b, Audio for Adobe Flash Player 9+ (.F4A)793+!:mime audio/mp4794+>8 string F4B \b, Audio Book for Adobe Flash Player 9+ (.F4B)795+!:mime audio/mp4796+>8 string isc2 \b, ISMACryp 2.0 Encrypted File797+# ?/enc-isoff-generic798+>8 string iso2 \b, MP4 Base Media v2 [ISO 14496-12:2005]799+!:mime video/mp4800+>8 string isom \b, MP4 Base Media v1 [IS0 14496-12:2003]801+!:mime video/mp4802+>8 string/W jp2 \b, JPEG 2000803+!:mime image/jp2804+>8 string JP2 \b, JPEG 2000 Image (.JP2) [ISO 15444-1 ?]805+!:mime image/jp2806+>8 string JP20 \b, Unknown, from GPAC samples (prob non-existent)807+>8 string jpm \b, JPEG 2000 Compound Image (.JPM) [ISO 15444-6]808+!:mime image/jpm809+>8 string jpx \b, JPEG 2000 w/ extensions (.JPX) [ISO 15444-2]810+!:mime image/jpx811+>8 string KDDI \b, 3GPP2 EZmovie for KDDI 3G cellphones812!:mime video/3gpp2813->>11 byte 4 \b v4 (H.263/AMR GSM 6.10)814->>11 byte 5 \b v5 (H.263/AMR GSM 6.10)815->>11 byte 6 \b v6 (ITU H.264/AMR GSM 6.10)816+>8 string M4A \b, Apple iTunes ALAC/AAC-LC (.M4A) Audio817+!:mime audio/x-m4a818+>8 string M4B \b, Apple iTunes ALAC/AAC-LC (.M4B) Audio Book819+!:mime audio/mp4820+>8 string M4P \b, Apple iTunes ALAC/AAC-LC (.M4P) AES Protected Audio821+!:mime video/mp4822+>8 string M4V \b, Apple iTunes Video (.M4V) Video823+!:mime video/x-m4v824+>8 string M4VH \b, Apple TV (.M4V)825+!:mime video/x-m4v826+>8 string M4VP \b, Apple iPhone (.M4V)827+!:mime video/x-m4v828+>8 string mj2s \b, Motion JPEG 2000 [ISO 15444-3] Simple Profile829+!:mime video/mj2830+>8 string mjp2 \b, Motion JPEG 2000 [ISO 15444-3] General Profile831+!:mime video/mj2832+>8 string mmp4 \b, MPEG-4/3GPP Mobile Profile (.MP4 / .3GP) (for NTT)833+!:mime video/mp4834+>8 string mobi \b, MPEG-4, MOBI format835+!:mime video/mp4836+>8 string mp21 \b, MPEG-21 [ISO/IEC 21000-9]837+>8 string mp41 \b, MP4 v1 [ISO 14496-1:ch13]838+!:mime video/mp4839+>8 string mp42 \b, MP4 v2 [ISO 14496-14]840+!:mime video/mp4841+>8 string mp71 \b, MP4 w/ MPEG-7 Metadata [per ISO 14496-12]842+>8 string mp7t \b, MPEG v4 system, MPEG v7 XML843+>8 string mp7b \b, MPEG v4 system, MPEG v7 binary XML844>8 string mmp4 \b, MPEG v4 system, 3GPP Mobile845!:mime video/mp4846->8 string avc1 \b, MPEG v4 system, 3GPP JVT AVC847-!:mime video/3gpp848->8 string/W M4A \b, MPEG v4 system, iTunes AAC-LC849+>8 string MPPI \b, Photo Player, MAF [ISO/IEC 23000-3]850+>8 string mqt \b, Sony / Mobile QuickTime (.MQV) US Pat 7,477,830851+!:mime video/quicktime852+>8 string MSNV \b, MPEG-4 (.MP4) for SonyPSP853!:mime audio/mp4854->8 string/W M4V \b, MPEG v4 system, iTunes AVC-LC855+>8 string NDAS \b, MP4 v2 [ISO 14496-14] Nero Digital AAC Audio856+!:mime audio/mp4857+>8 string NDSC \b, MPEG-4 (.MP4) Nero Cinema Profile858!:mime video/mp4859->8 string/W M4P \b, MPEG v4 system, iTunes AES encrypted860->8 string/W M4B \b, MPEG v4 system, iTunes bookmarked861->8 string/W qt \b, Apple QuickTime movie862+>8 string NDSH \b, MPEG-4 (.MP4) Nero HDTV Profile863+!:mime video/mp4864+>8 string NDSM \b, MPEG-4 (.MP4) Nero Mobile Profile865+!:mime video/mp4866+>8 string NDSP \b, MPEG-4 (.MP4) Nero Portable Profile867+!:mime video/mp4868+>8 string NDSS \b, MPEG-4 (.MP4) Nero Standard Profile869+!:mime video/mp4870+>8 string NDXC \b, H.264/MPEG-4 AVC (.MP4) Nero Cinema Profile871+!:mime video/mp4872+>8 string NDXH \b, H.264/MPEG-4 AVC (.MP4) Nero HDTV Profile873+!:mime video/mp4874+>8 string NDXM \b, H.264/MPEG-4 AVC (.MP4) Nero Mobile Profile875+!:mime video/mp4876+>8 string NDXP \b, H.264/MPEG-4 AVC (.MP4) Nero Portable Profile877+!:mime video/mp4878+>8 string NDXS \b, H.264/MPEG-4 AVC (.MP4) Nero Standard Profile879+!:mime video/mp4880+>8 string odcf \b, OMA DCF DRM Format 2.0 (OMA-TS-DRM-DCF-V2_0-20060303-A)881+>8 string opf2 \b, OMA PDCF DRM Format 2.1 (OMA-TS-DRM-DCF-V2_1-20070724-C)882+>8 string opx2 \b, OMA PDCF DRM + XBS ext (OMA-TS-DRM_XBS-V1_0-20070529-C)883+>8 string pana \b, Panasonic Digital Camera884+>8 string qt \b, Apple QuickTime (.MOV/QT)885!:mime video/quicktime886+>8 string ROSS \b, Ross Video887+>8 string sdv \b, SD Memory Card Video888+>8 string ssc1 \b, Samsung stereo, single stream (patent pending)889+>8 string ssc2 \b, Samsung stereo, dual stream (patent pending)890891# MPEG sequences892# Scans for all common MPEG header start codes893Index: contrib/file/magic/Magdir/archive894===================================================================895--- contrib/file/magic/Magdir/archive (revision 284174)896+++ contrib/file/magic/Magdir/archive (working copy)897@@ -1,5 +1,5 @@898#------------------------------------------------------------------------------899-# $File: archive,v 1.87 2014/06/03 19:15:58 christos Exp $900+# $File: archive,v 1.88 2014/08/16 10:42:17 christos Exp $901# archive: file(1) magic for archive formats (see also "msdos" for self-902# extracting compressed archives)903#904@@ -954,34 +954,3 @@905>0xE08 search/7776 \x55\xAA906>>&-512 indirect x \b; contains907908-# Symantec GHOST image by Joerg Jenderek at May 2014909-# http://us.norton.com/ghost/910-# http://www.garykessler.net/library/file_sigs.html911-0 ubelong&0xFFFFf7f0 0xFEEF0100 Norton GHost image912-# *.GHO913->2 ubyte&0x08 0x00 \b, first file914-# *.GHS or *.[0-9] with cns program option915->2 ubyte&0x08 0x08 \b, split file916-# part of split index interesting for *.ghs917->>4 ubyte x id=0x%x918-# compression tag minus one equals numeric compression command line switch z[1-9]919->3 ubyte 0 \b, no compression920->3 ubyte 2 \b, fast compression (Z1)921->3 ubyte 3 \b, medium compression (Z2)922->3 ubyte >3923->>3 ubyte <11 \b, compression (Z%d-1)924->2 ubyte&0x08 0x00925-# ~ 30 byte password field only for *.gho926->>12 ubequad !0 \b, password protected927->>44 ubyte !1928-# 1~Image All, sector-by-sector only for *.gho929->>>10 ubyte 1 \b, sector copy930-# 1~Image Boot track only for *.gho931->>>43 ubyte 1 \b, boot track932-# 1~Image Disc only for *.gho implies Image Boot track and sector copy933->>44 ubyte 1 \b, disc sector copy934-# optional image description only *.gho935->>0xff string >\0 "%-.254s"936-# look for DOS sector end sequence937->0xE08 search/7776 \x55\xAA938->>&-512 indirect x \b; contains939Index: contrib/file/magic/Magdir/blender940===================================================================941--- contrib/file/magic/Magdir/blender (revision 284174)942+++ contrib/file/magic/Magdir/blender (working copy)943@@ -1,6 +1,6 @@944945#------------------------------------------------------------------------------946-# $File: blender,v 1.5 2009/09/19 16:28:08 christos Exp $947+# $File: blender,v 1.6 2014/08/30 08:34:17 christos Exp $948# blender: file(1) magic for Blender 3D related files949#950# Native format rule v1.2. For questions use the developers list951@@ -35,5 +35,5 @@952>>>0x44 string =GLOB \b.953>>>>0x60 beshort x \b%.4d954955-# Scripts that run in the embeded Python interpreter956+# Scripts that run in the embedded Python interpreter9570 string #!BPY Blender3D BPython script958Index: contrib/file/magic/Magdir/cafebabe959===================================================================960--- contrib/file/magic/Magdir/cafebabe (revision 284174)961+++ contrib/file/magic/Magdir/cafebabe (working copy)962@@ -1,6 +1,6 @@963964#------------------------------------------------------------------------------965-# $File: cafebabe,v 1.16 2014/04/30 21:41:02 christos Exp $966+# $File: cafebabe,v 1.17 2015/01/01 17:07:00 christos Exp $967# Cafe Babes unite!968#969# Since Java bytecode and Mach-O universal binaries have the same magic number,970@@ -45,7 +45,7 @@9719720 name mach-o \b [973>0 use mach-o-cpu \b974->&(8.L) indirect \b:975+>(8.L) indirect \b:976>0 belong x \b]9779780 belong 0xcafebabe979Index: contrib/file/magic/Magdir/commands980===================================================================981--- contrib/file/magic/Magdir/commands (revision 284174)982+++ contrib/file/magic/Magdir/commands (working copy)983@@ -1,6 +1,6 @@984985#------------------------------------------------------------------------------986-# $File: commands,v 1.50 2014/05/30 16:48:44 christos Exp $987+# $File: commands,v 1.51 2014/09/27 00:12:55 christos Exp $988# commands: file(1) magic for various shells and interpreters989#990#0 string/w : shell archive or script for antique kernel text991@@ -56,7 +56,7 @@992!:mime text/x-awk9930 string/wt #!\ /usr/bin/awk awk script text executable994!:mime text/x-awk995-0 regex/4096 =^\\s{0,100}BEGIN\\s{0,100}[{] awk script text996+0 regex/4096 =^\\s{0,100}BEGIN\\s{0,100}[{] awk or perl script text997998# AT&T Bell Labs' Plan 9 shell9990 string/wt #!\ /bin/rc Plan 9 rc shell script text executable1000Index: contrib/file/magic/Magdir/compress1001===================================================================1002--- contrib/file/magic/Magdir/compress (revision 284174)1003+++ contrib/file/magic/Magdir/compress (working copy)1004@@ -1,5 +1,5 @@1005#------------------------------------------------------------------------------1006-# $File: compress,v 1.58 2014/05/07 19:36:59 christos Exp $1007+# $File: compress,v 1.62 2014/09/13 14:27:12 christos Exp $1008# compress: file(1) magic for pure-compression formats (no archives)1009#1010# compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, etc.1011@@ -251,3 +251,13 @@1012# http://code.google.com/p/snappy/source/browse/trunk/framing_format.txt10130 string \377\006\0\0sNaPpY snappy framed data1014!:mime application/x-snappy-framed1015+1016+# qpress, http://www.quicklz.com/1017+0 string qpress10 qpress compressed data1018+!:mime application/x-qpress1019+1020+# Zlib https://www.ietf.org/rfc/rfc6713.txt1021+0 beshort%31 =01022+>0 byte&0xf =81023+>>0 byte&0x80 =0 zlib compressed data1024+!:mime application/zlib1025Index: contrib/file/magic/Magdir/database1026===================================================================1027--- contrib/file/magic/Magdir/database (revision 284174)1028+++ contrib/file/magic/Magdir/database (working copy)1029@@ -1,6 +1,6 @@10301031#------------------------------------------------------------------------------1032-# $File: database,v 1.41 2014/06/03 19:17:27 christos Exp $1033+# $File: database,v 1.43 2014/10/28 15:47:39 christos Exp $1034# database: file(1) magic for various databases1035#1036# extracted from header/code files by Graeme Wilford ([email protected])1037@@ -9,10 +9,18 @@1038# GDBM magic numbers1039# Will be maintained as part of the GDBM distribution in the future.1040# <[email protected]>1041-0 belong 0x13579ace GNU dbm 1.x or ndbm database, big endian1042+0 belong 0x13579acd GNU dbm 1.x or ndbm database, big endian, 32-bit1043!:mime application/x-gdbm1044-0 lelong 0x13579ace GNU dbm 1.x or ndbm database, little endian1045+0 belong 0x13579ace GNU dbm 1.x or ndbm database, big endian, old1046!:mime application/x-gdbm1047+0 belong 0x13579acf GNU dbm 1.x or ndbm database, big endian, 64-bit1048+!:mime application/x-gdbm1049+0 lelong 0x13579acd GNU dbm 1.x or ndbm database, little endian, 32-bit1050+!:mime application/x-gdbm1051+0 lelong 0x13579ace GNU dbm 1.x or ndbm database, little endian, old1052+!:mime application/x-gdbm1053+0 lelong 0x13579acf GNU dbm 1.x or ndbm database, little endian, 64-bit1054+!:mime application/x-gdbm10550 string GDBM GNU dbm 2.x database1056!:mime application/x-gdbm1057#1058@@ -202,27 +210,27 @@1059# for multiple index files (*.MDX) Production flag,tag numbers(<=0x30),tag length(<=0x20), reserverd (NULL)1060>>>>>>>24 ubelong&0x0133f7ff >01061# test for reserved NULL byte1062->>>>>>>>47 ubyte x1063+>>>>>>>>47 ubyte 01064# test for valid TAG key format (0x10 or 0)1065>>>>>>>>>559 ubyte&0xeF 01066# test MM <= 121067->>>>>>>>>45 ubeshort <0x0C201068->>>>>>>>>>45 ubyte >01069->>>>>>>>>>>46 ubyte <321070->>>>>>>>>>>>46 ubyte >01071+>>>>>>>>>>45 ubeshort <0x0C201072+>>>>>>>>>>>45 ubyte >01073+>>>>>>>>>>>>46 ubyte <321074+>>>>>>>>>>>>>46 ubyte >01075#!:mime application/x-mdx1076->>>>>>>>>>>>>0 use xbase-type1077->>>>>>>>>>>>>0 ubyte x \b MDX1078->>>>>>>>>>>>>1 ubyte x \b, creation-date1079->>>>>>>>>>>>>1 use xbase-date1080->>>>>>>>>>>>>44 ubyte x \b, update-date1081->>>>>>>>>>>>>44 use xbase-date1082+>>>>>>>>>>>>>>0 use xbase-type1083+>>>>>>>>>>>>>>0 ubyte x \b MDX1084+>>>>>>>>>>>>>>1 ubyte x \b, creation-date1085+>>>>>>>>>>>>>>1 use xbase-date1086+>>>>>>>>>>>>>>44 ubyte x \b, update-date1087+>>>>>>>>>>>>>>44 use xbase-date1088# No.of tags in use (1,2,5,12)1089->>>>>>>>>>>>>28 uleshort x \b, %d1090+>>>>>>>>>>>>>>28 uleshort x \b, %d1091# No. of entries in tag (0x30)1092->>>>>>>>>>>>>25 ubyte x \b/%d tags1093+>>>>>>>>>>>>>>25 ubyte x \b/%d tags1094# Length of tag1095->>>>>>>>>>>>>26 ubyte x * %d1096+>>>>>>>>>>>>>>26 ubyte x * %d1097# 1st tag name_1098>>>>>>>>>>>>>548 string x \b, 1st tag "%.11s"1099# 2nd tag name1100@@ -337,60 +345,103 @@1101# dBASE III1102>>>>>>16 ubyte 31103# dBASE III DBT1104->>>>>>>0 use xbase-memo-print1105-# dBASE IV DBT , FoxPro FPT or many PNG , ZIP , DBF garbage1106+>>>>>>>0 use dbase3-memo-print1107+# dBASE III DBT without version, dBASE IV DBT , FoxPro FPT , or many ZIP , DBF garbage1108>>>>>>16 ubyte 01109-# dBASE IV DBT with DBF name or DBF garbage1110->>>>>>>8 ubelong >0x400000001111-# skip DBF and catch dBASE IV DBT with DBF name and with non big index of next free block1112->>>>>>>>0 ulelong <0x010100021113->>>>>>>>>0 use xbase-memo-print1114->>>>>>>8 ubelong 01115+# unusual dBASE III DBT like angest.dbt, dBASE IV DBT with block size 0 , FoxPro FPT , or garbage PCX DBF1116+>>>>>>>20 uleshort 01117+# FoxPro FPT , unusual dBASE III DBT like biblio.dbt or garbage1118+>>>>>>>>8 ulong =01119+>>>>>>>>>6 ubeshort >01120+# skip emacs.PIF1121+>>>>>>>>>>4 ushort 01122+>>>>>>>>>>>0 use foxpro-memo-print1123+# dBASE III DBT , garbage1124+>>>>>>>>>6 ubeshort 01125# skip MM*DD*.bin by test for for reserved NULL byte1126->>>>>>>>508 ubelong 01127-# real memo files should contain text here1128->>>>>>>>>520 ubelong >0x202020191129->>>>>>>>>>520 ubelong <0xFEFEFEFF1130->>>>>>>>>>>0 use xbase-memo-print1131-# garbage PCX , ZIP , JAR , XPI1132->>>>>>>8 default x1133+>>>>>>>>>>510 ubeshort 01134+# skip TK-DOS11.img image by looking for memo text1135+>>>>>>>>>>>512 ubelong <0xfeffff031136+# skip EFI executables by looking for memo text1137+>>>>>>>>>>>>512 ubelong >0x1F2020201138+>>>>>>>>>>>>>513 ubyte >01139+# unusual dBASE III DBT like adressen.dbt1140+>>>>>>>>>>>>>>0 use dbase3-memo-print1141+# dBASE III DBT like angest.dbt, or garbage PCX DBF1142+>>>>>>>>8 ubelong !01143+# skip PCX and some DBF by test for for reserved NULL bytes1144+>>>>>>>>>510 ubeshort 01145+# skip some DBF by test of invalid version1146+>>>>>>>>>>0 ubyte >51147+>>>>>>>>>>>0 ubyte <481148+>>>>>>>>>>>>0 use dbase3-memo-print1149+# dBASE IV DBT with positive block size1150+>>>>>>>20 uleshort >01151+>>>>>>>>0 use dbase4-memo-print11521153-# Print the information of dBase DBT or FoxPro FPT memo files1154-0 name xbase-memo-print1155->0 ubyte x1156-# test version1157-# memo file1158->>16 ubyte 3 dBase III DBT1159->>16 ubyte 01160->>>512 ubelong <0x00000003 FoxPro FPT1161-# Size of blocks for FoxPro1162->>>>6 ubeshort x \b, blocks size %u1163-# Number of next available block for appending data for FoxPro1164->>>>0 ubelong =0 \b, next free block index %u1165->>>>0 ubelong !0 \b, next free block index %u1166->>>512 default x dBase IV DBT1167-# DBF file name without extension1168->>>>8 string >\0 \b of %-.8s.DBF1169-# size of blocks ; not reliable 0x2020204C1170-#>>>>4 ulelong =0 \b, blocks size %u1171->>>>4 ulelong !0 \b, blocks size %u1172-# Block length found 0 , 5121173-#>>>>20 uleshort =0 \b, block length %u1174->>>>20 uleshort !0 \b, block length %u1175+# Print the information of dBase III DBT memo file1176+0 name dbase3-memo-print1177+>0 ubyte x dBase III DBT1178+# instead 3 as version number 0 for unusual examples like biblio.dbt1179+>16 ubyte !3 \b, version number %u1180# Number of next available block for appending data1181->>>>0 ulelong =0 \b, next free block index %u1182->>>>0 ulelong !0 \b, next free block index %u1183->>512 ubelong x1184->>>512 ubelong =0xFFFF08001185->>>>520 string >\0 \b, 1st used item "%s"1186-# FoxPro1187->>>512 ubelong <31188-# FoxPro memo1189->>>>512 ubelong =11190->>>>520 string >\0 \b, 1st used item "%s"1191->>>512 default x1192-# may be deleted memo field1193->>>>512 string >\0 \b, 1st item "%s"1194+#>0 lelong =0 \b, next free block index %u1195+>0 lelong !0 \b, next free block index %u1196+# no positiv block length1197+#>20 uleshort =0 \b, block length %u1198+>20 uleshort !0 \b, block length %u1199+# dBase III memo field terminated by \032\0321200+>512 string >\0 \b, 1st item "%s"1201+# Print the information of dBase IV DBT memo file1202+0 name dbase4-memo-print1203+>0 lelong x dBase IV DBT1204+# 8 character shorted main name of coresponding dBASE IV DBF file1205+>8 ubelong >0x200000001206+# skip unusual like for angest.dbt1207+>>20 uleshort >01208+>>>8 string >\0 \b of %-.8s.DBF1209+# value 0 implies 512 as size1210+#>4 ulelong =0 \b, blocks size %u1211+# size of blocks not reliable like 0x2020204C in angest.dbt1212+>4 ulelong !01213+>>4 ulelong&0x0000003f 0 \b, blocks size %u1214+# dBase IV DBT with positive block length (found 512 , 1024)1215+>20 uleshort >0 \b, block length %u1216+# next available block1217+#>0 lelong =0 \b, next free block index %u1218+>0 lelong !0 \b, next free block index %u1219+>20 uleshort >01220+>>(20.s) ubelong x1221+>>>&-4 use dbase4-memofield-print1222+# unusual dBase IV DBT without block length (implies 512 as length)1223+>20 uleshort =01224+>>512 ubelong x1225+>>>&-4 use dbase4-memofield-print1226+# Print the information of dBase IV memo field1227+0 name dbase4-memofield-print1228+# free dBase IV memo field1229+>0 ubelong !0xFFFF08001230+>>0 lelong x \b, next free block %u1231+>>4 lelong x \b, next used block %u1232+# used dBase IV memo field1233+>0 ubelong =0xFFFF08001234+# length of memo field1235+>>4 lelong x \b, field length %d1236+>>>8 string >\0 \b, 1st used item "%s"1237+# Print the information of FoxPro FPT memo file1238+0 name foxpro-memo-print1239+>0 belong x FoxPro FPT1240+# Size of blocks for FoxPro ( 64,256 )1241+>6 ubeshort x \b, blocks size %u1242+# next available block1243+#>0 belong =0 \b, next free block index %u1244+>0 belong !0 \b, next free block index %u1245+# field type ( 0~picture, 1~memo, 2~object )1246+>512 ubelong <3 \b, field type %u1247+# length of memo field1248+>512 ubelong 11249+>>516 belong >0 \b, field length %d1250+>>>520 string >\0 \b, 1st item "%s"12511252# TODO:1253# DBASE index file *.NDX1254Index: contrib/file/magic/Magdir/elf1255===================================================================1256--- contrib/file/magic/Magdir/elf (revision 284174)1257+++ contrib/file/magic/Magdir/elf (working copy)1258@@ -1,6 +1,6 @@12591260#------------------------------------------------------------------------------1261-# $File: elf,v 1.67 2014/06/12 13:52:48 christos Exp $1262+# $File: elf,v 1.68 2014/09/19 19:05:57 christos Exp $1263# elf: file(1) magic for ELF executables1264#1265# We have to check the byte order flag to see what byte order all the1266@@ -257,6 +257,7 @@1267>18 leshort 216 Cognitive Smart Memory,1268>18 leshort 217 iCelero CoolEngine,1269>18 leshort 218 Nanoradio Optimized RISC,1270+>18 leshort 243 UCB RISC-V,1271>18 leshort 0x1057 AVR (unofficial),1272>18 leshort 0x1059 MSP430 (unofficial),1273>18 leshort 0x1223 Adapteva Epiphany (unofficial),1274Index: contrib/file/magic/Magdir/filesystems1275===================================================================1276--- contrib/file/magic/Magdir/filesystems (revision 284174)1277+++ contrib/file/magic/Magdir/filesystems (working copy)1278@@ -1,5 +1,5 @@1279#------------------------------------------------------------------------------1280-# $File: filesystems,v 1.95 2014/06/03 19:17:27 christos Exp $1281+# $File: filesystems,v 1.108 2015/01/01 17:43:47 christos Exp $1282# filesystems: file(1) magic for different filesystems1283#12840 name partid1285@@ -254,19 +254,20 @@128630 search/481 \x55\xAA1287# to display DOS/MBR boot sector (40) before old one (strength=50+21),Syslinux bootloader (71),SYSLINUX MBR (37+36),NetBSD mbr (110),AdvanceMAME mbr (111)1288# DOS BPB information (70) and after DOS floppy (120) like in previous file version1289-!:strength +721290+!:strength +651291# for sector sizes < 512 Bytes1292>11 uleshort <5121293>>(11.s-2) uleshort 0xAA55 DOS/MBR boot sector1294# for sector sizes with 512 or more Bytes1295>0x1FE leshort 0xAA55 DOS/MBR boot sector1296+1297# keep old DOS/MBR boot sector as dummy for mbr and bootloader displaying1298# only for sector sizes with 512 or more Bytes1299-0x1FE leshort 0xAA551300+0x1FE leshort 0xAA55 DOS/MBR boot sector1301#1302# to display information (50) before DOS BPB (strength=70) and after DOS floppy (120) like in old file version1303-!:strength +211304->2 string OSBS \b, OS/BS MBR1305+!:strength +651306+>2 string OSBS OS/BS MBR1307# added by Joerg Jenderek at Feb 2013 according to http://thestarman.pcministry.com/asm/mbr/1308# and http://en.wikipedia.org/wiki/Master_Boot_Record1309# test for nearly all MS-DOS Master Boot Record initial program loader (IPL) is now done by1310@@ -538,6 +539,8 @@1311>>>514 string !HdrS1312# not BeOS1313>>>>422 string !Be\ Boot\ Loader1314+>>>>>32769 string CD0011315+>>>>>>0 use cdrom1316# jump over BPB instruction implies DOS bootsector or AdvanceMAME mbr1317>>>>>0 ubelong&0xFD000000 =0xE90000001318# AdvanceMAME mbr1319@@ -1043,7 +1046,7 @@1320>>>>>>466 ubyte <0x101321>>>>>>>466 ubyte 0x05 \b, extended partition table1322>>>>>>>466 ubyte 0x0F \b, extended partition table (LBA)1323->>>>>>>466 ubyte 0x0 \b, extended partition table (last)1324+>>>>>>>466 ubyte 0x0 \b, extended partition table (last)13251326# DOS x86 sector separated and moved from "DOS/MBR boot sector" by Joerg Jenderek at May 201113271328@@ -1236,6 +1239,7 @@1329>>>>>181 search/166 Error\ \01330# "a: disk" , "Fn: diskn" or "NetBSD MBR boot"1331>>>>>>&3 string x \b,"%s"1332+>>>446 use partition-table1333# Andrea Mazzoleni AdvanceCD mbr loader of http://advancemame.sourceforge.net/boot-readme.html1334# added by Joerg Jenderek at Nov 2012 for versions 1.3 - 1.41335# assembler instructions: jmp short 0x58;nop;ASCII1336@@ -1353,18 +1357,19 @@1337# minimal short forward jump found 0x29 for bootloaders or 0x01338# maximal short forward jump is 0x7f1339# OEM-ID is empty or contain readable bytes1340-0 ulelong&0x804000E9 0x000000E91341+0 ulelong&0x804000E9 0x000000E91342+!:strength +601343# mtools-3.9.8/msdos.h1344# usual values are marked with comments to get only informations of strange FAT systems1345# valid sectorsize must be a power of 2 from 32 to 327681346->11 uleshort&0xf001f 01347+>11 uleshort&0x001f 01348>>11 uleshort <327691349>>>11 uleshort >311350>>>>21 ubyte&0xf0 0xF01351->>>>>0 ubyte 0xEB1352+>>>>>0 ubyte 0xEB DOS/MBR boot sector1353>>>>>>1 ubyte x \b, code offset 0x%x+21354>>>>>0 ubyte 0xE91355->>>>>>1 uleshort x \b, code offset 0x%x+21356+>>>>>>1 uleshort x \b, code offset 0x%x+31357>>>>>3 string >\0 \b, OEM-ID "%-.8s"1358#http://mirror.href.com/thestarman/asm/debug/debug2.htm#IHC1359>>>>>>8 string IHC \b cached by Windows 9M1360@@ -1373,10 +1378,11 @@1361>>>>>11 uleshort <512 \b, Bytes/sector %u1362>>>>>13 ubyte >1 \b, sectors/cluster %u1363#>>>>>13 ubyte =1 \b, sectors/cluster %u (usual on Floppies)1364->>>>>82 string FAT321365+# for lazy FAT32 implementation like Transcend digital photo frame PF8301366+>>>>>82 string/c fat321367>>>>>>14 uleshort !32 \b, reserved sectors %u1368#>>>>>>14 uleshort =32 \b, reserved sectors %u (usual Fat32)1369->>>>>82 string !FAT321370+>>>>>82 string/c !fat321371>>>>>>14 uleshort >1 \b, reserved sectors %u1372#>>>>>>14 uleshort =1 \b, reserved sectors %u (usual FAT12,FAT16)1373#>>>>>>14 uleshort 0 \b, reserved sectors %u (usual NTFS)1374@@ -1399,24 +1405,29 @@1375>>>>>26 ubyte =1 \b, heads %u1376# valid only for sector sizes with more then 32 Bytes1377>>>>>11 uleshort >321378-# skip for Digital Research DOS (version 3.41) 1440 kB Bootdisk1379->>>>>>38 ubyte !0x701380+# http://en.wikipedia.org/wiki/Design_of_the_FAT_file_system#Extended_BIOS_Parameter_Block1381+# skip for values 2,2Ah,70h,73h,DFh1382+# and continue for extended boot signature values 0,28h,29h,80h1383+>>>>>>38 ubyte&0x56 =01384>>>>>>>28 ulelong >0 \b, hidden sectors %u1385#>>>>>>>28 ulelong =0 \b, hidden sectors %u (usual floppy)1386>>>>>>>32 ulelong >0 \b, sectors %u (volumes > 32 MB)1387#>>>>>>>32 ulelong =0 \b, sectors %u (volumes > 32 MB)1388# FAT<32 bit specific1389->>>>>>>82 string !FAT321390+>>>>>>>82 string/c !fat321391#>>>>>>>>36 ubyte 0x80 \b, physical drive 0x%x=0x80 (usual harddisk)1392#>>>>>>>>36 ubyte 0 \b, physical drive 0x%x=0 (usual floppy)1393>>>>>>>>36 ubyte !0x801394>>>>>>>>>36 ubyte !0 \b, physical drive 0x%x1395+# VGA-copy CRC or1396+# in Windows NT bit 0 is a dirty flag to request chkdsk at boot time. bit 1 requests surface scan too1397>>>>>>>>37 ubyte >0 \b, reserved 0x%x1398#>>>>>>>>37 ubyte =0 \b, reserved 0x%x1399-# value is 0x80 for NTFS1400+# extended boot signatur value is 0x80 for NTFS, 0x28 or 0x29 for others1401>>>>>>>>38 ubyte !0x29 \b, dos < 4.0 BootSector (0x%x)1402+>>>>>>>>38 ubyte&0xFE =0x281403+>>>>>>>>>39 ulelong x \b, serial number 0x%x1404>>>>>>>>38 ubyte =0x291405->>>>>>>>>39 ulelong x \b, serial number 0x%x1406>>>>>>>>>43 string <NO\ NAME \b, label: "%11.11s"1407>>>>>>>>>43 string >NO\ NAME \b, label: "%11.11s"1408>>>>>>>>>43 string =NO\ NAME \b, unlabeled1409@@ -1426,11 +1437,35 @@1410# if it is small enough FAT is 12 bit, if it is too big enough FAT is 32 bit,1411# otherwise FAT is 16 bit.1412# http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/determining-fat-widths.html1413->>>>>>54 string FAT \b, FAT1414->>>>>>>54 string FAT12 \b (12 bit)1415->>>>>>>54 string FAT16 \b (16 bit)1416+>>>>>82 string/c !fat321417+>>>>>>54 string FAT12 \b, FAT (12 bit)1418+>>>>>>54 string FAT16 \b, FAT (16 bit)1419+>>>>>>54 default x1420+# determinate FAT bit size by media descriptor1421+# small floppies implies FAT121422+>>>>>>>21 ubyte <0xF0 \b, FAT (12 bit by descriptor)1423+# with media descriptor F0h floppy or maybe superfloppy with FAT161424+>>>>>>>21 ubyte =0xF01425+# superfloppy (many sectors) implies FAT161426+>>>>>>>>32 ulelong >0xFFFF \b, FAT (16 bit by descriptor+sectors)1427+# no superfloppy with media descriptor F0h implies FAT121428+>>>>>>>>32 default x \b, FAT (12 bit by descriptor+sectors)1429+# with media descriptor F8h floppy or hard disc with FAT12 or FAT161430+>>>>>>>21 ubyte =0xF81431+# 360 KiB with media descriptor F8h, 9 sectors per track ,single sided floppy implies FAT121432+>>>>>>>>19 ubequad 0xd002f80300090001 \b, FAT (12 bit by descriptor+geometry)1433+# hard disc with FAT12 or FAT161434+>>>>>>>>19 default x \b, FAT (1Y bit by descriptor)1435+# with media descriptor FAh floppy, RAM disc with FAT12 or FAT16 or Tandy hard disc1436+>>>>>>>21 ubyte =0xFA1437+# 320 KiB with media descriptor FAh, 8 sectors per track ,single sided floppy implies FAT121438+>>>>>>>>19 ubequad 0x8002fa0200080001 \b, FAT (12 bit by descriptor+geometry)1439+# RAM disc with FAT12 or FAT16 or Tandy hard disc1440+>>>>>>>>19 default x \b, FAT (1Y bit by descriptor)1441+# others are floppy1442+>>>>>>>21 default x \b, FAT (12 bit by descriptor)1443# FAT32 bit specific1444->>>>>82 string FAT32 \b, FAT (32 bit)1445+>>>>>82 string/c fat32 \b, FAT (32 bit)1446>>>>>>36 ulelong x \b, sectors/FAT %u1447# http://technet.microsoft.com/en-us/library/cc977221.aspx1448>>>>>>40 uleshort >0 \b, extension flags 0x%x1449@@ -1443,9 +1478,12 @@1450>>>>>>48 uleshort >1 \b, infoSector %u1451#>>>>>>48 uleshort =1 \b, infoSector %u (usual)1452>>>>>>48 uleshort <1 \b, infoSector %u1453->>>>>>50 uleshort >6 \b, Backup boot sector %u1454+# 0 or 0xFFFF instead of usual 6 means no backup sector1455+>>>>>>50 uleshort =0xFFFF \b, no Backup boot sector1456+>>>>>>50 uleshort =0 \b, no Backup boot sector1457#>>>>>>50 uleshort =6 \b, Backup boot sector %u (usual)1458->>>>>>50 uleshort <6 \b, Backup boot sector %u1459+>>>>>>50 default x1460+>>>>>>>50 uleshort x \b, Backup boot sector %u1461# corrected by Joerg Jenderek at Feb 2011 according to http://thestarman.pcministry.com/asm/mbr/MSWIN41.htm#FSINFO1462>>>>>>52 ulelong >0 \b, reserved1 0x%x1463>>>>>>56 ulelong >0 \b, reserved2 0x%x1464@@ -1880,12 +1918,11 @@1465# defect IO.SYS+MSDOS.SYS ?1466#>>>>>0x162 use 2xDOS-filename14671468-# CDROM Filesystems1469-# Modified for UDF by [email protected]1470-32769 string CD001 #1471+0 name cdrom1472+>38913 string !NSR0 ISO 9660 CD-ROM filesystem data1473!:mime application/x-iso9660-image1474->38913 string !NSR0 ISO 9660 CD-ROM filesystem data1475>38913 string NSR0 UDF filesystem data1476+!:mime application/x-iso9660-image1477>>38917 string 1 (version 1.0)1478>>38917 string 2 (version 1.5)1479>>38917 string 3 (version 2.0)1480@@ -1898,6 +1935,18 @@1481!:mime application/x-iso9660-image148232777 string CDROM High Sierra CD-ROM filesystem data14831484+# CDROM Filesystems1485+# https://en.wikipedia.org/wiki/ISO_96601486+# Modified for UDF by [email protected]1487+32769 string CD0011488+# mime line at that position does not work1489+# to display CD-ROM (70=81-11) after MBR (113=40+72+1), partition-table (71=50+21) and before Apple Driver Map (51)1490+!:strength -111491+# to display CD-ROM (114=81+33) before MBR (113=40+72+1), partition-table (71=50+21) and Apple Driver Map (51)1492+# does not work1493+#!:strength +331494+>0 use cdrom1495+1496# .cso files14970 string CISO Compressed ISO CD image14981499@@ -2080,6 +2129,7 @@1500#----------------------------------------------------------1501#delta ISO Daniel Novotny ([email protected])15020 string DISO Delta ISO data1503+!:strength +501504>4 belong x version %d15051506# VMS backup savesets - [email protected]1507@@ -2131,7 +2181,6 @@1508# which is mapped to VBN 2 of [000000]INDEXF.SYS;1 - [email protected]1509#15101008 string DECFILE11 Files-11 On-Disk Structure1511->525 byte x Level %d1512>525 byte x (ODS-%d);1513>1017 string A RSX-11, VAX/VMS or OpenVMS VAX file system;1514>1017 string B1515@@ -2266,14 +2315,31 @@15161517# UBIfs1518# Linux kernel sources: fs/ubifs/ubifs-media.h1519-0 belong 0x311810061520->0x16 short 0 UBIfs image1521->0x08 lequad x \b, sequence number %llu1522->0x10 leshort x \b, length %u1523->0x04 lelong x \b, CRC 0x%08x1524+0 lelong 0x061018311525+>0x16 leshort 0 UBIfs image1526+>0x08 lequad x \b, sequence number %llu1527+>0x10 leshort x \b, length %u1528+>0x04 lelong x \b, CRC 0x%08x15291530-0 belong 0x554249231531->0x04 short <21532->0x05 string \0\0\01533->0x1c string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01534->0x04 short x UBI image, version %u1535+0 lelong 0x234942551536+>0x04 leshort <21537+>0x05 string \0\0\01538+>0x1c string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01539+>0x04 leshort x UBI image, version %u1540+1541+# NEC PC-88 2D disk image1542+# From Fabio R. Schmidlin <[email protected]>1543+0x20 ulelong&0xFFFFFEFF 0x2A01544+>0x10 string \0\0\0\0\0\0\0\0\0\01545+>>0x280 string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01546+>>>0x1A ubyte&0xEF 01547+>>>>0x1B ubyte&0x8F 01548+>>>>>0x1B ubyte&70 <0x401549+>>>>>>0x1C ulelong >0x211550+>>>>>>>0 regex [[:print:]]* NEC PC-88 disk image, name=%s1551+>>>>>>>>0x1B ubyte 0 \b, media=2D1552+>>>>>>>>0x1B ubyte 0x10 \b, media=2DD1553+>>>>>>>>0x1B ubyte 0x20 \b, media=2HD1554+>>>>>>>>0x1B ubyte 0x30 \b, media=1D1555+>>>>>>>>0x1B ubyte 0x40 \b, media=1DD1556+>>>>>>>>0x1A ubyte 0x10 \b, write-protected1557Index: contrib/file/magic/Magdir/images1558===================================================================1559--- contrib/file/magic/Magdir/images (revision 284174)1560+++ contrib/file/magic/Magdir/images (working copy)1561@@ -1,6 +1,6 @@15621563#------------------------------------------------------------------------------1564-# $File: images,v 1.91 2014/04/30 21:41:02 christos Exp $1565+# $File: images,v 1.102 2015/01/02 02:36:35 christos Exp $1566# images: file(1) magic for image formats (see also "iff", and "c-lang" for1567# XPM bitmaps)1568#1569@@ -115,9 +115,154 @@1570# never changed. The TIFF specification recommends testing for it.15710 string MM\x00\x2a TIFF image data, big-endian1572!:mime image/tiff1573+>(4.L) use \^tiff_ifd15740 string II\x2a\x00 TIFF image data, little-endian1575!:mime image/tiff1576+>(4.l) use tiff_ifd15771578+0 name tiff_ifd1579+>0 leshort x \b, direntries=%d1580+>2 use tiff_entry1581+1582+0 name tiff_entry1583+# NewSubFileType1584+>0 leshort 0xfe1585+>>12 use tiff_entry1586+>0 leshort 0x1001587+>>4 lelong 11588+>>>12 use tiff_entry1589+>>>8 leshort x \b, width=%d1590+>0 leshort 0x1011591+>>4 lelong 11592+>>>8 leshort x \b, height=%d1593+>>>12 use tiff_entry1594+>0 leshort 0x1021595+>>8 leshort x \b, bps=%d1596+>>12 use tiff_entry1597+>0 leshort 0x1031598+>>4 lelong 1 \b, compression=1599+>>>8 leshort 1 \bnone1600+>>>8 leshort 2 \bhuffman1601+>>>8 leshort 3 \bbi-level group 31602+>>>8 leshort 4 \bbi-level group 41603+>>>8 leshort 5 \bLZW1604+>>>8 leshort 6 \bJPEG (old)1605+>>>8 leshort 7 \bJPEG1606+>>>8 leshort 8 \bdeflate1607+>>>8 leshort 9 \bJBIG, ITU-T T.851608+>>>8 leshort 0xa \bJBIG, ITU-T T.431609+>>>8 leshort 0x7ffe \bNeXT RLE 2-bit1610+>>>8 leshort 0x8005 \bPackBits (Macintosh RLE)1611+>>>8 leshort 0x8029 \bThunderscan RLE1612+>>>8 leshort 0x807f \bRasterPadding (CT or MP)1613+>>>8 leshort 0x8080 \bRLE (Line Work)1614+>>>8 leshort 0x8081 \bRLE (High-Res Cont-Tone)1615+>>>8 leshort 0x8082 \bRLE (Binary Line Work)1616+>>>8 leshort 0x80b2 \bDeflate (PKZIP)1617+>>>8 leshort 0x80b3 \bKodak DCS1618+>>>8 leshort 0x8765 \bJBIG1619+>>>8 leshort 0x8798 \bJPEG20001620+>>>8 leshort 0x8799 \bNikon NEF Compressed1621+>>>8 default x1622+>>>>8 leshort x \b(unknown 0x%x)1623+>>>12 use tiff_entry1624+>0 leshort 0x106 \b, PhotometricIntepretation=1625+>>8 leshort 0 \bWhiteIsZero1626+>>8 leshort 1 \bBlackIsZero1627+>>8 leshort 2 \bRGB1628+>>8 leshort 3 \bRGB Palette1629+>>8 leshort 4 \bTransparency Mask1630+>>8 leshort 5 \bCMYK1631+>>8 leshort 6 \bYCbCr1632+>>8 leshort 8 \bCIELab1633+>>>8 leshort x \b(unknown=0x%x)1634+>>12 use tiff_entry1635+# FillOrder1636+>0 leshort 0x10a1637+>>4 lelong 11638+>>>12 use tiff_entry1639+# DocumentName1640+>0 leshort 0x10d1641+>>(8.l) string x \b, name=%s1642+>>>12 use tiff_entry1643+# ImageDescription1644+>0 leshort 0x10e1645+>>(8.l) string x \b, description=%s1646+>>>12 use tiff_entry1647+# Make1648+>0 leshort 0x10f1649+>>(8.l) string x \b, manufacturer=%s1650+>>>12 use tiff_entry1651+# Model1652+>0 leshort 0x1101653+>>(8.l) string x \b, model=%s1654+>>>12 use tiff_entry1655+# StripOffsets1656+>0 leshort 0x1111657+>>12 use tiff_entry1658+# Orientation1659+>0 leshort 0x112 \b, orientation=1660+>>8 leshort 1 \bupper-left1661+>>8 leshort 3 \blower-right1662+>>8 leshort 6 \bupper-right1663+>>8 leshort 8 \blower-left1664+>>8 leshort 9 \bundefined1665+>>8 default x1666+>>>8 leshort x \b[*%d*]1667+>>12 use tiff_entry1668+# XResolution1669+>0 leshort 0x11a1670+>>8 lelong x \b, xresolution=%d1671+>>12 use tiff_entry1672+# YResolution1673+>0 leshort 0x11b1674+>>8 lelong x \b, yresolution=%d1675+>>12 use tiff_entry1676+# ResolutionUnit1677+>0 leshort 0x1281678+>>8 leshort x \b, resolutionunit=%d1679+>>12 use tiff_entry1680+# Software1681+>0 leshort 0x1311682+>>(8.l) string x \b, software=%s1683+>>12 use tiff_entry1684+# Datetime1685+>0 leshort 0x1321686+>>(8.l) string x \b, datetime=%s1687+>>12 use tiff_entry1688+# HostComputer1689+>0 leshort 0x13c1690+>>(8.l) string x \b, hostcomputer=%s1691+>>12 use tiff_entry1692+# WhitePoint1693+>0 leshort 0x13e1694+>>12 use tiff_entry1695+# PrimaryChromaticities1696+>0 leshort 0x13f1697+>>12 use tiff_entry1698+# YCbCrCoefficients1699+>0 leshort 0x2111700+>>12 use tiff_entry1701+# YCbCrPositioning1702+>0 leshort 0x2131703+>>12 use tiff_entry1704+# ReferenceBlackWhite1705+>0 leshort 0x2141706+>>12 use tiff_entry1707+# Copyright1708+>0 leshort 0x82981709+>>(8.l) string x \b, copyright=%s1710+>>12 use tiff_entry1711+# ExifOffset1712+>0 leshort 0x87691713+>>12 use tiff_entry1714+# GPS IFD1715+>0 leshort 0x8825 \b, GPS-Data1716+>>12 use tiff_entry1717+1718+#>0 leshort x \b, unknown=0x%x1719+#>>12 use tiff_entry1720+17210 string MM\x00\x2b Big TIFF image data, big-endian1722!:mime image/tiff17230 string II\x2b\x00 Big TIFF image data, little-endian1724@@ -892,6 +1037,65 @@17250 string \x46\x4d\x52\x00 ISO/IEC 19794-2 Format Minutiae Record (FMR)17261727# WEBP https://developers.google.com/speed/webp/docs/riff_container1728-0 string RIFF1729->8 string WEBP Web/P image data1730->>4 lelong x \b, %d bytes1731+#0 string RIFF1732+#>8 string WEBP Web/P image data1733+#>>4 lelong x \b, %d bytes1734+1735+# doc: http://www.shikino.co.jp/eng/products/images/FLOWER.jpg.zip1736+# example: http://www.shikino.co.jp/eng/products/images/FLOWER.wdp.zip1737+90 bequad 0x574D50484F544F00 JPEG-XR Image1738+>98 byte&0x08 =0x08 \b, hard tiling1739+>99 byte&0x80 =0x80 \b, tiling present1740+>99 byte&0x40 =0x40 \b, codestream present1741+>99 byte&0x38 x \b, spatial xform=1742+>99 byte&0x38 0x00 \bTL1743+>99 byte&0x38 0x08 \bBL1744+>99 byte&0x38 0x10 \bTR1745+>99 byte&0x38 0x18 \bBR1746+>99 byte&0x38 0x20 \bBT1747+>99 byte&0x38 0x28 \bRB1748+>99 byte&0x38 0x30 \bLT1749+>99 byte&0x38 0x38 \bLB1750+>100 byte&0x80 =0x80 \b, short header1751+>>102 beshort+1 x \b, %d1752+>>104 beshort+1 x \bx%d1753+>100 byte&0x80 =0x00 \b, long header1754+>>102 belong+1 x \b, %x1755+>>106 belong+1 x \bx%x1756+>101 beshort&0xf x \b, bitdepth=1757+>>101 beshort&0xf 0x0 \b1-WHITE=11758+>>101 beshort&0xf 0x1 \b81759+>>101 beshort&0xf 0x2 \b161760+>>101 beshort&0xf 0x3 \b16-SIGNED1761+>>101 beshort&0xf 0x4 \b16-FLOAT1762+>>101 beshort&0xf 0x5 \b(reserved 5)1763+>>101 beshort&0xf 0x6 \b32-SIGNED1764+>>101 beshort&0xf 0x7 \b32-FLOAT1765+>>101 beshort&0xf 0x8 \b51766+>>101 beshort&0xf 0x9 \b101767+>>101 beshort&0xf 0xa \b5-6-51768+>>101 beshort&0xf 0xb \b(reserved %d)1769+>>101 beshort&0xf 0xc \b(reserved %d)1770+>>101 beshort&0xf 0xd \b(reserved %d)1771+>>101 beshort&0xf 0xe \b(reserved %d)1772+>>101 beshort&0xf 0xf \b1-BLACK=11773+>101 beshort&0xf0 x \b, colorfmt=1774+>>101 beshort&0xf0 0x00 \bYONLY1775+>>101 beshort&0xf0 0x10 \bYUV2401776+>>101 beshort&0xf0 0x20 \bYWV4221777+>>101 beshort&0xf0 0x30 \bYWV4441778+>>101 beshort&0xf0 0x40 \bCMYK1779+>>101 beshort&0xf0 0x50 \bCMYKDIRECT1780+>>101 beshort&0xf0 0x60 \bNCOMPONENT1781+>>101 beshort&0xf0 0x70 \bRGB1782+>>101 beshort&0xf0 0x80 \bRGBE1783+>>101 beshort&0xf0 >0x80 \b(reserved 0x%x)1784+1785+# From: Johan van der Knijff <[email protected]>1786+#1787+# BPG (Better Portable Graphics) format1788+# http://bellard.org/bpg/1789+# http://fileformats.archiveteam.org/wiki/BPG1790+#1791+0 string \x42\x50\x47\xFB BPG (Better Portable Graphics)1792+!:mime image/bpg1793Index: contrib/file/magic/Magdir/jpeg1794===================================================================1795--- contrib/file/magic/Magdir/jpeg (revision 284174)1796+++ contrib/file/magic/Magdir/jpeg (working copy)1797@@ -1,6 +1,6 @@17981799#------------------------------------------------------------------------------1800-# $File: jpeg,v 1.19 2013/02/04 15:50:03 christos Exp $1801+# $File: jpeg,v 1.25 2015/01/02 16:56:50 christos Exp $1802# JPEG images1803# SunOS 5.5.1 had1804#1805@@ -22,133 +22,74 @@1806>>11 byte x \b %d.1807>>12 byte x \b%02d1808# Next, the resolution or aspect ratio of the image:1809-#>>13 byte 0 \b, aspect ratio1810-#>>13 byte 1 \b, resolution (DPI)1811-#>>13 byte 2 \b, resolution (DPCM)1812-#>>4 beshort x \b, segment length %d1813+>>13 byte 0 \b, aspect ratio1814+>>13 byte 1 \b, resolution (DPI)1815+>>13 byte 2 \b, resolution (DPCM)1816+>>14 beshort x \b, density %dx1817+>>16 beshort x \b%d1818+>>4 beshort x \b, segment length %d1819# Next, show thumbnail info, if it exists:1820>>18 byte !0 \b, thumbnail %dx1821>>>19 byte x \b%d1822+>6 string Exif \b, Exif standard: [1823+>>12 indirect/r x1824+>>12 string x \b]18251826-# EXIF moved down here to avoid reporting a bogus version number,1827-# and EXIF version number printing added.1828-# - Patrik R=E5dman <[email protected]>1829->6 string Exif \b, EXIF standard1830-# Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD.1831-# All possible combinations of entries have to be enumerated, since no looping1832-# is possible. And both endians are possible...1833-# The combinations included below are from real-world JPEGs.1834-# Little-endian1835->>12 string II1836-# IFD 0 Entry #5:1837->>>70 leshort 0x87691838-# EXIF IFD Entry #1:1839->>>>(78.l+14) leshort 0x90001840->>>>>(78.l+23) byte x %c1841->>>>>(78.l+24) byte x \b.%c1842->>>>>(78.l+25) byte !0x30 \b%c1843-# IFD 0 Entry #9:1844->>>118 leshort 0x87691845-# EXIF IFD Entry #3:1846->>>>(126.l+38) leshort 0x90001847->>>>>(126.l+47) byte x %c1848->>>>>(126.l+48) byte x \b.%c1849->>>>>(126.l+49) byte !0x30 \b%c1850-# IFD 0 Entry #101851->>>130 leshort 0x87691852-# EXIF IFD Entry #3:1853->>>>(138.l+38) leshort 0x90001854->>>>>(138.l+47) byte x %c1855->>>>>(138.l+48) byte x \b.%c1856->>>>>(138.l+49) byte !0x30 \b%c1857-# EXIF IFD Entry #4:1858->>>>(138.l+50) leshort 0x90001859->>>>>(138.l+59) byte x %c1860->>>>>(138.l+60) byte x \b.%c1861->>>>>(138.l+61) byte !0x30 \b%c1862-# EXIF IFD Entry #5:1863->>>>(138.l+62) leshort 0x90001864->>>>>(138.l+71) byte x %c1865->>>>>(138.l+72) byte x \b.%c1866->>>>>(138.l+73) byte !0x30 \b%c1867-# IFD 0 Entry #111868->>>142 leshort 0x87691869-# EXIF IFD Entry #3:1870->>>>(150.l+38) leshort 0x90001871->>>>>(150.l+47) byte x %c1872->>>>>(150.l+48) byte x \b.%c1873->>>>>(150.l+49) byte !0x30 \b%c1874-# EXIF IFD Entry #4:1875->>>>(150.l+50) leshort 0x90001876->>>>>(150.l+59) byte x %c1877->>>>>(150.l+60) byte x \b.%c1878->>>>>(150.l+61) byte !0x30 \b%c1879-# EXIF IFD Entry #5:1880->>>>(150.l+62) leshort 0x90001881->>>>>(150.l+71) byte x %c1882->>>>>(150.l+72) byte x \b.%c1883->>>>>(150.l+73) byte !0x30 \b%c1884-# Big-endian1885->>12 string MM1886-# IFD 0 Entry #9:1887->>>118 beshort 0x87691888-# EXIF IFD Entry #1:1889->>>>(126.L+14) beshort 0x90001890->>>>>(126.L+23) byte x %c1891->>>>>(126.L+24) byte x \b.%c1892->>>>>(126.L+25) byte !0x30 \b%c1893-# EXIF IFD Entry #3:1894->>>>(126.L+38) beshort 0x90001895->>>>>(126.L+47) byte x %c1896->>>>>(126.L+48) byte x \b.%c1897->>>>>(126.L+49) byte !0x30 \b%c1898-# IFD 0 Entry #101899->>>130 beshort 0x87691900-# EXIF IFD Entry #3:1901->>>>(138.L+38) beshort 0x90001902->>>>>(138.L+47) byte x %c1903->>>>>(138.L+48) byte x \b.%c1904->>>>>(138.L+49) byte !0x30 \b%c1905-# EXIF IFD Entry #5:1906->>>>(138.L+62) beshort 0x90001907->>>>>(138.L+71) byte x %c1908->>>>>(138.L+72) byte x \b.%c1909->>>>>(138.L+73) byte !0x30 \b%c1910-# IFD 0 Entry #111911->>>142 beshort 0x87691912-# EXIF IFD Entry #4:1913->>>>(150.L+50) beshort 0x90001914->>>>>(150.L+59) byte x %c1915->>>>>(150.L+60) byte x \b.%c1916->>>>>(150.L+61) byte !0x30 \b%c1917-# Here things get sticky. We can do ONE MORE marker segment with1918-# indirect addressing, and that's all. It would be great if we could1919-# do pointer arithemetic like in an assembler language. Christos?1920-# And if there was some sort of looping construct to do searches, plus a few1921-# named accumulators, it would be even more effective...1922-# At least we can show a comment if no other segments got inserted before:1923->(4.S+5) byte 0xFE \b, comment:1924->>(4.S+6) pstring/HJ x "%s"1925-# Or, we can show the encoding type (I've included only the three most common)1926-# and image dimensions if we are lucky and the SOFn (image segment) is here:1927->(4.S+5) byte 0xC0 \b, baseline1928->>(4.S+6) byte x \b, precision %d1929->>(4.S+7) beshort x \b, %dx1930->>(4.S+9) beshort x \b%d1931->(4.S+5) byte 0xC1 \b, extended sequential1932->>(4.S+6) byte x \b, precision %d1933->>(4.S+7) beshort x \b, %dx1934->>(4.S+9) beshort x \b%d1935->(4.S+5) byte 0xC2 \b, progressive1936->>(4.S+6) byte x \b, precision %d1937->>(4.S+7) beshort x \b, %dx1938->>(4.S+9) beshort x \b%d1939-# I've commented-out quantisation table reporting. I doubt anyone cares yet.1940-#>(4.S+5) byte 0xDB \b, quantisation table1941-#>>(4.S+6) beshort x \b length=%d1942-#>14 beshort x \b, %d x1943-#>16 beshort x \b %d1944+# Jump to the first segment1945+>(4.S+4) use jpeg_segment19461947+# This uses recursion...1948+0 name jpeg_segment1949+>0 beshort 0xFFFE1950+>>(2.S+2) use jpeg_segment1951+>>2 pstring/HJ x \b, comment: "%s"1952+1953+>0 beshort 0xFFC01954+>>(2.S+2) use jpeg_segment1955+>>4 byte x \b, baseline, precision %d1956+>>7 beshort x \b, %dx1957+>>5 beshort x \b%d1958+>>9 byte x \b, frames %d1959+1960+>0 beshort 0xFFC11961+>>(2.S+2) use jpeg_segment1962+>>4 byte x \b, extended sequential, precision %d1963+>>7 beshort x \b, %dx1964+>>5 beshort x \b%d1965+>>9 byte x \b, frames %d1966+1967+>0 beshort 0xFFC21968+>>(2.S+2) use jpeg_segment1969+>>4 byte x \b, progressive, precision %d1970+>>7 beshort x \b, %dx1971+>>5 beshort x \b%d1972+>>9 byte x \b, frames %d1973+1974+# Define Huffman Tables1975+>0 beshort 0xFFC41976+>>(2.S+2) use jpeg_segment1977+1978+>0 beshort 0xFFE11979+#>>(2.S+2) use jpeg_segment1980+>>4 string Exif \b, Exif Standard: [1981+>>>10 indirect/r x1982+>>>10 string x \b]1983+1984+# Application specific markers1985+>0 beshort&0xFFE0 =0xFFE01986+>>(2.S+2) use jpeg_segment1987+1988+# DB: Define Quantization tables1989+# DD: Define Restart interval [XXX: wrong here, it is 4 bytes]1990+# D8: Start of image1991+# D9: End of image1992+# Dn: Restart1993+>0 beshort&0xFFD0 =0xFFD01994+>>(2.S+2) use jpeg_segment1995+1996+#>0 beshort x unknown 0x%x1997+#>>(2.S+2) use jpeg_segment1998+1999# HSI is Handmade Software's proprietary JPEG encoding scheme20000 string hsi1 JPEG image data, HSI proprietary20012002Index: contrib/file/magic/Magdir/kerberos2003===================================================================2004--- contrib/file/magic/Magdir/kerberos (revision 0)2005+++ contrib/file/magic/Magdir/kerberos (working copy)2006@@ -0,0 +1,45 @@2007+2008+#------------------------------------------------------------------------------2009+# $File: kerberos,v 1.1 2014/12/10 18:45:43 christos Exp $2010+# kerberos: MIT kerberos file binary formats2011+#2012+2013+# This magic entry is for demonstration purposes and could be improved2014+# if the following features were implemented in file:2015+#2016+# Strings inside [[ .. ]] in the descriptions have special meanings and2017+# are not printed.2018+#2019+# - Provide some form of iteration in number of components2020+# [[${counter}=%d]] in the description2021+# then append2022+# [${counter}--] in the offset of the entries2023+# - Provide a way to round the next offset2024+# Add [R:4] after the offset?2025+# - Provide a way to have optional entries2026+# XXX: Syntax:2027+# - Provide a way to "save" entries to print them later.2028+# if the description is [[${name}=%s]], then nothing is2029+# printed and a subsequent entry in the same magic file2030+# can refer to ${name}2031+# - Provide a way to format strings as hex values2032+#2033+# http://www.gnu.org/software/shishi/manual/html_node/\2034+# The-Keytab-Binary-File-Format.html2035+#2036+2037+0 name keytab_entry2038+#>0 beshort x \b, size=%d2039+#>2 beshort x \b, components=%d2040+>4 pstring/H x \b, realm=%s2041+>>&0 pstring/H x \b, principal=%s/2042+>>>&0 pstring/H x \b%s2043+>>>>&0 belong x \b, type=%d2044+>>>>>&0 bedate x \b, date=%s2045+>>>>>>&0 byte x \b, kvno=%u2046+#>>>>>>>&0 pstring/H x2047+#>>>>>>>>&0 belong x2048+#>>>>>>>>>>&0 use keytab_entry2049+2050+0 belong 0x05020000 Kerberos Keytab file2051+>4 use keytab_entry2052Index: contrib/file/magic/Magdir/linux2053===================================================================2054--- contrib/file/magic/Magdir/linux (revision 284174)2055+++ contrib/file/magic/Magdir/linux (working copy)2056@@ -1,6 +1,6 @@20572058#------------------------------------------------------------------------------2059-# $File: linux,v 1.57 2014/05/20 20:10:17 christos Exp $2060+# $File: linux,v 1.59 2014/11/03 21:03:36 christos Exp $2061# linux: file(1) magic for Linux files2062#2063# Values for Linux/i386 binaries, from Daniel Quinlan <[email protected]>2064@@ -413,3 +413,22 @@2065>>>>20 belong >162066>>>>>36 belong x \b, DT structure block size=%d20672068+# glibc locale archive as defined in glibc locale/locarchive.h2069+0 lelong 0xde020109 locale archive2070+>24 lelong x %d strings2071+2072+# Summary: Database file for mlocate2073+# Description: A database file as used by mlocate, a fast implementation2074+# of locate/updatedb. It uses merging to reuse the existing2075+# database and avoid rereading most of the filesystem. It's2076+# the default version of locate on Arch Linux (and others).2077+# File path: /var/lib/mlocate/mlocate.db by default (but configurable)2078+# Site: https://fedorahosted.org/mlocate/2079+# Format docs: http://linux.die.net/man/5/mlocate.db2080+# Type: mlocate database file2081+# URL: https://fedorahosted.org/mlocate/2082+# From: Wander Nauta <[email protected]>2083+0 string \0mlocate mlocate database2084+>12 byte x \b, version %d2085+>13 byte 1 \b, require visibility2086+>16 string x \b, root %s2087Index: contrib/file/magic/Magdir/macintosh2088===================================================================2089--- contrib/file/magic/Magdir/macintosh (revision 284174)2090+++ contrib/file/magic/Magdir/macintosh (working copy)2091@@ -1,6 +1,6 @@20922093#------------------------------------------------------------------------------2094-# $File: macintosh,v 1.23 2013/11/19 18:47:58 christos Exp $2095+# $File: macintosh,v 1.25 2014/09/03 13:34:16 christos Exp $2096# macintosh description2097#2098# BinHex is the Macintosh ASCII-encoded file format (see also "apple")2099@@ -165,7 +165,7 @@2100#>65 string ZSYS (Pre-System 7 system file)2101#>65 string acf3 (Aldus FreeHand)2102#>65 string cdev (control panel)2103-#>65 string dfil (Desk Acessory suitcase)2104+#>65 string dfil (Desk Accessory suitcase)2105#>65 string libr (library)2106#>65 string nX^d (WriteNow word processor)2107#>65 string nX^w (WriteNow dictionary)2108@@ -288,20 +288,38 @@2109>0x412 beshort x number of blocks: %d,2110>0x424 pstring x volume name: %s21112112+# *.hfs updated by Joerg Jenderek2113+# http://en.wikipedia.org/wiki/Hierarchical_File_System2114# "BD" gives many false positives2115-#0x400 beshort 0x4244 Macintosh HFS data2116-#>0 beshort 0x4C4B (bootable)2117-#>0x40a beshort &0x8000 (locked)2118-#>0x40a beshort ^0x0100 (mounted)2119-#>0x40a beshort &0x0200 (spared blocks)2120-#>0x40a beshort &0x0800 (unclean)2121-#>0x47C beshort 0x482B (Embedded HFS+ Volume)2122-#>0x402 beldate-0x7C25B080 x created: %s,2123-#>0x406 beldate-0x7C25B080 x last modified: %s,2124-#>0x440 beldate-0x7C25B080 >0 last backup: %s,2125-#>0x414 belong x block size: %d,2126-#>0x412 beshort x number of blocks: %d,2127-#>0x424 pstring x volume name: %s2128+0x400 beshort 0x42442129+# ftp://ftp.mars.org/pub/hfs/hfsutils-3.2.6.tar.gz/hfsutils-3.2.6/libhfs/apple.h2130+# first block of volume bit map (always 3)2131+>0x40e ubeshort 0x00032132+# maximal length of volume name is 272133+>>0x424 ubyte <28 Macintosh HFS data2134+#!:mime application/octet-stream2135+# these mime and apple types are not sure2136+!:mime application/x-apple-diskimage2137+#!:apple hfsdINIT2138+#!:apple MACSdisk2139+>>>0 beshort 0x4C4B (bootable)2140+#>>>0 beshort 0x0000 (not bootable)2141+>>>0x40a beshort &0x8000 (locked)2142+>>>0x40a beshort ^0x0100 (mounted)2143+>>>0x40a beshort &0x0200 (spared blocks)2144+>>>0x40a beshort &0x0800 (unclean)2145+>>>0x47C beshort 0x482B (Embedded HFS+ Volume)2146+# http://www.epochconverter.com/2147+# 0x7C245F00 seconds ~ 2082758400 ~ 01 Jan 2036 00:00:00 ~ 66 years to 19702148+# 0x7C25B080 seconds ~ 2082844800 ~ 02 Jan 2036 00:00:002149+# construct not working2150+#>>>0x402 beldate-0x7C25B080 x created: %s,2151+#>>>0x406 beldate-0x7C25B080 x last modified: %s,2152+#>>>0x440 beldate-0x7C25B080 >0 last backup: %s,2153+# found block sizes 200h,1200h,2800h2154+>>>0x414 belong x block size: %d,2155+>>>0x412 beshort x number of blocks: %d,2156+>>>0x424 pstring x volume name: %s215721580x400 beshort 0x482B Macintosh HFS Extended2159>&0 beshort x version %d data2160@@ -322,43 +340,9 @@2161>&42 belong x number of blocks: %d,2162>&46 belong x free blocks: %d21632164-# I don't think this is really necessary since it doesn't do much and2165-# anything with a valid driver descriptor will also have a valid2166-# partition map2167-#0 beshort 0x4552 Apple Device Driver data2168-#>&24 beshort =1 \b, MacOS2169-2170-# Is that the partition type a cstring or a pstring? Well, IM says "strings2171-# shorter than 32 bytes must be terminated with NULL" so I'll treat it as a2172-# cstring. Of course, partitions can contain more than four entries, but2173-# what're you gonna do?2174-# GRR: This magic is too weak, it is just "PM"2175-#0x200 beshort 0x504D Apple Partition data2176-#>0x2 beshort x (block size: %d):2177-#>0x230 string x first type: %s,2178-#>0x210 string x name: %s,2179-#>0x254 belong x number of blocks: %d,2180-#>0x400 beshort 0x504D2181-#>>0x430 string x second type: %s,2182-#>>0x410 string x name: %s,2183-#>>0x454 belong x number of blocks: %d,2184-#>>0x600 beshort 0x504D2185-#>>>0x630 string x third type: %s,2186-#>>>0x610 string x name: %s,2187-#>>>0x654 belong x number of blocks: %d,2188-#>>0x800 beshort 0x504D2189-#>>>0x830 string x fourth type: %s,2190-#>>>0x810 string x name: %s,2191-#>>>0x854 belong x number of blocks: %d,2192-#>>>0xa00 beshort 0x504D2193-#>>>>0xa30 string x fifth type: %s,2194-#>>>>0xa10 string x name: %s,2195-#>>>>0xa54 belong x number of blocks: %d2196-#>>>0xc00 beshort 0x504D2197-#>>>>0xc30 string x sixth type: %s,2198-#>>>>0xc10 string x name: %s,2199-#>>>>0xc54 belong x number of blocks: %d2200## AFAIK, only the signature is different2201+# same as Apple Partition Map2202+# GRR: This magic is too weak, it is just "TS"2203#0x200 beshort 0x5453 Apple Old Partition data2204#>0x2 beshort x block size: %d,2205#>0x230 string x first type: %s,2206Index: contrib/file/magic/Magdir/meteorological2207===================================================================2208--- contrib/file/magic/Magdir/meteorological (revision 0)2209+++ contrib/file/magic/Magdir/meteorological (working copy)2210@@ -0,0 +1,49 @@2211+2212+#------------------------------------------------------------------------------2213+# $File: meteorological,v 1.1 2014/08/04 06:26:16 christos Exp $2214+# rinex: file(1) magic for RINEX files2215+# http://igscb.jpl.nasa.gov/igscb/data/format/rinex210.txt2216+# ftp://cddis.gsfc.nasa.gov/pub/reports/formats/rinex300.pdf2217+# data for testing: ftp://cddis.gsfc.nasa.gov/pub/gps/data2218+60 string RINEX2219+>80 search/256 XXRINEXB RINEX Data, GEO SBAS Broadcast2220+>>&32 string x \b, date %15.15s2221+>>5 string x \b, version %6.6s2222+!:mime rinex/broadcast2223+>80 search/256 XXRINEXD RINEX Data, Observation (Hatanaka comp)2224+>>&32 string x \b, date %15.15s2225+>>5 string x \b, version %6.6s2226+!:mime rinex/observation2227+>80 search/256 XXRINEXC RINEX Data, Clock2228+>>&32 string x \b, date %15.15s2229+>>5 string x \b, version %6.6s2230+!:mime rinex/clock2231+>80 search/256 XXRINEXH RINEX Data, GEO SBAS Navigation2232+>>&32 string x \b, date %15.15s2233+>>5 string x \b, version %6.6s2234+!:mime rinex/navigation2235+>80 search/256 XXRINEXG RINEX Data, GLONASS Navigation2236+>>&32 string x \b, date %15.15s2237+>>5 string x \b, version %6.6s2238+!:mime rinex/navigation2239+>80 search/256 XXRINEXL RINEX Data, Galileo Navigation2240+>>&32 string x \b, date %15.15s2241+>>5 string x \b, version %6.6s2242+!:mime rinex/navigation2243+>80 search/256 XXRINEXM RINEX Data, Meteorological2244+>>&32 string x \b, date %15.15s2245+>>5 string x \b, version %6.6s2246+!:mime rinex/meteorological2247+>80 search/256 XXRINEXN RINEX Data, Navigation2248+>>&32 string x \b, date %15.15s2249+>>5 string x \b, version %6.6s2250+!:mime rinex/navigation2251+>80 search/256 XXRINEXO RINEX Data, Observation2252+>>&32 string x \b, date %15.15s2253+>>5 string x \b, version %6.6s2254+!:mime rinex/observation2255+2256+# https://en.wikipedia.org/wiki/GRIB2257+0 string GRIB2258+>7 byte =1 Gridded binary (GRIB) version 12259+>7 byte =2 Gridded binary (GRIB) version 22260Index: contrib/file/magic/Magdir/msooxml2261===================================================================2262--- contrib/file/magic/Magdir/msooxml (revision 284174)2263+++ contrib/file/magic/Magdir/msooxml (working copy)2264@@ -1,6 +1,6 @@22652266#------------------------------------------------------------------------------2267-# $File: msooxml,v 1.4 2014/01/06 18:16:24 rrt Exp $2268+# $File: msooxml,v 1.5 2014/08/05 07:38:45 christos Exp $2269# msooxml: file(1) magic for Microsoft Office XML2270# From: Ralf Brown <[email protected]>22712272@@ -16,7 +16,7 @@22730 string PK\003\0042274!:strength +102275# make sure the first file is correct2276->0x1E regex \[Content_Types\]\.xml|_rels/\.rels2277+>0x1E regex \\[Content_Types\\]\\.xml|_rels/\\.rels2278# skip to the second local file header2279# since some documents include a 520-byte extra field following the file2280# header, we need to scan for the next header2281Index: contrib/file/magic/Magdir/netbsd2282===================================================================2283--- contrib/file/magic/Magdir/netbsd (revision 284174)2284+++ contrib/file/magic/Magdir/netbsd (working copy)2285@@ -1,6 +1,6 @@22862287#------------------------------------------------------------------------------2288-# $File: netbsd,v 1.21 2014/03/29 15:40:34 christos Exp $2289+# $File: netbsd,v 1.22 2014/12/08 20:53:52 christos Exp $2290# netbsd: file(1) magic for NetBSD objects2291#2292# All new-style magic numbers are in network byte order.2293@@ -247,7 +247,7 @@2294# Kernel core dump format22950 belong&0x0000ffff 0x00008fca NetBSD kernel core file2296>0 belong&0x03ff0000 0x00000000 \b, Unknown2297->0 belong&0x03ff0000 0x00001000 \b, sun 68010/680202298+>0 belong&0x03ff0000 0x00010000 \b, sun 68010/680202299>0 belong&0x03ff0000 0x00020000 \b, sun 680202300>0 belong&0x03ff0000 0x00640000 \b, 386 PC2301>0 belong&0x03ff0000 0x00860000 \b, i386 BSD2302@@ -262,20 +262,24 @@2303>0 belong&0x03ff0000 0x008f0000 \b, arm6 BSD2304>0 belong&0x03ff0000 0x00900000 \b, m68k BSD (2K pages)2305>0 belong&0x03ff0000 0x00910000 \b, sh3 BSD2306->0 belong&0x03ff0000 0x00920000 \b, ppc BSD (Big Endian)2307->0 belong&0x03ff0000 0x00930000 \b, vax BSD (4K pages)2308->0 belong&0x03ff0000 0x00940000 \b, mips1 BSD2309->0 belong&0x03ff0000 0x00950000 \b, mips2 BSD2310->0 belong&0x03ff0000 0x00960000 \b, parisc BSD2311->0 belong&0x03ff0000 0x00970000 \b, sh5/64 BSD2312->0 belong&0x03ff0000 0x00980000 \b, SPARC/64 BSD2313->0 belong&0x03ff0000 0x00990000 \b, amd64 BSD2314->0 belong&0x03ff0000 0x009a0000 \b, hp200 (68010) BSD2315->0 belong&0x03ff0000 0x009b0000 \b, hp300 (68020+68881) BSD2316->0 belong&0x03ff0000 0x009b0000 \b, hp300 (68020+68881) BSD2317->0 belong&0x03ff0000 0x00c80000 \b, hp2002318->0 belong&0x03ff0000 0x020b0000 \b, hp300 (68020+68881) HP-UX2319->0 belong&0x03ff0000 0x020c0000 \b, hp300 (68020+68881) HP-UX2320+>0 belong&0x03ff0000 0x00950000 \b, ppc BSD (Big Endian)2321+>0 belong&0x03ff0000 0x00960000 \b, vax BSD (4K pages)2322+>0 belong&0x03ff0000 0x00970000 \b, mips1 BSD2323+>0 belong&0x03ff0000 0x00980000 \b, mips2 BSD2324+>0 belong&0x03ff0000 0x00990000 \b, m88k BSD2325+>0 belong&0x03ff0000 0x00920000 \b, parisc BSD2326+>0 belong&0x03ff0000 0x009b0000 \b, sh5/64 BSD2327+>0 belong&0x03ff0000 0x009c0000 \b, SPARC/64 BSD2328+>0 belong&0x03ff0000 0x009d0000 \b, amd64 BSD2329+>0 belong&0x03ff0000 0x009e0000 \b, sh5/32 BSD2330+>0 belong&0x03ff0000 0x009f0000 \b, ia64 BSD2331+>0 belong&0x03ff0000 0x00b70000 \b, aarch64 BSD2332+>0 belong&0x03ff0000 0x00b80000 \b, or1k BSD2333+>0 belong&0x03ff0000 0x00b90000 \b, Risk-V BSD2334+>0 belong&0x03ff0000 0x00c80000 \b, hp200 BSD2335+>0 belong&0x03ff0000 0x012c0000 \b, hp300 BSD2336+>0 belong&0x03ff0000 0x020b0000 \b, hp800 HP-UX2337+>0 belong&0x03ff0000 0x020c0000 \b, hp200/hp300 HP-UX2338>0 belong&0xfc000000 0x04000000 \b, CPU2339>0 belong&0xfc000000 0x08000000 \b, DATA2340>0 belong&0xfc000000 0x10000000 \b, STACK2341Index: contrib/file/magic/Magdir/pascal2342===================================================================2343--- contrib/file/magic/Magdir/pascal (revision 284174)2344+++ contrib/file/magic/Magdir/pascal (working copy)2345@@ -1,10 +1,10 @@2346#------------------------------------------------------------------------------2347-# $File: pascal,v 1.1 2011/12/08 12:12:46 rrt Exp $2348+# $File: pascal,v 1.2 2014/07/14 14:21:33 rrt Exp $2349# pascal: file(1) magic for Pascal source2350#23510 search/8192 (input, Pascal source text2352!:mime text/x-pascal2353-0 regex \^program Pascal source text2354-!:mime text/x-pascal2355-0 regex \^record Pascal source text2356-!:mime text/x-pascal2357+#0 regex \^program Pascal source text2358+#!:mime text/x-pascal2359+#0 regex \^record Pascal source text2360+#!:mime text/x-pascal2361Index: contrib/file/magic/Magdir/pgp2362===================================================================2363--- contrib/file/magic/Magdir/pgp (revision 284174)2364+++ contrib/file/magic/Magdir/pgp (working copy)2365@@ -1,6 +1,6 @@23662367#------------------------------------------------------------------------------2368-# $File: pgp,v 1.9 2009/09/19 16:28:11 christos Exp $2369+# $File: pgp,v 1.11 2014/11/11 21:32:38 christos Exp $2370# pgp: file(1) magic for Pretty Good Privacy2371# see http://lists.gnupg.org/pipermail/gnupg-devel/1999-September/016052.html2372#2373@@ -21,7 +21,449 @@237423752 string ---BEGIN\ PGP\ PUBLIC\ KEY\ BLOCK- PGP public key block2376!:mime application/pgp-keys2377+>10 search/100 \n\n2378+>>&0 use pgp23790 string -----BEGIN\040PGP\40MESSAGE- PGP message2380!:mime application/pgp2381+>10 search/100 \n\n2382+>>&0 use pgp23830 string -----BEGIN\040PGP\40SIGNATURE- PGP signature2384!:mime application/pgp-signature2385+>10 search/100 \n\n2386+>>&0 use pgp2387+2388+# Decode the type of the packet based on it's base64 encoding.2389+# Idea from Mark Martinec2390+# The specification is in RFC 4880, section 4.2 and 4.3:2391+# http://tools.ietf.org/html/rfc4880#section-4.22392+2393+0 name pgp2394+>0 byte 0x67 Reserved (old)2395+>0 byte 0x68 Public-Key Encrypted Session Key (old)2396+>0 byte 0x69 Signature (old)2397+>0 byte 0x6a Symmetric-Key Encrypted Session Key (old)2398+>0 byte 0x6b One-Pass Signature (old)2399+>0 byte 0x6c Secret-Key (old)2400+>0 byte 0x6d Public-Key (old)2401+>0 byte 0x6e Secret-Subkey (old)2402+>0 byte 0x6f Compressed Data (old)2403+>0 byte 0x70 Symmetrically Encrypted Data (old)2404+>0 byte 0x71 Marker (old)2405+>0 byte 0x72 Literal Data (old)2406+>0 byte 0x73 Trust (old)2407+>0 byte 0x74 User ID (old)2408+>0 byte 0x75 Public-Subkey (old)2409+>0 byte 0x76 Unused (old)2410+>0 byte 0x772411+>>1 byte&0xc0 0x00 Reserved2412+>>1 byte&0xc0 0x40 Public-Key Encrypted Session Key2413+>>1 byte&0xc0 0x80 Signature2414+>>1 byte&0xc0 0xc0 Symmetric-Key Encrypted Session Key2415+>0 byte 0x782416+>>1 byte&0xc0 0x00 One-Pass Signature2417+>>1 byte&0xc0 0x40 Secret-Key2418+>>1 byte&0xc0 0x80 Public-Key2419+>>1 byte&0xc0 0xc0 Secret-Subkey2420+>0 byte 0x792421+>>1 byte&0xc0 0x00 Compressed Data2422+>>1 byte&0xc0 0x40 Symmetrically Encrypted Data2423+>>1 byte&0xc0 0x80 Marker2424+>>1 byte&0xc0 0xc0 Literal Data2425+>0 byte 0x7a2426+>>1 byte&0xc0 0x00 Trust2427+>>1 byte&0xc0 0x40 User ID2428+>>1 byte&0xc0 0x80 Public-Subkey2429+>>1 byte&0xc0 0xc0 Unused [z%x]2430+>0 byte 0x302431+>>1 byte&0xc0 0x00 Unused [0%x]2432+>>1 byte&0xc0 0x40 User Attribute2433+>>1 byte&0xc0 0x80 Sym. Encrypted and Integrity Protected Data2434+>>1 byte&0xc0 0xc0 Modification Detection Code2435+2436+# magic signatures to detect PGP crypto material (from stef)2437+# detects and extracts metadata from:2438+# - symmetric encrypted packet header2439+# - RSA (e=65537) secret (sub-)keys2440+2441+# 1024b RSA encrypted data2442+2443+0 string \x84\x8c\x03 PGP RSA encrypted session key -2444+>3 lelong x keyid: %X2445+>7 lelong x %X2446+>11 byte 0x01 RSA (Encrypt or Sign) 1024b2447+>11 byte 0x02 RSA Encrypt-Only 1024b2448+>12 string \x04\x002449+>12 string \x03\xff2450+>12 string \x03\xfe2451+>12 string \x03\xfd2452+>12 string \x03\xfc2453+>12 string \x03\xfb2454+>12 string \x03\xfa2455+>12 string \x03\xf92456+>142 byte 0xd2 .2457+2458+# 2048b RSA encrypted data2459+2460+0 string \x85\x01\x0c\x03 PGP RSA encrypted session key -2461+>4 lelong x keyid: %X2462+>8 lelong x %X2463+>12 byte 0x01 RSA (Encrypt or Sign) 2048b2464+>12 byte 0x02 RSA Encrypt-Only 2048b2465+>13 string \x08\x002466+>13 string \x07\xff2467+>13 string \x07\xfe2468+>13 string \x07\xfd2469+>13 string \x07\xfc2470+>13 string \x07\xfb2471+>13 string \x07\xfa2472+>13 string \x07\xf92473+>271 byte 0xd2 .2474+2475+# 3072b RSA encrypted data2476+2477+0 string \x85\x01\x8c\x03 PGP RSA encrypted session key -2478+>4 lelong x keyid: %X2479+>8 lelong x %X2480+>12 byte 0x01 RSA (Encrypt or Sign) 3072b2481+>12 byte 0x02 RSA Encrypt-Only 3072b2482+>13 string \x0c\x002483+>13 string \x0b\xff2484+>13 string \x0b\xfe2485+>13 string \x0b\xfd2486+>13 string \x0b\xfc2487+>13 string \x0b\xfb2488+>13 string \x0b\xfa2489+>13 string \x0b\xf92490+>399 byte 0xd2 .2491+2492+# 3072b RSA encrypted data2493+2494+0 string \x85\x02\x0c\x03 PGP RSA encrypted session key -2495+>4 lelong x keyid: %X2496+>8 lelong x %X2497+>12 byte 0x01 RSA (Encrypt or Sign) 4096b2498+>12 byte 0x02 RSA Encrypt-Only 4096b2499+>13 string \x10\x002500+>13 string \x0f\xff2501+>13 string \x0f\xfe2502+>13 string \x0f\xfd2503+>13 string \x0f\xfc2504+>13 string \x0f\xfb2505+>13 string \x0f\xfa2506+>13 string \x0f\xf92507+>527 byte 0xd2 .2508+2509+# 4096b RSA encrypted data2510+2511+0 string \x85\x04\x0c\x03 PGP RSA encrypted session key -2512+>4 lelong x keyid: %X2513+>8 lelong x %X2514+>12 byte 0x01 RSA (Encrypt or Sign) 8129b2515+>12 byte 0x02 RSA Encrypt-Only 8129b2516+>13 string \x20\x002517+>13 string \x1f\xff2518+>13 string \x1f\xfe2519+>13 string \x1f\xfd2520+>13 string \x1f\xfc2521+>13 string \x1f\xfb2522+>13 string \x1f\xfa2523+>13 string \x1f\xf92524+>1039 byte 0xd2 .2525+2526+# crypto algo mapper2527+2528+0 name crypto2529+>0 byte 0x00 Plaintext or unencrypted data2530+>0 byte 0x01 IDEA2531+>0 byte 0x02 TripleDES2532+>0 byte 0x03 CAST5 (128 bit key)2533+>0 byte 0x04 Blowfish (128 bit key, 16 rounds)2534+>0 byte 0x07 AES with 128-bit key2535+>0 byte 0x08 AES with 192-bit key2536+>0 byte 0x09 AES with 256-bit key2537+>0 byte 0x0a Twofish with 256-bit key2538+2539+# hash algo mapper2540+2541+0 name hash2542+>0 byte 0x01 MD52543+>0 byte 0x02 SHA-12544+>0 byte 0x03 RIPE-MD/1602545+>0 byte 0x08 SHA2562546+>0 byte 0x09 SHA3842547+>0 byte 0x0a SHA5122548+>0 byte 0x0b SHA2242549+2550+# pgp symmetric encrypted data2551+2552+0 byte 0x8c PGP symmetric key encrypted data -2553+>1 byte 0x0d2554+>1 byte 0x0c2555+>2 byte 0x042556+>3 use crypto2557+>4 byte 0x01 salted -2558+>>5 use hash2559+>>14 byte 0xd2 .2560+>>14 byte 0xc9 .2561+>4 byte 0x03 salted & iterated -2562+>>5 use hash2563+>>15 byte 0xd2 .2564+>>15 byte 0xc9 .2565+2566+# encrypted keymaterial needs s2k & can be checksummed/hashed2567+2568+0 name chkcrypto2569+>0 use crypto2570+>1 byte 0x00 Simple S2K2571+>1 byte 0x01 Salted S2K2572+>1 byte 0x03 Salted&Iterated S2K2573+>2 use hash2574+2575+# all PGP keys start with this prolog2576+# containing version, creation date, and purpose2577+2578+0 name keyprolog2579+>0 byte 0x042580+>1 beldate x created on %s -2581+>5 byte 0x01 RSA (Encrypt or Sign)2582+>5 byte 0x02 RSA Encrypt-Only2583+2584+# end of secret keys known signature2585+# contains e=65537 and the prolog to2586+# the encrypted parameters2587+2588+0 name keyend2589+>0 string \x00\x11\x01\x00\x01 e=655372590+>5 use crypto2591+>5 byte 0xff checksummed2592+>>6 use chkcrypto2593+>5 byte 0xfe hashed2594+>>6 use chkcrypto2595+2596+# PGP secret keys contain also the public parts2597+# these vary by bitsize of the key2598+2599+0 name x10242600+>0 use keyprolog2601+>6 string \x03\xfe2602+>6 string \x03\xff2603+>6 string \x04\x002604+>136 use keyend2605+2606+0 name x20482607+>0 use keyprolog2608+>6 string \x80\x002609+>6 string \x07\xfe2610+>6 string \x07\xff2611+>264 use keyend2612+2613+0 name x30722614+>0 use keyprolog2615+>6 string \x0b\xfe2616+>6 string \x0b\xff2617+>6 string \x0c\x002618+>392 use keyend2619+2620+0 name x40962621+>0 use keyprolog2622+>6 string \x10\x002623+>6 string \x0f\xfe2624+>6 string \x0f\xff2625+>520 use keyend2626+2627+# \x00|\x1f[\xfe\xff]).{1024})'2628+0 name x81922629+>0 use keyprolog2630+>6 string \x20\x002631+>6 string \x1f\xfe2632+>6 string \x1f\xff2633+>1032 use keyend2634+2635+# depending on the size of the pkt2636+# we branch into the proper key size2637+# signatures defined as x{keysize}2638+2639+>0 name pgpkey2640+>0 string \x01\xd8 1024b2641+>>2 use x10242642+>0 string \x01\xeb 1024b2643+>>2 use x10242644+>0 string \x01\xfb 1024b2645+>>2 use x10242646+>0 string \x01\xfd 1024b2647+>>2 use x10242648+>0 string \x01\xf3 1024b2649+>>2 use x10242650+>0 string \x01\xee 1024b2651+>>2 use x10242652+>0 string \x01\xfe 1024b2653+>>2 use x10242654+>0 string \x01\xf4 1024b2655+>>2 use x10242656+>0 string \x02\x0d 1024b2657+>>2 use x10242658+>0 string \x02\x03 1024b2659+>>2 use x10242660+>0 string \x02\x05 1024b2661+>>2 use x10242662+>0 string \x02\x15 1024b2663+>>2 use x10242664+>0 string \x02\x00 1024b2665+>>2 use x10242666+>0 string \x02\x10 1024b2667+>>2 use x10242668+>0 string \x02\x04 1024b2669+>>2 use x10242670+>0 string \x02\x06 1024b2671+>>2 use x10242672+>0 string \x02\x16 1024b2673+>>2 use x10242674+>0 string \x03\x98 2048b2675+>>2 use x20482676+>0 string \x03\xab 2048b2677+>>2 use x20482678+>0 string \x03\xbb 2048b2679+>>2 use x20482680+>0 string \x03\xbd 2048b2681+>>2 use x20482682+>0 string \x03\xcd 2048b2683+>>2 use x20482684+>0 string \x03\xb3 2048b2685+>>2 use x20482686+>0 string \x03\xc3 2048b2687+>>2 use x20482688+>0 string \x03\xc5 2048b2689+>>2 use x20482690+>0 string \x03\xd5 2048b2691+>>2 use x20482692+>0 string \x03\xae 2048b2693+>>2 use x20482694+>0 string \x03\xbe 2048b2695+>>2 use x20482696+>0 string \x03\xc0 2048b2697+>>2 use x20482698+>0 string \x03\xd0 2048b2699+>>2 use x20482700+>0 string \x03\xb4 2048b2701+>>2 use x20482702+>0 string \x03\xc4 2048b2703+>>2 use x20482704+>0 string \x03\xc6 2048b2705+>>2 use x20482706+>0 string \x03\xd6 2048b2707+>>2 use x20482708+>0 string \x05X 3072b2709+>>2 use x30722710+>0 string \x05k 3072b2711+>>2 use x30722712+>0 string \x05{ 3072b2713+>>2 use x30722714+>0 string \x05} 3072b2715+>>2 use x30722716+>0 string \x05\x8d 3072b2717+>>2 use x30722718+>0 string \x05s 3072b2719+>>2 use x30722720+>0 string \x05\x83 3072b2721+>>2 use x30722722+>0 string \x05\x85 3072b2723+>>2 use x30722724+>0 string \x05\x95 3072b2725+>>2 use x30722726+>0 string \x05n 3072b2727+>>2 use x30722728+>0 string \x05\x7e 3072b2729+>>2 use x30722730+>0 string \x05\x80 3072b2731+>>2 use x30722732+>0 string \x05\x90 3072b2733+>>2 use x30722734+>0 string \x05t 3072b2735+>>2 use x30722736+>0 string \x05\x84 3072b2737+>>2 use x30722738+>0 string \x05\x86 3072b2739+>>2 use x30722740+>0 string \x05\x96 3072b2741+>>2 use x30722742+>0 string \x07[ 4096b2743+>>2 use x40962744+>0 string \x07\x18 4096b2745+>>2 use x40962746+>0 string \x07+ 4096b2747+>>2 use x40962748+>0 string \x07; 4096b2749+>>2 use x40962750+>0 string \x07= 4096b2751+>>2 use x40962752+>0 string \x07M 4096b2753+>>2 use x40962754+>0 string \x073 4096b2755+>>2 use x40962756+>0 string \x07C 4096b2757+>>2 use x40962758+>0 string \x07E 4096b2759+>>2 use x40962760+>0 string \x07U 4096b2761+>>2 use x40962762+>0 string \x07. 4096b2763+>>2 use x40962764+>0 string \x07> 4096b2765+>>2 use x40962766+>0 string \x07@ 4096b2767+>>2 use x40962768+>0 string \x07P 4096b2769+>>2 use x40962770+>0 string \x074 4096b2771+>>2 use x40962772+>0 string \x07D 4096b2773+>>2 use x40962774+>0 string \x07F 4096b2775+>>2 use x40962776+>0 string \x07V 4096b2777+>>2 use x40962778+>0 string \x0e[ 8192b2779+>>2 use x81922780+>0 string \x0e\x18 8192b2781+>>2 use x81922782+>0 string \x0e+ 8192b2783+>>2 use x81922784+>0 string \x0e; 8192b2785+>>2 use x81922786+>0 string \x0e= 8192b2787+>>2 use x81922788+>0 string \x0eM 8192b2789+>>2 use x81922790+>0 string \x0e3 8192b2791+>>2 use x81922792+>0 string \x0eC 8192b2793+>>2 use x81922794+>0 string \x0eE 8192b2795+>>2 use x81922796+>0 string \x0eU 8192b2797+>>2 use x81922798+>0 string \x0e. 8192b2799+>>2 use x81922800+>0 string \x0e> 8192b2801+>>2 use x81922802+>0 string \x0e@ 8192b2803+>>2 use x81922804+>0 string \x0eP 8192b2805+>>2 use x81922806+>0 string \x0e4 8192b2807+>>2 use x81922808+>0 string \x0eD 8192b2809+>>2 use x81922810+>0 string \x0eF 8192b2811+>>2 use x81922812+>0 string \x0eV 8192b2813+>>2 use x81922814+2815+# PGP RSA (e=65537) secret (sub-)key header2816+2817+0 byte 0x95 PGP Secret Key -2818+>1 use pgpkey2819+0 byte 0x97 PGP Secret Sub-key -2820+>1 use pgpkey2821+0 byte 0x9d PGP Secret Sub-key -2822+>1 use pgpkey2823Index: contrib/file/magic/Magdir/python2824===================================================================2825--- contrib/file/magic/Magdir/python (revision 284174)2826+++ contrib/file/magic/Magdir/python (working copy)2827@@ -1,6 +1,6 @@28282829#------------------------------------------------------------------------------2830-# $File: python,v 1.25 2014/05/06 16:08:32 christos Exp $2831+# $File: python,v 1.26 2014/08/04 05:58:40 christos Exp $2832# python: file(1) magic for python2833#2834# Outlook puts """ too for urgent messages2835@@ -23,6 +23,7 @@28360 belong 0x4f0c0d0a python 3.1 byte-compiled28370 belong 0x6c0c0d0a python 3.2 byte-compiled28380 belong 0x9e0c0d0a python 3.3 byte-compiled2839+0 belong 0xee0c0d0a python 3.4 byte-compiled284028410 search/1/w #!\ /usr/bin/python Python script text executable2842!:mime text/x-python2843Index: contrib/file/magic/Magdir/qt2844===================================================================2845--- contrib/file/magic/Magdir/qt (revision 0)2846+++ contrib/file/magic/Magdir/qt (working copy)2847@@ -0,0 +1,19 @@2848+2849+#------------------------------------------------------------------------------2850+# $File: qt,v 1.2 2014/12/16 19:49:29 christos Exp $2851+# qt: file(1) magic for Qt2852+2853+# http://doc.qt.io/qt-5/resources.html2854+0 string \<!DOCTYPE\040RCC\> Qt Resource Collection file2855+2856+# https://qt.gitorious.org/qt/qtbase/source/\2857+# 5367fa356233da4c0f28172a8f817791525f5457:\2858+# src/tools/rcc/rcc.cpp#L8402859+0 string qres\0\0 Qt Binary Resource file2860+0 search/1024 The\040Resource\040Compiler\040for\040Qt Qt C-code resource file2861+2862+# https://qt.gitorious.org/qt/qtbase/source/\2863+# 5367fa356233da4c0f28172a8f817791525f5457:\2864+# src/corelib/kernel/qtranslator.cpp#L622865+0 string \x3c\xb8\x64\x18\xca\xef\x9c\x952866+>8 string \xcd\x21\x1c\xbf\x60\xa1\xbd\xdd Qt Translation file2867Index: contrib/file/magic/Magdir/riff2868===================================================================2869--- contrib/file/magic/Magdir/riff (revision 284174)2870+++ contrib/file/magic/Magdir/riff (working copy)2871@@ -1,6 +1,6 @@28722873#------------------------------------------------------------------------------2874-# $File: riff,v 1.27 2014/04/30 21:41:02 christos Exp $2875+# $File: riff,v 1.30 2014/09/23 17:02:12 christos Exp $2876# riff: file(1) magic for RIFF format2877# See2878#2879@@ -45,6 +45,26 @@2880>>&(4.l+4) use riff-walk2881>0 string fact2882>>&(4.l+4) use riff-walk2883+>0 string VP82884+>>11 byte 0x9d2885+>>>12 byte 0x012886+>>>>13 byte 0x2a \b, VP8 encoding2887+>>>>>14 leshort&0x3fff x \b, %d2888+>>>>>16 leshort&0x3fff x \bx%d, Scaling:2889+>>>>>14 leshort&0xc000 0x0000 \b [none]2890+>>>>>14 leshort&0xc000 0x1000 \b [5/4]2891+>>>>>14 leshort&0xc000 0x2000 \b [5/3]2892+>>>>>14 leshort&0xc000 0x3000 \b [2]2893+>>>>>14 leshort&0xc000 0x0000 \bx[none]2894+>>>>>14 leshort&0xc000 0x1000 \bx[5/4]2895+>>>>>14 leshort&0xc000 0x2000 \bx[5/3]2896+>>>>>14 leshort&0xc000 0x3000 \bx[2]2897+>>>>>15 byte&0x80 =0x00 \b, YUV color2898+>>>>>15 byte&0x80 =0x80 \b, bad color specification2899+>>>>>15 byte&0x40 =0x40 \b, no clamping required2900+>>>>>15 byte&0x40 =0x00 \b, decoders should clamp2901+#>0 string x we got %s2902+#>>&(4.l+4) use riff-walk29032904# AVI section extended by Patrik Radman <[email protected]>2905#2906@@ -209,6 +229,8 @@2907>8 string 4XMV \b, 4X Movie file2908# AMV-type AVI file: http://wiki.multimedia.cx/index.php?title=AMV2909>8 string AMV\040 \b, AMV2910+>8 string WEBP \b, Web/P image2911+>>12 use riff-walk29122913#2914# XXX - some of the below may only appear in little-endian form.2915@@ -284,4 +306,3 @@2916>>&6 leshort =2 \b, stereo2917>>&6 leshort >2 \b, %d channels2918>>&8 lelong >0 %d Hz2919-2920Index: contrib/file/magic/Magdir/rinex2921===================================================================2922--- contrib/file/magic/Magdir/rinex (revision 284174)2923+++ contrib/file/magic/Magdir/rinex (working copy)2924@@ -1,44 +0,0 @@2925-2926-#------------------------------------------------------------------------------2927-# $File: rinex,v 1.4 2011/05/03 01:44:17 christos Exp $2928-# rinex: file(1) magic for RINEX files2929-# http://igscb.jpl.nasa.gov/igscb/data/format/rinex210.txt2930-# ftp://cddis.gsfc.nasa.gov/pub/reports/formats/rinex300.pdf2931-# data for testing: ftp://cddis.gsfc.nasa.gov/pub/gps/data2932-60 string RINEX2933->80 search/256 XXRINEXB RINEX Data, GEO SBAS Broadcast2934->>&32 string x \b, date %15.15s2935->>5 string x \b, version %6.6s2936-!:mime rinex/broadcast2937->80 search/256 XXRINEXD RINEX Data, Observation (Hatanaka comp)2938->>&32 string x \b, date %15.15s2939->>5 string x \b, version %6.6s2940-!:mime rinex/observation2941->80 search/256 XXRINEXC RINEX Data, Clock2942->>&32 string x \b, date %15.15s2943->>5 string x \b, version %6.6s2944-!:mime rinex/clock2945->80 search/256 XXRINEXH RINEX Data, GEO SBAS Navigation2946->>&32 string x \b, date %15.15s2947->>5 string x \b, version %6.6s2948-!:mime rinex/navigation2949->80 search/256 XXRINEXG RINEX Data, GLONASS Navigation2950->>&32 string x \b, date %15.15s2951->>5 string x \b, version %6.6s2952-!:mime rinex/navigation2953->80 search/256 XXRINEXL RINEX Data, Galileo Navigation2954->>&32 string x \b, date %15.15s2955->>5 string x \b, version %6.6s2956-!:mime rinex/navigation2957->80 search/256 XXRINEXM RINEX Data, Meteorological2958->>&32 string x \b, date %15.15s2959->>5 string x \b, version %6.6s2960-!:mime rinex/meteorological2961->80 search/256 XXRINEXN RINEX Data, Navigation2962->>&32 string x \b, date %15.15s2963->>5 string x \b, version %6.6s2964-!:mime rinex/navigation2965->80 search/256 XXRINEXO RINEX Data, Observation2966->>&32 string x \b, date %15.15s2967->>5 string x \b, version %6.6s2968-!:mime rinex/observation2969Index: contrib/file/magic/Magdir/sequent2970===================================================================2971--- contrib/file/magic/Magdir/sequent (revision 284174)2972+++ contrib/file/magic/Magdir/sequent (working copy)2973@@ -1,6 +1,6 @@29742975#------------------------------------------------------------------------------2976-# $File: sequent,v 1.11 2014/06/02 19:27:54 christos Exp $2977+# $File: sequent,v 1.12 2014/08/16 16:07:12 christos Exp $2978# sequent: file(1) magic for Sequent machines2979#2980# Sequent information updated by Don Dwiggins <atsun!dwiggins>.2981@@ -30,9 +30,6 @@29820 leshort 0x32eb SYMMETRY i386 executable (invalid @ 0)2983>16 lelong >0 not stripped2984>124 lelong >0 version %d2985-0 leshort 0x42eb SYMMETRY i386 standalone executable2986->16 lelong >0 not stripped2987->124 lelong >0 version %d2988# http://en.wikipedia.org/wiki/Sequent_Computer_Systems2989# below test line conflicts with MS-DOS 2.11 floppies and Acronis loader2990#0 leshort 0x42eb SYMMETRY i386 standalone executable2991Index: contrib/file/magic/Magdir/sereal2992===================================================================2993--- contrib/file/magic/Magdir/sereal (revision 284174)2994+++ contrib/file/magic/Magdir/sereal (working copy)2995@@ -1,5 +1,6 @@2996+2997#------------------------------------------------------------------------------2998-# $File: sereal,v 1.1 2014/05/14 23:04:59 christos Exp $2999+# $File: sereal,v 1.2 2014/11/11 20:10:49 christos Exp $3000# sereal: file(1) magic the Sereal binary serialization format3001#3002# From: Ævar Arnfjörð Bjarmason <[email protected]>3003@@ -15,10 +16,10 @@3004#3005# See https://github.com/Sereal/Sereal/commit/35372ae01d in the3006# Sereal.git repository for test Sereal data.3007-0 string \=srl Sereal data3008+0 string \=srl Sereal data3009!:mime application/sereal3010->4 byte&0x0F x (version %d,3011->4 byte&0xF0 0x00 uncompressed)3012->4 byte&0xF0 0x10 compressed with non-incremental Snappy)3013->4 byte&0xF0 0x20 compressed with incremental Snappy)3014->4 byte&0xF0 >0x20 unknown subformat, flag: %d>>4)3015+>4 byte&0x0F x (version %d,3016+>4 byte&0xF0 0x00 uncompressed)3017+>4 byte&0xF0 0x10 compressed with non-incremental Snappy)3018+>4 byte&0xF0 0x20 compressed with incremental Snappy)3019+>4 byte&0xF0 >0x20 unknown subformat, flag: %d>>4)3020Index: contrib/file/magic/Magdir/ssh3021===================================================================3022--- contrib/file/magic/Magdir/ssh (revision 284174)3023+++ contrib/file/magic/Magdir/ssh (working copy)3024@@ -3,6 +3,7 @@302530260 string SSH\ PRIVATE\ KEY OpenSSH RSA1 private key,3027>28 string >\0 version %s3028+0 string -----BEGIN\ OPENSSH\ PRIVATE\ KEY----- OpenSSH private key302930300 string ssh-dss\ OpenSSH DSA public key30310 string ssh-rsa\ OpenSSH RSA public key3032@@ -9,3 +10,4 @@30330 string ecdsa-sha2-nistp256 OpenSSH ECDSA public key30340 string ecdsa-sha2-nistp384 OpenSSH ECDSA public key30350 string ecdsa-sha2-nistp521 OpenSSH ECDSA public key3036+0 string ssh-ed25519 OpenSSH ED25519 public key3037Index: contrib/file/magic/Magdir/vms3038===================================================================3039--- contrib/file/magic/Magdir/vms (revision 284174)3040+++ contrib/file/magic/Magdir/vms (working copy)3041@@ -1,6 +1,6 @@30423043#------------------------------------------------------------------------------3044-# $File: vms,v 1.7 2013/03/09 22:36:00 christos Exp $3045+# $File: vms,v 1.9 2014/08/17 13:47:59 christos Exp $3046# vms: file(1) magic for VMS executables (experimental)3047#3048# VMS .exe formats, both VAX and AXP (Greg Roelofs, [email protected])3049Index: contrib/file/magic/Magdir/vorbis3050===================================================================3051--- contrib/file/magic/Magdir/vorbis (revision 284174)3052+++ contrib/file/magic/Magdir/vorbis (working copy)3053@@ -1,6 +1,6 @@30543055#------------------------------------------------------------------------------3056-# $File: vorbis,v 1.18 2014/04/30 21:41:02 christos Exp $3057+# $File: vorbis,v 1.20 2014/09/23 16:35:08 christos Exp $3058# vorbis: file(1) magic for Ogg/Vorbis files3059#3060# From Felix von Leitner <[email protected]>3061@@ -23,7 +23,6 @@3062# --- Ogg Framing ---3063#0 search/1000 OggS Ogg data30640 string OggS Ogg data3065-!:mime application/ogg3066>4 byte !0 UNKNOWN REVISION %u3067##>4 byte 0 revision 03068>4 byte 03069@@ -31,9 +30,12 @@3070# non-Vorbis content: FLAC (Free Lossless Audio Codec, http://flac.sourceforge.net)3071>>28 string \x7fFLAC \b, FLAC audio3072# non-Vorbis content: Theora3073+!:mime audio/ogg3074>>28 string \x80theora \b, Theora video3075+!:mime video/ogg3076# non-Vorbis content: Kate3077->>28 string \x80kate\0\0\0\0 \b, Kate3078+>>28 string \x80kate\0\0\0\0 \b, Kate (Karaoke and Text)3079+!:mime application/ogg3080>>>37 ubyte x v%u3081>>>38 ubyte x \b.%u,3082>>>40 byte 0 utf8 encoding,3083@@ -44,12 +46,15 @@3084>>>76 string \0 no category set3085# non-Vorbis content: Skeleton3086>>28 string fishead\0 \b, Skeleton3087+!:mime video/ogg3088>>>36 short x v%u3089>>>40 short x \b.%u3090# non-Vorbis content: Speex3091>>28 string Speex\ \ \ \b, Speex audio3092+!:mime audio/ogg3093# non-Vorbis content: OGM3094>>28 string \x01video\0\0\0 \b, OGM video3095+!:mime video/ogg3096>>>37 string/c div3 (DivX 3)3097>>>37 string/c divx (DivX 4)3098>>>37 string/c dx50 (DivX 5)3099@@ -56,6 +61,7 @@3100>>>37 string/c xvid (XviD)3101# --- First vorbis packet - general header ---3102>>28 string \x01vorbis \b, Vorbis audio,3103+!:mime audio/ogg3104>>>35 lelong !0 UNKNOWN VERSION %u,3105##>>>35 lelong 0 version 0,3106>>>35 lelong 03107Index: contrib/file/magic/Magdir/windows3108===================================================================3109--- contrib/file/magic/Magdir/windows (revision 284174)3110+++ contrib/file/magic/Magdir/windows (working copy)3111@@ -1,6 +1,6 @@31123113#------------------------------------------------------------------------------3114-# $File: windows,v 1.8 2014/04/30 21:41:02 christos Exp $3115+# $File: windows,v 1.10 2014/09/24 19:52:46 christos Exp $3116# windows: file(1) magic for Microsoft Windows3117#3118# This file is mainly reserved for files where programs3119@@ -159,8 +159,9 @@3120>&0 string Version\ 5.00\r\n\r\n Windows Registry text (Win2K or above)31213122# Windows *.INF *.INI files updated by Joerg Jenderek at Apr 20133123-# emtpy ,comment , section , unicode line3124-0 regex/s \\`(\r\n|;|[[]|\xFF\xFE)3125+# empty ,comment , section3126+# PR/383: remove unicode BOM because it is not portable across regex impls3127+0 regex/s \\`(\\r\\n|;|[[])3128# left bracket in section line3129>&0 search/8192 [3130# http://en.wikipedia.org/wiki/Autorun.inf3131Index: contrib/file/magic/Makefile.am3132===================================================================3133--- contrib/file/magic/Makefile.am (revision 284174)3134+++ contrib/file/magic/Makefile.am (working copy)3135@@ -1,5 +1,5 @@3136#3137-# $File: Makefile.am,v 1.98 2014/06/03 18:22:34 christos Exp $3138+# $File: Makefile.am,v 1.101 2014/12/12 16:48:39 christos Exp $3139#3140MAGIC_FRAGMENT_BASE = Magdir3141MAGIC_DIR = $(top_srcdir)/magic3142@@ -117,6 +117,7 @@ $(MAGIC_FRAGMENT_DIR)/jpeg \3143$(MAGIC_FRAGMENT_DIR)/karma \3144$(MAGIC_FRAGMENT_DIR)/kde \3145$(MAGIC_FRAGMENT_DIR)/keepass \3146+$(MAGIC_FRAGMENT_DIR)/kerberos \3147$(MAGIC_FRAGMENT_DIR)/kml \3148$(MAGIC_FRAGMENT_DIR)/lecter \3149$(MAGIC_FRAGMENT_DIR)/lex \3150@@ -142,6 +143,7 @@ $(MAGIC_FRAGMENT_DIR)/matroska \3151$(MAGIC_FRAGMENT_DIR)/mcrypt \3152$(MAGIC_FRAGMENT_DIR)/mercurial \3153$(MAGIC_FRAGMENT_DIR)/metastore \3154+$(MAGIC_FRAGMENT_DIR)/meteorological \3155$(MAGIC_FRAGMENT_DIR)/mime \3156$(MAGIC_FRAGMENT_DIR)/mips \3157$(MAGIC_FRAGMENT_DIR)/mirage \3158@@ -196,9 +198,9 @@ $(MAGIC_FRAGMENT_DIR)/pulsar \3159$(MAGIC_FRAGMENT_DIR)/pwsafe \3160$(MAGIC_FRAGMENT_DIR)/pyramid \3161$(MAGIC_FRAGMENT_DIR)/python \3162+$(MAGIC_FRAGMENT_DIR)/qt \3163$(MAGIC_FRAGMENT_DIR)/revision \3164$(MAGIC_FRAGMENT_DIR)/riff \3165-$(MAGIC_FRAGMENT_DIR)/rinex \3166$(MAGIC_FRAGMENT_DIR)/rpm \3167$(MAGIC_FRAGMENT_DIR)/rtf \3168$(MAGIC_FRAGMENT_DIR)/ruby \3169Index: contrib/file/magic/Makefile.in3170===================================================================3171--- contrib/file/magic/Makefile.in (revision 284174)3172+++ contrib/file/magic/Makefile.in (working copy)3173@@ -262,7 +262,7 @@ top_builddir = @top_builddir@3174top_srcdir = @top_srcdir@31753176#3177-# $File: Makefile.am,v 1.98 2014/06/03 18:22:34 christos Exp $3178+# $File: Makefile.am,v 1.101 2014/12/12 16:48:39 christos Exp $3179#3180MAGIC_FRAGMENT_BASE = Magdir3181MAGIC_DIR = $(top_srcdir)/magic3182@@ -378,6 +378,7 @@ $(MAGIC_FRAGMENT_DIR)/jpeg \3183$(MAGIC_FRAGMENT_DIR)/karma \3184$(MAGIC_FRAGMENT_DIR)/kde \3185$(MAGIC_FRAGMENT_DIR)/keepass \3186+$(MAGIC_FRAGMENT_DIR)/kerberos \3187$(MAGIC_FRAGMENT_DIR)/kml \3188$(MAGIC_FRAGMENT_DIR)/lecter \3189$(MAGIC_FRAGMENT_DIR)/lex \3190@@ -403,6 +404,7 @@ $(MAGIC_FRAGMENT_DIR)/matroska \3191$(MAGIC_FRAGMENT_DIR)/mcrypt \3192$(MAGIC_FRAGMENT_DIR)/mercurial \3193$(MAGIC_FRAGMENT_DIR)/metastore \3194+$(MAGIC_FRAGMENT_DIR)/meteorological \3195$(MAGIC_FRAGMENT_DIR)/mime \3196$(MAGIC_FRAGMENT_DIR)/mips \3197$(MAGIC_FRAGMENT_DIR)/mirage \3198@@ -457,9 +459,9 @@ $(MAGIC_FRAGMENT_DIR)/pulsar \3199$(MAGIC_FRAGMENT_DIR)/pwsafe \3200$(MAGIC_FRAGMENT_DIR)/pyramid \3201$(MAGIC_FRAGMENT_DIR)/python \3202+$(MAGIC_FRAGMENT_DIR)/qt \3203$(MAGIC_FRAGMENT_DIR)/revision \3204$(MAGIC_FRAGMENT_DIR)/riff \3205-$(MAGIC_FRAGMENT_DIR)/rinex \3206$(MAGIC_FRAGMENT_DIR)/rpm \3207$(MAGIC_FRAGMENT_DIR)/rtf \3208$(MAGIC_FRAGMENT_DIR)/ruby \3209Index: contrib/file/src/Makefile.in3210===================================================================3211--- contrib/file/src/Makefile.in (revision 284174)3212+++ contrib/file/src/Makefile.in (working copy)3213@@ -81,9 +81,9 @@ build_triplet = @build@3214host_triplet = @host@3215bin_PROGRAMS = file$(EXEEXT)3216subdir = src3217-DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am pread.c \3218- ctime_r.c getline.c vasprintf.c asprintf.c asctime_r.c \3219- fmtcheck.c strlcpy.c getopt_long.c strcasestr.c strlcat.c \3220+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am ctime_r.c \3221+ vasprintf.c asctime_r.c asprintf.c strcasestr.c pread.c \3222+ getline.c strlcpy.c strlcat.c fmtcheck.c getopt_long.c \3223$(top_srcdir)/depcomp $(include_HEADERS)3224ACLOCAL_M4 = $(top_srcdir)/aclocal.m43225am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \3226Index: contrib/file/src/apprentice.c3227===================================================================3228--- contrib/file/src/apprentice.c (revision 284174)3229+++ contrib/file/src/apprentice.c (working copy)3230@@ -32,7 +32,7 @@3231#include "file.h"32323233#ifndef lint3234-FILE_RCSID("@(#)$File: apprentice.c,v 1.211 2014/06/03 19:01:34 christos Exp $")3235+FILE_RCSID("@(#)$File: apprentice.c,v 1.229 2015/01/01 17:07:34 christos Exp $")3236#endif /* lint */32373238#include "magic.h"3239@@ -86,6 +86,10 @@3240#define ALLOC_CHUNK (size_t)103241#define ALLOC_INCR (size_t)20032423243+#define MAP_TYPE_MMAP 03244+#define MAP_TYPE_MALLOC 13245+#define MAP_TYPE_USER 23246+3247struct magic_entry {3248struct magic *mp;3249uint32_t cont_count;3250@@ -101,6 +105,7 @@ struct magic_entry_set {3251struct magic_map {3252void *p;3253size_t len;3254+ int type;3255struct magic *magic[MAGIC_SETS];3256uint32_t nmagic[MAGIC_SETS];3257};3258@@ -131,7 +136,10 @@ private uint16_t swap2(uint16_t);3259private uint32_t swap4(uint32_t);3260private uint64_t swap8(uint64_t);3261private char *mkdbname(struct magic_set *, const char *, int);3262+private struct magic_map *apprentice_buf(struct magic_set *, struct magic *,3263+ size_t);3264private struct magic_map *apprentice_map(struct magic_set *, const char *);3265+private int check_buffer(struct magic_set *, struct magic_map *, const char *);3266private void apprentice_unmap(struct magic_map *);3267private int apprentice_compile(struct magic_set *, struct magic_map *,3268const char *);3269@@ -396,10 +404,11 @@ add_mlist(struct mlist *mlp, struct magic_map *map3270{3271struct mlist *ml;32723273+ mlp->map = idx == 0 ? map : NULL;3274if ((ml = CAST(struct mlist *, malloc(sizeof(*ml)))) == NULL)3275return -1;32763277- ml->map = idx == 0 ? map : NULL;3278+ ml->map = NULL;3279ml->magic = map->magic[idx];3280ml->nmagic = map->nmagic[idx];32813282@@ -416,13 +425,11 @@ add_mlist(struct mlist *mlp, struct magic_map *map3283private int3284apprentice_1(struct magic_set *ms, const char *fn, int action)3285{3286+ struct magic_map *map;3287#ifndef COMPILE_ONLY3288struct mlist *ml;3289-#endif /* COMPILE_ONLY */3290- struct magic_map *map;3291-#ifndef COMPILE_ONLY3292size_t i;3293-#endif /* COMPILE_ONLY */3294+#endif32953296if (magicsize != FILE_MAGICSIZE) {3297file_error(ms, 0, "magic element size %lu != %lu",3298@@ -451,22 +458,29 @@ apprentice_1(struct magic_set *ms, const char *fn,3299for (i = 0; i < MAGIC_SETS; i++) {3300if (add_mlist(ms->mlist[i], map, i) == -1) {3301file_oomem(ms, sizeof(*ml));3302- apprentice_unmap(map);3303- return -1;3304+ goto fail;3305}3306}33073308if (action == FILE_LIST) {3309for (i = 0; i < MAGIC_SETS; i++) {3310- printf("Set %zu:\nBinary patterns:\n", i);3311+ printf("Set %" SIZE_T_FORMAT "u:\nBinary patterns:\n",3312+ i);3313apprentice_list(ms->mlist[i], BINTEST);3314printf("Text patterns:\n");3315apprentice_list(ms->mlist[i], TEXTTEST);3316}3317}3318+ return 0;3319+fail:3320+ for (i = 0; i < MAGIC_SETS; i++) {3321+ mlist_free(ms->mlist[i]);3322+ ms->mlist[i] = NULL;3323+ }3324+ return -1;3325+#else3326+ return 0;3327#endif /* COMPILE_ONLY */3328-3329- return 0;3330}33313332protected void3333@@ -510,6 +524,11 @@ file_ms_alloc(int flags)3334ms->mlist[i] = NULL;3335ms->file = "unknown";3336ms->line = 0;3337+ ms->indir_max = FILE_INDIR_MAX;3338+ ms->name_max = FILE_NAME_MAX;3339+ ms->elf_shnum_max = FILE_ELF_SHNUM_MAX;3340+ ms->elf_phnum_max = FILE_ELF_PHNUM_MAX;3341+ ms->elf_notes_max = FILE_ELF_NOTES_MAX;3342return ms;3343free:3344free(ms);3345@@ -521,17 +540,21 @@ apprentice_unmap(struct magic_map *map)3346{3347if (map == NULL)3348return;3349- if (map->p != NULL) {3350+3351+ switch (map->type) {3352#ifdef QUICK3353- if (map->len)3354+ case MAP_TYPE_MMAP:3355+ if (map->p)3356(void)munmap(map->p, map->len);3357- else3358+ break;3359#endif3360+ case MAP_TYPE_MALLOC:3361free(map->p);3362- } else {3363- uint32_t j;3364- for (j = 0; j < MAGIC_SETS; j++)3365- free(map->magic[j]);3366+ break;3367+ case MAP_TYPE_USER:3368+ break;3369+ default:3370+ abort();3371}3372free(map);3373}3374@@ -550,21 +573,70 @@ mlist_alloc(void)3375private void3376mlist_free(struct mlist *mlist)3377{3378- struct mlist *ml;3379+ struct mlist *ml, *next;33803381if (mlist == NULL)3382return;33833384- for (ml = mlist->next; ml != mlist;) {3385- struct mlist *next = ml->next;3386+ ml = mlist->next;3387+ for (ml = mlist->next; (next = ml->next) != NULL; ml = next) {3388if (ml->map)3389apprentice_unmap(ml->map);3390free(ml);3391- ml = next;3392+ if (ml == mlist)3393+ break;3394}3395- free(ml);3396}33973398+#ifndef COMPILE_ONLY3399+/* void **bufs: an array of compiled magic files */3400+protected int3401+buffer_apprentice(struct magic_set *ms, struct magic **bufs,3402+ size_t *sizes, size_t nbufs)3403+{3404+ size_t i, j;3405+ struct mlist *ml;3406+ struct magic_map *map;3407+3408+ if (nbufs == 0)3409+ return -1;3410+3411+ if (ms->mlist[0] != NULL)3412+ file_reset(ms);3413+3414+ init_file_tables();3415+3416+ for (i = 0; i < MAGIC_SETS; i++) {3417+ mlist_free(ms->mlist[i]);3418+ if ((ms->mlist[i] = mlist_alloc()) == NULL) {3419+ file_oomem(ms, sizeof(*ms->mlist[i]));3420+ goto fail;3421+ }3422+ }3423+3424+ for (i = 0; i < nbufs; i++) {3425+ map = apprentice_buf(ms, bufs[i], sizes[i]);3426+ if (map == NULL)3427+ goto fail;3428+3429+ for (j = 0; j < MAGIC_SETS; j++) {3430+ if (add_mlist(ms->mlist[j], map, j) == -1) {3431+ file_oomem(ms, sizeof(*ml));3432+ goto fail;3433+ }3434+ }3435+ }3436+3437+ return 0;3438+fail:3439+ for (i = 0; i < MAGIC_SETS; i++) {3440+ mlist_free(ms->mlist[i]);3441+ ms->mlist[i] = NULL;3442+ }3443+ return -1;3444+}3445+#endif3446+3447/* const char *fn: list of magic files and directories */3448protected int3449file_apprentice(struct magic_set *ms, const char *fn, int action)3450@@ -590,11 +662,9 @@ file_apprentice(struct magic_set *ms, const char *3451mlist_free(ms->mlist[i]);3452if ((ms->mlist[i] = mlist_alloc()) == NULL) {3453file_oomem(ms, sizeof(*ms->mlist[i]));3454- if (i != 0) {3455- --i;3456- do3457- mlist_free(ms->mlist[i]);3458- while (i != 0);3459+ while (i-- > 0) {3460+ mlist_free(ms->mlist[i]);3461+ ms->mlist[i] = NULL;3462}3463free(mfn);3464return -1;3465@@ -1317,7 +1387,7 @@ file_signextend(struct magic_set *ms, struct magic3466* the sign extension must have happened.3467*/3468case FILE_BYTE:3469- v = (char) v;3470+ v = (signed char) v;3471break;3472case FILE_SHORT:3473case FILE_BESHORT:3474@@ -1535,6 +1605,145 @@ check_cond(struct magic_set *ms, int cond, uint32_3475}3476#endif /* ENABLE_CONDITIONALS */34773478+private int3479+parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp)3480+{3481+ const char *l = *lp;3482+3483+ while (!isspace((unsigned char)*++l))3484+ switch (*l) {3485+ case CHAR_INDIRECT_RELATIVE:3486+ m->str_flags |= INDIRECT_RELATIVE;3487+ break;3488+ default:3489+ if (ms->flags & MAGIC_CHECK)3490+ file_magwarn(ms, "indirect modifier `%c' "3491+ "invalid", *l);3492+ *lp = l;3493+ return -1;3494+ }3495+ *lp = l;3496+ return 0;3497+}3498+3499+private void3500+parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp,3501+ int op)3502+{3503+ const char *l = *lp;3504+ char *t;3505+ uint64_t val;3506+3507+ ++l;3508+ m->mask_op |= op;3509+ val = (uint64_t)strtoull(l, &t, 0);3510+ l = t;3511+ m->num_mask = file_signextend(ms, m, val);3512+ eatsize(&l);3513+ *lp = l;3514+}3515+3516+private int3517+parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp)3518+{3519+ const char *l = *lp;3520+ char *t;3521+ int have_range = 0;3522+3523+ while (!isspace((unsigned char)*++l)) {3524+ switch (*l) {3525+ case '0': case '1': case '2':3526+ case '3': case '4': case '5':3527+ case '6': case '7': case '8':3528+ case '9':3529+ if (have_range && (ms->flags & MAGIC_CHECK))3530+ file_magwarn(ms, "multiple ranges");3531+ have_range = 1;3532+ m->str_range = CAST(uint32_t, strtoul(l, &t, 0));3533+ if (m->str_range == 0)3534+ file_magwarn(ms, "zero range");3535+ l = t - 1;3536+ break;3537+ case CHAR_COMPACT_WHITESPACE:3538+ m->str_flags |= STRING_COMPACT_WHITESPACE;3539+ break;3540+ case CHAR_COMPACT_OPTIONAL_WHITESPACE:3541+ m->str_flags |= STRING_COMPACT_OPTIONAL_WHITESPACE;3542+ break;3543+ case CHAR_IGNORE_LOWERCASE:3544+ m->str_flags |= STRING_IGNORE_LOWERCASE;3545+ break;3546+ case CHAR_IGNORE_UPPERCASE:3547+ m->str_flags |= STRING_IGNORE_UPPERCASE;3548+ break;3549+ case CHAR_REGEX_OFFSET_START:3550+ m->str_flags |= REGEX_OFFSET_START;3551+ break;3552+ case CHAR_BINTEST:3553+ m->str_flags |= STRING_BINTEST;3554+ break;3555+ case CHAR_TEXTTEST:3556+ m->str_flags |= STRING_TEXTTEST;3557+ break;3558+ case CHAR_TRIM:3559+ m->str_flags |= STRING_TRIM;3560+ break;3561+ case CHAR_PSTRING_1_LE:3562+#define SET_LENGTH(a) m->str_flags = (m->str_flags & ~PSTRING_LEN) | (a)3563+ if (m->type != FILE_PSTRING)3564+ goto bad;3565+ SET_LENGTH(PSTRING_1_LE);3566+ break;3567+ case CHAR_PSTRING_2_BE:3568+ if (m->type != FILE_PSTRING)3569+ goto bad;3570+ SET_LENGTH(PSTRING_2_BE);3571+ break;3572+ case CHAR_PSTRING_2_LE:3573+ if (m->type != FILE_PSTRING)3574+ goto bad;3575+ SET_LENGTH(PSTRING_2_LE);3576+ break;3577+ case CHAR_PSTRING_4_BE:3578+ if (m->type != FILE_PSTRING)3579+ goto bad;3580+ SET_LENGTH(PSTRING_4_BE);3581+ break;3582+ case CHAR_PSTRING_4_LE:3583+ switch (m->type) {3584+ case FILE_PSTRING:3585+ case FILE_REGEX:3586+ break;3587+ default:3588+ goto bad;3589+ }3590+ SET_LENGTH(PSTRING_4_LE);3591+ break;3592+ case CHAR_PSTRING_LENGTH_INCLUDES_ITSELF:3593+ if (m->type != FILE_PSTRING)3594+ goto bad;3595+ m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF;3596+ break;3597+ default:3598+ bad:3599+ if (ms->flags & MAGIC_CHECK)3600+ file_magwarn(ms, "string modifier `%c' "3601+ "invalid", *l);3602+ goto out;3603+ }3604+ /* allow multiple '/' for readability */3605+ if (l[1] == '/' && !isspace((unsigned char)l[2]))3606+ l++;3607+ }3608+ if (string_modifier_check(ms, m) == -1)3609+ goto out;3610+ *lp = l;3611+ return 0;3612+out:3613+ *lp = l;3614+ return -1;3615+}3616+3617/*3618* parse one line from magic file, put into magic[index++] if valid3619*/3620@@ -1804,118 +2013,27 @@ parse(struct magic_set *ms, struct magic_entry *me3621m->str_range = 0;3622m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0;3623if ((op = get_op(*l)) != -1) {3624- if (!IS_STRING(m->type)) {3625- uint64_t val;3626- ++l;3627- m->mask_op |= op;3628- val = (uint64_t)strtoull(l, &t, 0);3629- l = t;3630- m->num_mask = file_signextend(ms, m, val);3631- eatsize(&l);3632- }3633- else if (op == FILE_OPDIVIDE) {3634- int have_range = 0;3635- while (!isspace((unsigned char)*++l)) {3636- switch (*l) {3637- case '0': case '1': case '2':3638- case '3': case '4': case '5':3639- case '6': case '7': case '8':3640- case '9':3641- if (have_range &&3642- (ms->flags & MAGIC_CHECK))3643- file_magwarn(ms,3644- "multiple ranges");3645- have_range = 1;3646- m->str_range = CAST(uint32_t,3647- strtoul(l, &t, 0));3648- if (m->str_range == 0)3649- file_magwarn(ms,3650- "zero range");3651- l = t - 1;3652- break;3653- case CHAR_COMPACT_WHITESPACE:3654- m->str_flags |=3655- STRING_COMPACT_WHITESPACE;3656- break;3657- case CHAR_COMPACT_OPTIONAL_WHITESPACE:3658- m->str_flags |=3659- STRING_COMPACT_OPTIONAL_WHITESPACE;3660- break;3661- case CHAR_IGNORE_LOWERCASE:3662- m->str_flags |= STRING_IGNORE_LOWERCASE;3663- break;3664- case CHAR_IGNORE_UPPERCASE:3665- m->str_flags |= STRING_IGNORE_UPPERCASE;3666- break;3667- case CHAR_REGEX_OFFSET_START:3668- m->str_flags |= REGEX_OFFSET_START;3669- break;3670- case CHAR_BINTEST:3671- m->str_flags |= STRING_BINTEST;3672- break;3673- case CHAR_TEXTTEST:3674- m->str_flags |= STRING_TEXTTEST;3675- break;3676- case CHAR_TRIM:3677- m->str_flags |= STRING_TRIM;3678- break;3679- case CHAR_PSTRING_1_LE:3680- if (m->type != FILE_PSTRING)3681- goto bad;3682- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_1_LE;3683- break;3684- case CHAR_PSTRING_2_BE:3685- if (m->type != FILE_PSTRING)3686- goto bad;3687- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_BE;3688- break;3689- case CHAR_PSTRING_2_LE:3690- if (m->type != FILE_PSTRING)3691- goto bad;3692- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_LE;3693- break;3694- case CHAR_PSTRING_4_BE:3695- if (m->type != FILE_PSTRING)3696- goto bad;3697- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_BE;3698- break;3699- case CHAR_PSTRING_4_LE:3700- switch (m->type) {3701- case FILE_PSTRING:3702- case FILE_REGEX:3703- break;3704- default:3705- goto bad;3706- }3707- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_LE;3708- break;3709- case CHAR_PSTRING_LENGTH_INCLUDES_ITSELF:3710- if (m->type != FILE_PSTRING)3711- goto bad;3712- m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF;3713- break;3714- default:3715- bad:3716- if (ms->flags & MAGIC_CHECK)3717- file_magwarn(ms,3718- "string extension `%c' "3719- "invalid", *l);3720- return -1;3721- }3722- /* allow multiple '/' for readability */3723- if (l[1] == '/' &&3724- !isspace((unsigned char)l[2]))3725- l++;3726+ if (IS_STRING(m->type)) {3727+ int r;3728+3729+ if (op != FILE_OPDIVIDE) {3730+ if (ms->flags & MAGIC_CHECK)3731+ file_magwarn(ms,3732+ "invalid string/indirect op: "3733+ "`%c'", *t);3734+ return -1;3735}3736- if (string_modifier_check(ms, m) == -1)3737+3738+ if (m->type == FILE_INDIRECT)3739+ r = parse_indirect_modifier(ms, m, &l);3740+ else3741+ r = parse_string_modifier(ms, m, &l);3742+ if (r == -1)3743return -1;3744- }3745- else {3746- if (ms->flags & MAGIC_CHECK)3747- file_magwarn(ms, "invalid string op: %c", *t);3748- return -1;3749- }3750+ } else3751+ parse_op_modifier(ms, m, &l, op);3752}3753+3754/*3755* We used to set mask to all 1's here, instead let's just not do3756* anything if mask = 0 (unless you have a better idea)3757@@ -2069,8 +2187,14 @@ out:3758}37593760private int3761+goodchar(unsigned char x, const char *extra)3762+{3763+ return (isascii(x) && isalnum(x)) || strchr(extra, x);3764+}3765+3766+private int3767parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,3768- off_t off, size_t len, const char *name, int nt)3769+ off_t off, size_t len, const char *name, const char *extra, int nt)3770{3771size_t i;3772const char *l = line;3773@@ -2091,9 +2215,7 @@ parse_extra(struct magic_set *ms, struct magic_ent3774}37753776EATAB;3777- for (i = 0; *l && ((isascii((unsigned char)*l) &&3778- isalnum((unsigned char)*l)) || strchr("-+/.", *l)) &&3779- i < len; buf[i++] = *l++)3780+ for (i = 0; *l && i < len && goodchar(*l, extra); buf[i++] = *l++)3781continue;37823783if (i == len && *l) {3784@@ -2103,6 +2225,9 @@ parse_extra(struct magic_set *ms, struct magic_ent3785file_magwarn(ms, "%s type `%s' truncated %"3786SIZE_T_FORMAT "u", name, line, i);3787} else {3788+ if (!isspace((unsigned char)*l) && !goodchar(*l, extra))3789+ file_magwarn(ms, "%s type `%s' has bad char '%c'",3790+ name, line, *l);3791if (nt)3792buf[i] = '\0';3793}3794@@ -2109,8 +2234,9 @@ parse_extra(struct magic_set *ms, struct magic_ent37953796if (i > 0)3797return 0;3798- else3799- return -1;3800+3801+ file_magerror(ms, "Bad magic entry '%s'", line);3802+ return -1;3803}38043805/*3806@@ -2123,7 +2249,7 @@ parse_apple(struct magic_set *ms, struct magic_ent3807struct magic *m = &me->mp[0];38083809return parse_extra(ms, me, line, offsetof(struct magic, apple),3810- sizeof(m->apple), "APPLE", 0);3811+ sizeof(m->apple), "APPLE", "!+-./", 0);3812}38133814/*3815@@ -2136,7 +2262,7 @@ parse_mime(struct magic_set *ms, struct magic_entr3816struct magic *m = &me->mp[0];38173818return parse_extra(ms, me, line, offsetof(struct magic, mimetype),3819- sizeof(m->mimetype), "MIME", 1);3820+ sizeof(m->mimetype), "MIME", "+-/.", 1);3821}38223823private int3824@@ -2697,6 +2823,28 @@ eatsize(const char **p)3825}38263827/*3828+ * handle a buffer containing a compiled file.3829+ */3830+private struct magic_map *3831+apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len)3832+{3833+ struct magic_map *map;3834+3835+ if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {3836+ file_oomem(ms, sizeof(*map));3837+ return NULL;3838+ }3839+ map->len = len;3840+ map->p = buf;3841+ map->type = MAP_TYPE_USER;3842+ if (check_buffer(ms, map, "buffer") != 0) {3843+ apprentice_unmap(map);3844+ return NULL;3845+ }3846+ return map;3847+}3848+3849+/*3850* handle a compiled file.3851*/38523853@@ -2705,12 +2853,8 @@ apprentice_map(struct magic_set *ms, const char *f3854{3855int fd;3856struct stat st;3857- uint32_t *ptr;3858- uint32_t version, entries, nentries;3859- int needsbyteswap;3860char *dbname = NULL;3861struct magic_map *map;3862- size_t i;38633864fd = -1;3865if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {3866@@ -2742,6 +2886,7 @@ apprentice_map(struct magic_set *ms, const char *f3867file_error(ms, errno, "cannot map `%s'", dbname);3868goto error;3869}3870+ map->type = MAP_TYPE_MMAP;3871#else3872if ((map->p = CAST(void *, malloc(map->len))) == NULL) {3873file_oomem(ms, map->len);3874@@ -2751,16 +2896,39 @@ apprentice_map(struct magic_set *ms, const char *f3875file_badread(ms);3876goto error;3877}3878- map->len = 0;3879+ map->type = MAP_TYPE_MALLOC;3880#define RET 13881#endif3882(void)close(fd);3883fd = -1;3884+3885+ if (check_buffer(ms, map, dbname) != 0)3886+ goto error;3887+3888+ free(dbname);3889+ return map;3890+3891+error:3892+ if (fd != -1)3893+ (void)close(fd);3894+ apprentice_unmap(map);3895+ free(dbname);3896+ return NULL;3897+}3898+3899+private int3900+check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)3901+{3902+ uint32_t *ptr;3903+ uint32_t entries, nentries;3904+ uint32_t version;3905+ int i, needsbyteswap;3906+3907ptr = CAST(uint32_t *, map->p);3908if (*ptr != MAGICNO) {3909if (swap4(*ptr) != MAGICNO) {3910file_error(ms, 0, "bad magic in `%s'", dbname);3911- goto error;3912+ return -1;3913}3914needsbyteswap = 1;3915} else3916@@ -2773,15 +2941,14 @@ apprentice_map(struct magic_set *ms, const char *f3917file_error(ms, 0, "File %s supports only version %d magic "3918"files. `%s' is version %d", VERSION,3919VERSIONNO, dbname, version);3920- goto error;3921+ return -1;3922}3923- entries = (uint32_t)(st.st_size / sizeof(struct magic));3924- if ((off_t)(entries * sizeof(struct magic)) != st.st_size) {3925- file_error(ms, 0, "Size of `%s' %" INT64_T_FORMAT "u is not "3926+ entries = (uint32_t)(map->len / sizeof(struct magic));3927+ if ((entries * sizeof(struct magic)) != map->len) {3928+ file_error(ms, 0, "Size of `%s' %" SIZE_T_FORMAT "u is not "3929"a multiple of %" SIZE_T_FORMAT "u",3930- dbname, (unsigned long long)st.st_size,3931- sizeof(struct magic));3932- goto error;3933+ dbname, map->len, sizeof(struct magic));3934+ return -1;3935}3936map->magic[0] = CAST(struct magic *, map->p) + 1;3937nentries = 0;3938@@ -2797,20 +2964,12 @@ apprentice_map(struct magic_set *ms, const char *f3939if (entries != nentries + 1) {3940file_error(ms, 0, "Inconsistent entries in `%s' %u != %u",3941dbname, entries, nentries + 1);3942- goto error;3943+ return -1;3944}3945if (needsbyteswap)3946for (i = 0; i < MAGIC_SETS; i++)3947byteswap(map->magic[i], map->nmagic[i]);3948- free(dbname);3949- return map;3950-3951-error:3952- if (fd != -1)3953- (void)close(fd);3954- apprentice_unmap(map);3955- free(dbname);3956- return NULL;3957+ return 0;3958}39593960/*3961Index: contrib/file/src/ascmagic.c3962===================================================================3963--- contrib/file/src/ascmagic.c (revision 284174)3964+++ contrib/file/src/ascmagic.c (working copy)3965@@ -35,7 +35,7 @@3966#include "file.h"39673968#ifndef lint3969-FILE_RCSID("@(#)$File: ascmagic.c,v 1.88 2014/02/12 23:20:53 christos Exp $")3970+FILE_RCSID("@(#)$File: ascmagic.c,v 1.91 2014/11/28 02:46:39 christos Exp $")3971#endif /* lint */39723973#include "magic.h"3974@@ -147,7 +147,8 @@ file_ascmagic_with_encoding(struct magic_set *ms,3975== NULL)3976goto done;3977if ((rv = file_softmagic(ms, utf8_buf,3978- (size_t)(utf8_end - utf8_buf), 0, TEXTTEST, text)) == 0)3979+ (size_t)(utf8_end - utf8_buf), 0, NULL,3980+ TEXTTEST, text)) == 0)3981rv = -1;3982}39833984Index: contrib/file/src/cdf.c3985===================================================================3986--- contrib/file/src/cdf.c (revision 284174)3987+++ contrib/file/src/cdf.c (working copy)3988@@ -35,7 +35,7 @@3989#include "file.h"39903991#ifndef lint3992-FILE_RCSID("@(#)$File: cdf.c,v 1.63 2014/06/09 13:04:37 christos Exp $")3993+FILE_RCSID("@(#)$File: cdf.c,v 1.69 2014/12/04 15:56:46 christos Exp $")3994#endif39953996#include <assert.h>3997@@ -73,6 +73,8 @@ static union {3998#define CDF_TOLE8(x) ((uint64_t)(NEED_SWAP ? _cdf_tole8(x) : (uint64_t)(x)))3999#define CDF_TOLE4(x) ((uint32_t)(NEED_SWAP ? _cdf_tole4(x) : (uint32_t)(x)))4000#define CDF_TOLE2(x) ((uint16_t)(NEED_SWAP ? _cdf_tole2(x) : (uint16_t)(x)))4001+#define CDF_TOLE(x) (sizeof(x) == 2 ? CDF_TOLE2(x) : (sizeof(x) == 4 ? \4002+ CDF_TOLE4(x) : CDF_TOLE8(x)))4003#define CDF_GETUINT32(x, y) cdf_getuint32(x, y)400440054006@@ -461,6 +463,12 @@ cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t4007/ sizeof(maxsector));40084009DPRINTF(("Chain:"));4010+ if (sid == CDF_SECID_END_OF_CHAIN) {4011+ /* 0-length chain. */4012+ DPRINTF((" empty\n"));4013+ return 0;4014+ }4015+4016for (j = i = 0; sid >= 0; i++, j++) {4017DPRINTF((" %d", sid));4018if (j >= CDF_LOOP_LIMIT) {4019@@ -817,13 +825,18 @@ cdf_read_property_info(const cdf_stream_t *sst, co4020goto out;4021for (i = 0; i < sh.sh_properties; i++) {4022size_t tail = (i << 1) + 1;4023+ size_t ofs;4024if (cdf_check_stream_offset(sst, h, p, tail * sizeof(uint32_t),4025__LINE__) == -1)4026goto out;4027- size_t ofs = CDF_GETUINT32(p, tail);4028+ ofs = CDF_GETUINT32(p, tail);4029q = (const uint8_t *)(const void *)4030((const char *)(const void *)p + ofs4031- 2 * sizeof(uint32_t));4032+ if (q < p) {4033+ DPRINTF(("Wrapped around %p < %p\n", q, p));4034+ goto out;4035+ }4036if (q > e) {4037DPRINTF(("Ran of the end %p > %p\n", q, e));4038goto out;4039@@ -985,8 +998,56 @@ cdf_unpack_summary_info(const cdf_stream_t *sst, c4040}404140424043+#define extract_catalog_field(f, l) \4044+ memcpy(&ce[i].f, b + (l), sizeof(ce[i].f)); \4045+ ce[i].f = CDF_TOLE(ce[i].f)40464047int4048+cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,4049+ cdf_catalog_t **cat)4050+{4051+ size_t ss = sst->sst_dirlen < h->h_min_size_standard_stream ?4052+ CDF_SHORT_SEC_SIZE(h) : CDF_SEC_SIZE(h);4053+ const char *b = CAST(const char *, sst->sst_tab);4054+ const char *eb = b + ss * sst->sst_len;4055+ size_t nr, i, k;4056+ cdf_catalog_entry_t *ce;4057+ uint16_t reclen;4058+ const uint16_t *np;4059+4060+ for (nr = 0; b < eb; nr++) {4061+ memcpy(&reclen, b, sizeof(reclen));4062+ reclen = CDF_TOLE2(reclen);4063+ if (reclen == 0)4064+ break;4065+ b += reclen;4066+ }4067+ *cat = CAST(cdf_catalog_t *,4068+ malloc(sizeof(cdf_catalog_t) + nr * sizeof(*ce)));4069+ (*cat)->cat_num = nr;4070+ ce = (*cat)->cat_e;4071+ b = CAST(const char *, sst->sst_tab);4072+ for (i = 0; i < nr; i++) {4073+ extract_catalog_field(ce_namlen, 0);4074+ extract_catalog_field(ce_num, 2);4075+ extract_catalog_field(ce_timestamp, 6);4076+ reclen = ce[i].ce_namlen;4077+ ce[i].ce_namlen =4078+ sizeof(ce[i].ce_name) / sizeof(ce[i].ce_name[0]) - 1;4079+ if (ce[i].ce_namlen > reclen - 14)4080+ ce[i].ce_namlen = reclen - 14;4081+ np = CAST(const uint16_t *, (b + 16));4082+ for (k = 0; k < ce[i].ce_namlen; k++) {4083+ ce[i].ce_name[k] = np[k];4084+ CDF_TOLE2(ce[i].ce_name[k]);4085+ }4086+ ce[i].ce_name[ce[i].ce_namlen] = 0;4087+ b += reclen;4088+ }4089+ return 0;4090+}4091+4092+int4093cdf_print_classid(char *buf, size_t buflen, const cdf_classid_t *id)4094{4095return snprintf(buf, buflen, "%.8x-%.4x-%.4x-%.2x%.2x-"4096@@ -1068,6 +1129,15 @@ cdf_print_elapsed_time(char *buf, size_t bufsiz, c4097return len;4098}40994100+char *4101+cdf_u16tos8(char *buf, size_t len, const uint16_t *p)4102+{4103+ size_t i;4104+ for (i = 0; i < len && p[i]; i++)4105+ buf[i] = (char)p[i];4106+ buf[i] = '\0';4107+ return buf;4108+}41094110#ifdef CDF_DEBUG4111void4112@@ -1093,7 +1163,7 @@ cdf_dump_header(const cdf_header_t *h)4113for (i = 0; i < __arraycount(h->h_master_sat); i++) {4114if (h->h_master_sat[i] == CDF_SECID_FREE)4115break;4116- (void)fprintf(stderr, "%35.35s[%.3zu] = %d\n",4117+ (void)fprintf(stderr, "%35.35s[%.3" SIZE_T_FORMAT "u] = %d\n",4118"master_sat", i, h->h_master_sat[i]);4119}4120}4121@@ -1288,7 +1358,7 @@ cdf_dump_summary_info(const cdf_header_t *h, const4122return;4123(void)fprintf(stderr, "Endian: %x\n", ssi.si_byte_order);4124(void)fprintf(stderr, "Os Version %d.%d\n", ssi.si_os_version & 0xff,4125- ssi.si_os_version >> 8);4126+ ssi.si_os_version >> 8);4127(void)fprintf(stderr, "Os %d\n", ssi.si_os);4128cdf_print_classid(buf, sizeof(buf), &ssi.si_class);4129(void)fprintf(stderr, "Class %s\n", buf);4130@@ -1297,6 +1367,27 @@ cdf_dump_summary_info(const cdf_header_t *h, const4131free(info);4132}41334134+4135+void4136+cdf_dump_catalog(const cdf_header_t *h, const cdf_stream_t *sst)4137+{4138+ cdf_catalog_t *cat;4139+ cdf_unpack_catalog(h, sst, &cat);4140+ const cdf_catalog_entry_t *ce = cat->cat_e;4141+ struct timespec ts;4142+ char tbuf[64], sbuf[256];4143+ size_t i;4144+4145+ printf("Catalog:\n");4146+ for (i = 0; i < cat->cat_num; i++) {4147+ cdf_timestamp_to_timespec(&ts, ce[i].ce_timestamp);4148+ printf("\t%d %s %s", ce[i].ce_num,4149+ cdf_u16tos8(sbuf, ce[i].ce_namlen, ce[i].ce_name),4150+ cdf_ctime(&ts.tv_sec, tbuf));4151+ }4152+ free(cat);4153+}4154+4155#endif41564157#ifdef TEST4158@@ -1309,6 +1400,7 @@ main(int argc, char *argv[])4159cdf_stream_t sst, scn;4160cdf_dir_t dir;4161cdf_info_t info;4162+ const cdf_directory_t *root;41634164if (argc < 2) {4165(void)fprintf(stderr, "Usage: %s <filename>\n", getprogname());4166@@ -1342,7 +1434,8 @@ main(int argc, char *argv[])4167if (cdf_read_dir(&info, &h, &sat, &dir) == -1)4168err(1, "Cannot read dir");41694170- if (cdf_read_short_stream(&info, &h, &sat, &dir, &sst) == -1)4171+ if (cdf_read_short_stream(&info, &h, &sat, &dir, &sst, &root)4172+ == -1)4173err(1, "Cannot read short stream");4174#ifdef CDF_DEBUG4175cdf_dump_stream(&h, &sst);4176@@ -1355,10 +1448,18 @@ main(int argc, char *argv[])41774178if (cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,4179&scn) == -1)4180- err(1, "Cannot read summary info");4181+ warn("Cannot read summary info");4182#ifdef CDF_DEBUG4183- cdf_dump_summary_info(&h, &scn);4184+ else4185+ cdf_dump_summary_info(&h, &scn);4186#endif4187+ if (cdf_read_catalog(&info, &h, &sat, &ssat, &sst, &dir,4188+ &scn) == -1)4189+ warn("Cannot read catalog");4190+#ifdef CDF_DEBUG4191+ else4192+ cdf_dump_catalog(&h, &scn);4193+#endif41944195(void)close(info.i_fd);4196}4197Index: contrib/file/src/cdf.h4198===================================================================4199--- contrib/file/src/cdf.h (revision 284174)4200+++ contrib/file/src/cdf.h (working copy)4201@@ -267,6 +267,19 @@ typedef struct {4202size_t i_len;4203} cdf_info_t;42044205+4206+typedef struct {4207+ uint16_t ce_namlen;4208+ uint32_t ce_num;4209+ uint64_t ce_timestamp;4210+ uint16_t ce_name[256];4211+} cdf_catalog_entry_t;4212+4213+typedef struct {4214+ size_t cat_num;4215+ cdf_catalog_entry_t cat_e[0];4216+} cdf_catalog_t;4217+4218struct timespec;4219int cdf_timestamp_to_timespec(struct timespec *, cdf_timestamp_t);4220int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timespec *);4221@@ -301,11 +314,19 @@ int cdf_read_property_info(const cdf_stream_t *, c4222int cdf_read_user_stream(const cdf_info_t *, const cdf_header_t *,4223const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *,4224const cdf_dir_t *, const char *, cdf_stream_t *);4225+#define cdf_read_catalog(info, header, sat, ssat, stream, dir, scn) \4226+ cdf_read_user_stream(info, header, sat, ssat, stream, dir, "Catalog", \4227+ scn)4228+#define cdf_read_encrypted_package(info, header, sat, ssat, stream, dir, scn) \4229+ cdf_read_user_stream(info, header, sat, ssat, stream, dir, \4230+ "EncryptedPackage", scn)4231int cdf_read_summary_info(const cdf_info_t *, const cdf_header_t *,4232const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *,4233const cdf_dir_t *, cdf_stream_t *);4234int cdf_unpack_summary_info(const cdf_stream_t *, const cdf_header_t *,4235cdf_summary_info_header_t *, cdf_property_info_t **, size_t *);4236+int cdf_unpack_catalog(const cdf_header_t *, const cdf_stream_t *,4237+ cdf_catalog_t **);4238int cdf_print_classid(char *, size_t, const cdf_classid_t *);4239int cdf_print_property_name(char *, size_t, uint32_t);4240int cdf_print_elapsed_time(char *, size_t, cdf_timestamp_t);4241@@ -313,6 +334,7 @@ uint16_t cdf_tole2(uint16_t);4242uint32_t cdf_tole4(uint32_t);4243uint64_t cdf_tole8(uint64_t);4244char *cdf_ctime(const time_t *, char *);4245+char *cdf_u16tos8(char *, size_t, const uint16_t *);42464247#ifdef CDF_DEBUG4248void cdf_dump_header(const cdf_header_t *);4249@@ -323,6 +345,7 @@ void cdf_dump_dir(const cdf_info_t *, const cdf_he4250const cdf_sat_t *, const cdf_stream_t *, const cdf_dir_t *);4251void cdf_dump_property_info(const cdf_property_info_t *, size_t);4252void cdf_dump_summary_info(const cdf_header_t *, const cdf_stream_t *);4253+void cdf_dump_catalog(const cdf_header_t *, const cdf_stream_t *);4254#endif425542564257Index: contrib/file/src/compress.c4258===================================================================4259--- contrib/file/src/compress.c (revision 284174)4260+++ contrib/file/src/compress.c (working copy)4261@@ -35,7 +35,7 @@4262#include "file.h"42634264#ifndef lint4265-FILE_RCSID("@(#)$File: compress.c,v 1.73 2014/01/05 15:55:21 christos Exp $")4266+FILE_RCSID("@(#)$File: compress.c,v 1.77 2014/12/12 16:33:01 christos Exp $")4267#endif42684269#include "magic.h"4270@@ -45,7 +45,8 @@4271#endif4272#include <string.h>4273#include <errno.h>4274-#ifndef __MINGW32__4275+#include <signal.h>4276+#if !defined(__MINGW32__) && !defined(WIN32)4277#include <sys/ioctl.h>4278#endif4279#ifdef HAVE_SYS_WAIT_H4280@@ -103,10 +104,12 @@ file_zmagic(struct magic_set *ms, int fd, const ch4281size_t i, nsz;4282int rv = 0;4283int mime = ms->flags & MAGIC_MIME;4284+ sig_t osigpipe;42854286if ((ms->flags & MAGIC_COMPRESS) == 0)4287return 0;42884289+ osigpipe = signal(SIGPIPE, SIG_IGN);4290for (i = 0; i < ncompr; i++) {4291if (nbytes < compr[i].maglen)4292continue;4293@@ -133,6 +136,7 @@ file_zmagic(struct magic_set *ms, int fd, const ch4294}4295}4296error:4297+ (void)signal(SIGPIPE, osigpipe);4298free(newbuf);4299ms->flags |= MAGIC_COMPRESS;4300return rv;4301@@ -377,6 +381,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t4302const unsigned char *old, unsigned char **newch, size_t n)4303{4304int fdin[2], fdout[2];4305+ int status;4306ssize_t r;4307pid_t pid;43084309@@ -459,7 +464,17 @@ uncompressbuf(struct magic_set *ms, int fd, size_t4310/*NOTREACHED*/43114312default: /* parent */4313- break;4314+ if (wait(&status) == -1) {4315+#ifdef DEBUG4316+ (void)fprintf(stderr,4317+ "Wait failed (%s)\n",4318+ strerror(errno));4319+#endif4320+ exit(1);4321+ }4322+ exit(WIFEXITED(status) ?4323+ WEXITSTATUS(status) : 1);4324+ /*NOTREACHED*/4325}4326(void) close(fdin[1]);4327fdin[1] = -1;4328@@ -470,7 +485,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t4329(void)fprintf(stderr, "Malloc failed (%s)\n",4330strerror(errno));4331#endif4332- n = 0;4333+ n = NODATA;4334goto err;4335}4336if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {4337@@ -479,7 +494,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t4338strerror(errno));4339#endif4340free(*newch);4341- n = 0;4342+ n = NODATA;4343*newch = NULL;4344goto err;4345} else {4346@@ -491,12 +506,24 @@ err:4347if (fdin[1] != -1)4348(void) close(fdin[1]);4349(void) close(fdout[0]);4350-#ifdef WNOHANG4351- while (waitpid(pid, NULL, WNOHANG) != -1)4352- continue;4353-#else4354- (void)wait(NULL);4355+ if (wait(&status) == -1) {4356+#ifdef DEBUG4357+ (void)fprintf(stderr, "Wait failed (%s)\n",4358+ strerror(errno));4359#endif4360+ n = NODATA;4361+ } else if (!WIFEXITED(status)) {4362+#ifdef DEBUG4363+ (void)fprintf(stderr, "Child not exited (0x%x)\n",4364+ status);4365+#endif4366+ } else if (WEXITSTATUS(status) != 0) {4367+#ifdef DEBUG4368+ (void)fprintf(stderr, "Child exited (0x%d)\n",4369+ WEXITSTATUS(status));4370+#endif4371+ }4372+4373(void) close(fdin[0]);43744375return n;4376Index: contrib/file/src/elfclass.h4377===================================================================4378--- contrib/file/src/elfclass.h (revision 284174)4379+++ contrib/file/src/elfclass.h (working copy)4380@@ -32,17 +32,18 @@4381swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];43824383type = elf_getu16(swap, elfhdr.e_type);4384+ notecount = ms->elf_notes_max;4385switch (type) {4386#ifdef ELFCORE4387case ET_CORE:4388phnum = elf_getu16(swap, elfhdr.e_phnum);4389- if (phnum > MAX_PHNUM)4390- return toomany(ms, "program", phnum);4391+ if (phnum > ms->elf_phnum_max)4392+ return toomany(ms, "program headers", phnum);4393flags |= FLAGS_IS_CORE;4394if (dophn_core(ms, clazz, swap, fd,4395(off_t)elf_getu(swap, elfhdr.e_phoff), phnum,4396(size_t)elf_getu16(swap, elfhdr.e_phentsize),4397- fsize, &flags) == -1)4398+ fsize, &flags, ¬ecount) == -1)4399return -1;4400break;4401#endif4402@@ -49,26 +50,27 @@4403case ET_EXEC:4404case ET_DYN:4405phnum = elf_getu16(swap, elfhdr.e_phnum);4406- if (phnum > MAX_PHNUM)4407+ if (phnum > ms->elf_phnum_max)4408return toomany(ms, "program", phnum);4409shnum = elf_getu16(swap, elfhdr.e_shnum);4410- if (shnum > MAX_SHNUM)4411+ if (shnum > ms->elf_shnum_max)4412return toomany(ms, "section", shnum);4413if (dophn_exec(ms, clazz, swap, fd,4414(off_t)elf_getu(swap, elfhdr.e_phoff), phnum,4415(size_t)elf_getu16(swap, elfhdr.e_phentsize),4416- fsize, &flags, shnum) == -1)4417+ fsize, shnum, &flags, ¬ecount) == -1)4418return -1;4419/*FALLTHROUGH*/4420case ET_REL:4421shnum = elf_getu16(swap, elfhdr.e_shnum);4422- if (shnum > MAX_SHNUM)4423- return toomany(ms, "section", shnum);4424+ if (shnum > ms->elf_shnum_max)4425+ return toomany(ms, "section headers", shnum);4426if (doshn(ms, clazz, swap, fd,4427(off_t)elf_getu(swap, elfhdr.e_shoff), shnum,4428(size_t)elf_getu16(swap, elfhdr.e_shentsize),4429- fsize, &flags, elf_getu16(swap, elfhdr.e_machine),4430- (int)elf_getu16(swap, elfhdr.e_shstrndx)) == -1)4431+ fsize, elf_getu16(swap, elfhdr.e_machine),4432+ (int)elf_getu16(swap, elfhdr.e_shstrndx),4433+ &flags, ¬ecount) == -1)4434return -1;4435break;44364437@@ -75,4 +77,6 @@4438default:4439break;4440}4441+ if (notecount == 0)4442+ return toomany(ms, "notes", ms->elf_notes_max);4443return 1;4444Index: contrib/file/src/encoding.c4445===================================================================4446--- contrib/file/src/encoding.c (revision 284174)4447+++ contrib/file/src/encoding.c (working copy)4448@@ -35,7 +35,7 @@4449#include "file.h"44504451#ifndef lint4452-FILE_RCSID("@(#)$File: encoding.c,v 1.9 2013/11/19 20:45:50 christos Exp $")4453+FILE_RCSID("@(#)$File: encoding.c,v 1.10 2014/09/11 12:08:52 christos Exp $")4454#endif /* lint */44554456#include "magic.h"4457@@ -97,7 +97,6 @@ file_encoding(struct magic_set *ms, const unsigned4458*code_mime = "utf-8";4459} else if (file_looks_utf8(buf, nbytes, *ubuf, ulen) > 1) {4460DPRINTF(("utf8 %" SIZE_T_FORMAT "u\n", *ulen));4461- *code = "UTF-8 Unicode (with BOM)";4462*code = "UTF-8 Unicode";4463*code_mime = "utf-8";4464} else if ((ucs_type = looks_ucs16(buf, nbytes, *ubuf, ulen)) != 0) {4465Index: contrib/file/src/file.c4466===================================================================4467--- contrib/file/src/file.c (revision 284174)4468+++ contrib/file/src/file.c (working copy)4469@@ -32,7 +32,7 @@4470#include "file.h"44714472#ifndef lint4473-FILE_RCSID("@(#)$File: file.c,v 1.153 2014/02/11 15:41:04 christos Exp $")4474+FILE_RCSID("@(#)$File: file.c,v 1.160 2014/12/16 23:18:40 christos Exp $")4475#endif /* lint */44764477#include "magic.h"4478@@ -54,9 +54,6 @@4479#ifdef HAVE_UNISTD_H4480#include <unistd.h> /* for read() */4481#endif4482-#ifdef HAVE_LOCALE_H4483-#include <locale.h>4484-#endif4485#ifdef HAVE_WCHAR_H4486#include <wchar.h>4487#endif4488@@ -101,7 +98,7 @@ private const struct option long_options[] = {4489#undef OPT_LONGONLY4490{0, 0, NULL, 0}4491};4492-#define OPTSTRING "bcCde:Ef:F:hiklLm:nNprsvz0"4493+#define OPTSTRING "bcCde:Ef:F:hiklLm:nNpP:rsvz0"44944495private const struct {4496const char *name;4497@@ -119,6 +116,18 @@ private const struct {4498{ "tokens", MAGIC_NO_CHECK_TOKENS }, /* OBSOLETE: ignored for backwards compatibility */4499};45004501+private struct {4502+ const char *name;4503+ int tag;4504+ size_t value;4505+} pm[] = {4506+ { "indir", MAGIC_PARAM_INDIR_MAX, 0 },4507+ { "name", MAGIC_PARAM_NAME_MAX, 0 },4508+ { "elf_phnum", MAGIC_PARAM_ELF_PHNUM_MAX, 0 },4509+ { "elf_shnum", MAGIC_PARAM_ELF_SHNUM_MAX, 0 },4510+ { "elf_notes", MAGIC_PARAM_ELF_NOTES_MAX, 0 },4511+};4512+4513private char *progname; /* used throughout */45144515private void usage(void);4516@@ -128,6 +137,8 @@ private void help(void);4517private int unwrap(struct magic_set *, const char *);4518private int process(struct magic_set *ms, const char *, int);4519private struct magic_set *load(const char *, int);4520+private void setparam(const char *);4521+private void applyparam(magic_t);452245234524/*4525@@ -145,7 +156,9 @@ main(int argc, char *argv[])4526const char *magicfile = NULL; /* where the magic is */45274528/* makes islower etc work for other langs */4529+#ifdef HAVE_SETLOCALE4530(void)setlocale(LC_CTYPE, "");4531+#endif45324533#ifdef __EMX__4534/* sh-like wildcard expansion! Shouldn't hurt at least ... */4535@@ -243,9 +256,13 @@ main(int argc, char *argv[])4536flags |= MAGIC_PRESERVE_ATIME;4537break;4538#endif4539+ case 'P':4540+ setparam(optarg);4541+ break;4542case 'r':4543flags |= MAGIC_RAW;4544break;4545+ break;4546case 's':4547flags |= MAGIC_DEVICES;4548break;4549@@ -298,6 +315,8 @@ main(int argc, char *argv[])4550strerror(errno));4551return 1;4552}4553+4554+4555switch(action) {4556case FILE_CHECK:4557c = magic_check(magic, magicfile);4558@@ -321,7 +340,7 @@ main(int argc, char *argv[])4559if (magic == NULL)4560if ((magic = load(magicfile, flags)) == NULL)4561return 1;4562- break;4563+ applyparam(magic);4564}45654566if (optind == argc) {4567@@ -351,7 +370,42 @@ main(int argc, char *argv[])4568return e;4569}45704571+private void4572+applyparam(magic_t magic)4573+{4574+ size_t i;45754576+ for (i = 0; i < __arraycount(pm); i++) {4577+ if (pm[i].value == 0)4578+ continue;4579+ if (magic_setparam(magic, pm[i].tag, &pm[i].value) == -1) {4580+ (void)fprintf(stderr, "%s: Can't set %s %s\n", progname,4581+ pm[i].name, strerror(errno));4582+ exit(1);4583+ }4584+ }4585+}4586+4587+private void4588+setparam(const char *p)4589+{4590+ size_t i;4591+ char *s;4592+4593+ if ((s = strchr(p, '=')) == NULL)4594+ goto badparm;4595+4596+ for (i = 0; i < __arraycount(pm); i++) {4597+ if (strncmp(p, pm[i].name, s - p) != 0)4598+ continue;4599+ pm[i].value = atoi(s + 1);4600+ return;4601+ }4602+badparm:4603+ (void)fprintf(stderr, "%s: Unknown param %s\n", progname, p);4604+ exit(1);4605+}4606+4607private struct magic_set *4608/*ARGSUSED*/4609load(const char *magicfile, int flags)4610Index: contrib/file/src/file.h4611===================================================================4612--- contrib/file/src/file.h (revision 284174)4613+++ contrib/file/src/file.h (working copy)4614@@ -27,7 +27,7 @@4615*/4616/*4617* file.h - definitions for file(1) program4618- * @(#)$File: file.h,v 1.152 2014/06/03 19:01:34 christos Exp $4619+ * @(#)$File: file.h,v 1.164 2015/01/01 17:07:34 christos Exp $4620*/46214622#ifndef __file_h__4623@@ -64,7 +64,9 @@4624#include <regex.h>4625#include <time.h>4626#include <sys/types.h>4627+#ifndef WIN324628#include <sys/param.h>4629+#endif4630/* Do this here and now, because struct stat gets re-defined on solaris */4631#include <sys/stat.h>4632#include <stdarg.h>4633@@ -232,6 +234,7 @@ struct magic {4634(t) == FILE_LESTRING16 || \4635(t) == FILE_REGEX || \4636(t) == FILE_SEARCH || \4637+ (t) == FILE_INDIRECT || \4638(t) == FILE_NAME || \4639(t) == FILE_USE)46404641@@ -344,6 +347,8 @@ struct magic {4642#define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)4643#define STRING_DEFAULT_RANGE 10046444645+#define INDIRECT_RELATIVE BIT(0)4646+#define CHAR_INDIRECT_RELATIVE 'r'46474648/* list of magic entries */4649struct mlist {4650@@ -401,6 +406,16 @@ struct magic_set {4651/* FIXME: Make the string dynamically allocated so that e.g.4652strings matched in files can be longer than MAXstring */4653union VALUETYPE ms_value; /* either number or string */4654+ uint16_t indir_max;4655+ uint16_t name_max;4656+ uint16_t elf_shnum_max;4657+ uint16_t elf_phnum_max;4658+ uint16_t elf_notes_max;4659+#define FILE_INDIR_MAX 154660+#define FILE_NAME_MAX 304661+#define FILE_ELF_SHNUM_MAX 327684662+#define FILE_ELF_PHNUM_MAX 1284663+#define FILE_ELF_NOTES_MAX 2564664};46654666/* Type for Unicode characters */4667@@ -440,8 +455,10 @@ protected int file_encoding(struct magic_set *, co4668unichar **, size_t *, const char **, const char **, const char **);4669protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);4670protected int file_softmagic(struct magic_set *, const unsigned char *, size_t,4671- size_t, int, int);4672+ uint16_t, uint16_t *, int, int);4673protected int file_apprentice(struct magic_set *, const char *, int);4674+protected int buffer_apprentice(struct magic_set *, struct magic **,4675+ size_t *, size_t);4676protected int file_magicfind(struct magic_set *, const char *, struct mlist *);4677protected uint64_t file_signextend(struct magic_set *, struct magic *,4678uint64_t);4679@@ -464,14 +481,26 @@ protected int file_looks_utf8(const unsigned char4680size_t *);4681protected size_t file_pstring_length_size(const struct magic *);4682protected size_t file_pstring_get_length(const struct magic *, const char *);4683+protected char * file_printable(char *, size_t, const char *);4684#ifdef __EMX__4685protected int file_os2_apptype(struct magic_set *, const char *, const void *,4686size_t);4687#endif /* __EMX__ */46884689+#if defined(HAVE_LOCALE_H)4690+#include <locale.h>4691+#endif4692+#if defined(HAVE_XLOCALE_H)4693+#include <xlocale.h>4694+#endif4695+4696typedef struct {4697const char *pat;4698- char *old_lc_ctype;4699+#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)4700+#define USE_C_LOCALE4701+ locale_t old_lc_ctype;4702+ locale_t c_lc_ctype;4703+#endif4704int rc;4705regex_t rx;4706} file_regex_t;4707Index: contrib/file/src/file_opts.h4708===================================================================4709--- contrib/file/src/file_opts.h (revision 284174)4710+++ contrib/file/src/file_opts.h (working copy)4711@@ -43,6 +43,12 @@ OPT('0', "print0", 0, " terminate fi4712#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)4713OPT('p', "preserve-date", 0, " preserve access times on files\n")4714#endif4715+OPT('P', "parameter", 0, " set file engine parameter limits\n"4716+ " indir 15 recursion limit for indirection\n"4717+ " name 30 use limit for name/use magic\n"4718+ " elf_notes 256 max ELF notes processed\n"4719+ " elf_phnum 128 max ELF prog sections processed\n"4720+ " elf_shnum 32768 max ELF sections processed\n")4721OPT('r', "raw", 0, " don't translate unprintable chars to \\ooo\n")4722OPT('s', "special-files", 0, " treat special (block/char devices) files as\n"4723" ordinary ones\n")4724Index: contrib/file/src/fsmagic.c4725===================================================================4726--- contrib/file/src/fsmagic.c (revision 284174)4727+++ contrib/file/src/fsmagic.c (working copy)4728@@ -32,7 +32,7 @@4729#include "file.h"47304731#ifndef lint4732-FILE_RCSID("@(#)$File: fsmagic.c,v 1.73 2014/05/14 23:15:42 christos Exp $")4733+FILE_RCSID("@(#)$File: fsmagic.c,v 1.75 2014/12/04 15:56:46 christos Exp $")4734#endif /* lint */47354736#include "magic.h"4737@@ -75,10 +75,10 @@ bad_link(struct magic_set *ms, int err, char *buf)4738else if (!mime) {4739if (ms->flags & MAGIC_ERROR) {4740file_error(ms, err,4741- "broken symbolic link to `%s'", buf);4742+ "broken symbolic link to %s", buf);4743return -1;4744}4745- if (file_printf(ms, "broken symbolic link to `%s'", buf) == -1)4746+ if (file_printf(ms, "broken symbolic link to %s", buf) == -1)4747return -1;4748}4749return 1;4750@@ -129,7 +129,7 @@ file_fsmagic(struct magic_set *ms, const char *fn,47514752#ifdef WIN324753{4754- HANDLE hFile = CreateFile(fn, 0, FILE_SHARE_DELETE |4755+ HANDLE hFile = CreateFile((LPCSTR)fn, 0, FILE_SHARE_DELETE |4756FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0,4757NULL);4758if (hFile != INVALID_HANDLE_VALUE) {4759@@ -352,7 +352,7 @@ file_fsmagic(struct magic_set *ms, const char *fn,4760if (mime) {4761if (handle_mime(ms, mime, "symlink") == -1)4762return -1;4763- } else if (file_printf(ms, "%ssymbolic link to `%s'",4764+ } else if (file_printf(ms, "%ssymbolic link to %s",4765COMMA, buf) == -1)4766return -1;4767}4768Index: contrib/file/src/funcs.c4769===================================================================4770--- contrib/file/src/funcs.c (revision 284174)4771+++ contrib/file/src/funcs.c (working copy)4772@@ -27,7 +27,7 @@4773#include "file.h"47744775#ifndef lint4776-FILE_RCSID("@(#)$File: funcs.c,v 1.72 2014/05/14 23:15:42 christos Exp $")4777+FILE_RCSID("@(#)$File: funcs.c,v 1.79 2014/12/16 20:52:49 christos Exp $")4778#endif /* lint */47794780#include "magic.h"4781@@ -45,9 +45,6 @@4782#if defined(HAVE_LIMITS_H)4783#include <limits.h>4784#endif4785-#if defined(HAVE_LOCALE_H)4786-#include <locale.h>4787-#endif47884789#ifndef SIZE_MAX4790#define SIZE_MAX ((size_t)~0)4791@@ -230,7 +227,7 @@ file_buffer(struct magic_set *ms, int fd, const ch47924793/* try soft magic tests */4794if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)4795- if ((m = file_softmagic(ms, ubuf, nb, 0, BINTEST,4796+ if ((m = file_softmagic(ms, ubuf, nb, 0, NULL, BINTEST,4797looks_text)) != 0) {4798if ((ms->flags & MAGIC_DEBUG) != 0)4799(void)fprintf(stderr, "softmagic %d\n", m);4800@@ -455,13 +452,14 @@ out:4801protected int4802file_regcomp(file_regex_t *rx, const char *pat, int flags)4803{4804- rx->old_lc_ctype = setlocale(LC_CTYPE, NULL);4805+#ifdef USE_C_LOCALE4806+ rx->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);4807+ assert(rx->c_lc_ctype != NULL);4808+ rx->old_lc_ctype = uselocale(rx->c_lc_ctype);4809assert(rx->old_lc_ctype != NULL);4810- rx->old_lc_ctype = strdup(rx->old_lc_ctype);4811- assert(rx->old_lc_ctype != NULL);4812+#endif4813rx->pat = pat;48144815- (void)setlocale(LC_CTYPE, "C");4816return rx->rc = regcomp(&rx->rx, pat, flags);4817}48184819@@ -478,8 +476,10 @@ file_regfree(file_regex_t *rx)4820{4821if (rx->rc == 0)4822regfree(&rx->rx);4823- (void)setlocale(LC_CTYPE, rx->old_lc_ctype);4824- free(rx->old_lc_ctype);4825+#ifdef USE_C_LOCALE4826+ (void)uselocale(rx->old_lc_ctype);4827+ freelocale(rx->c_lc_ctype);4828+#endif4829}48304831protected void4832@@ -531,3 +531,28 @@ file_pop_buffer(struct magic_set *ms, file_pushbuf4833free(pb);4834return rbuf;4835}4836+4837+/*4838+ * convert string to ascii printable format.4839+ */4840+protected char *4841+file_printable(char *buf, size_t bufsiz, const char *str)4842+{4843+ char *ptr, *eptr;4844+ const unsigned char *s = (const unsigned char *)str;4845+4846+ for (ptr = buf, eptr = ptr + bufsiz - 1; ptr < eptr && *s; s++) {4847+ if (isprint(*s)) {4848+ *ptr++ = *s;4849+ continue;4850+ }4851+ if (ptr >= eptr - 3)4852+ break;4853+ *ptr++ = '\\';4854+ *ptr++ = ((*s >> 6) & 7) + '0';4855+ *ptr++ = ((*s >> 3) & 7) + '0';4856+ *ptr++ = ((*s >> 0) & 7) + '0';4857+ }4858+ *ptr = '\0';4859+ return buf;4860+}4861Index: contrib/file/src/getline.c4862===================================================================4863--- contrib/file/src/getline.c (revision 284174)4864+++ contrib/file/src/getline.c (working copy)4865@@ -1,4 +1,4 @@4866-/* $NetBSD: fgetln.c,v 1.9 2008/04/29 06:53:03 martin Exp $ */4867+/* $NetBSD: getline.c,v 1.2 2014/09/16 17:23:50 christos Exp $ */48684869/*-4870* Copyright (c) 2011 The NetBSD Foundation, Inc.4871@@ -52,10 +52,14 @@ getdelim(char **buf, size_t *bufsiz, int delimiter4872for (ptr = *buf, eptr = *buf + *bufsiz;;) {4873int c = fgetc(fp);4874if (c == -1) {4875- if (feof(fp))4876- return ptr == *buf ? -1 : ptr - *buf;4877- else4878- return -1;4879+ if (feof(fp)) {4880+ ssize_t diff = (ssize_t)(ptr - *buf);4881+ if (diff != 0) {4882+ *ptr = '\0';4883+ return diff;4884+ }4885+ }4886+ return -1;4887}4888*ptr++ = c;4889if (c == delimiter) {4890@@ -76,7 +80,7 @@ getdelim(char **buf, size_t *bufsiz, int delimiter4891}4892}48934894-ssize_t4895+public ssize_t4896getline(char **buf, size_t *bufsiz, FILE *fp)4897{4898return getdelim(buf, bufsiz, '\n', fp);4899@@ -93,7 +97,7 @@ main(int argc, char *argv[])4900size_t n = 0;49014902while ((len = getline(&p, &n, stdin)) != -1)4903- (void)printf("%zd %s", len, p);4904+ (void)printf("%" SIZE_T_FORMAT "d %s", len, p);4905free(p);4906return 0;4907}4908Index: contrib/file/src/magic.c4909===================================================================4910--- contrib/file/src/magic.c (revision 284174)4911+++ contrib/file/src/magic.c (working copy)4912@@ -33,7 +33,7 @@4913#include "file.h"49144915#ifndef lint4916-FILE_RCSID("@(#)$File: magic.c,v 1.84 2014/05/14 23:15:42 christos Exp $")4917+FILE_RCSID("@(#)$File: magic.c,v 1.91 2014/12/16 23:18:40 christos Exp $")4918#endif /* lint */49194920#include "magic.h"4921@@ -128,6 +128,7 @@ out:4922#else4923char *hmagicp;4924char *tmppath = NULL;4925+ LPTSTR dllpath;4926hmagicpath = NULL;49274928#define APPENDPATH() \4929@@ -173,7 +174,7 @@ out:4930}49314932/* Third, try to get magic file relative to dll location */4933- LPTSTR dllpath = malloc(sizeof(*dllpath) * (MAX_PATH + 1));4934+ dllpath = malloc(sizeof(*dllpath) * (MAX_PATH + 1));4935dllpath[MAX_PATH] = 0; /* just in case long path gets truncated and not null terminated */4936if (GetModuleFileNameA(NULL, dllpath, MAX_PATH)){4937PathRemoveFileSpecA(dllpath);4938@@ -257,7 +258,21 @@ magic_load(struct magic_set *ms, const char *magic4939return file_apprentice(ms, magicfile, FILE_LOAD);4940}49414942+#ifndef COMPILE_ONLY4943+/*4944+ * Install a set of compiled magic buffers.4945+ */4946public int4947+magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes,4948+ size_t nbufs)4949+{4950+ if (ms == NULL)4951+ return -1;4952+ return buffer_apprentice(ms, (struct magic **)bufs, sizes, nbufs);4953+}4954+#endif4955+4956+public int4957magic_compile(struct magic_set *ms, const char *magicfile)4958{4959if (ms == NULL)4960@@ -522,3 +537,53 @@ magic_version(void)4961{4962return MAGIC_VERSION;4963}4964+4965+public int4966+magic_setparam(struct magic_set *ms, int param, const void *val)4967+{4968+ switch (param) {4969+ case MAGIC_PARAM_INDIR_MAX:4970+ ms->indir_max = *(const size_t *)val;4971+ return 0;4972+ case MAGIC_PARAM_NAME_MAX:4973+ ms->name_max = *(const size_t *)val;4974+ return 0;4975+ case MAGIC_PARAM_ELF_PHNUM_MAX:4976+ ms->elf_phnum_max = *(const size_t *)val;4977+ return 0;4978+ case MAGIC_PARAM_ELF_SHNUM_MAX:4979+ ms->elf_shnum_max = *(const size_t *)val;4980+ return 0;4981+ case MAGIC_PARAM_ELF_NOTES_MAX:4982+ ms->elf_notes_max = *(const size_t *)val;4983+ return 0;4984+ default:4985+ errno = EINVAL;4986+ return -1;4987+ }4988+}4989+4990+public int4991+magic_getparam(struct magic_set *ms, int param, void *val)4992+{4993+ switch (param) {4994+ case MAGIC_PARAM_INDIR_MAX:4995+ *(size_t *)val = ms->indir_max;4996+ return 0;4997+ case MAGIC_PARAM_NAME_MAX:4998+ *(size_t *)val = ms->name_max;4999+ return 0;5000+ case MAGIC_PARAM_ELF_PHNUM_MAX:5001+ *(size_t *)val = ms->elf_phnum_max;5002+ return 0;5003+ case MAGIC_PARAM_ELF_SHNUM_MAX:5004+ *(size_t *)val = ms->elf_shnum_max;5005+ return 0;5006+ case MAGIC_PARAM_ELF_NOTES_MAX:5007+ *(size_t *)val = ms->elf_notes_max;5008+ return 0;5009+ default:5010+ errno = EINVAL;5011+ return -1;5012+ }5013+}5014Index: contrib/file/src/magic.h5015===================================================================5016--- contrib/file/src/magic.h (revision 284174)5017+++ contrib/file/src/magic.h (working copy)5018@@ -75,7 +75,7 @@5019#define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */5020#define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */50215022-#define MAGIC_VERSION 518 /* This implementation */5023+#define MAGIC_VERSION 521 /* This implementation */502450255026#ifdef __cplusplus5027@@ -96,11 +96,22 @@ int magic_setflags(magic_t, int);50285029int magic_version(void);5030int magic_load(magic_t, const char *);5031+int magic_load_buffers(magic_t, void **, size_t *, size_t);5032+5033int magic_compile(magic_t, const char *);5034int magic_check(magic_t, const char *);5035int magic_list(magic_t, const char *);5036int magic_errno(magic_t);50375038+#define MAGIC_PARAM_INDIR_MAX 05039+#define MAGIC_PARAM_NAME_MAX 15040+#define MAGIC_PARAM_ELF_PHNUM_MAX 25041+#define MAGIC_PARAM_ELF_SHNUM_MAX 35042+#define MAGIC_PARAM_ELF_NOTES_MAX 45043+5044+int magic_setparam(magic_t, int, const void *);5045+int magic_getparam(magic_t, int, void *);5046+5047#ifdef __cplusplus5048};5049#endif5050Index: contrib/file/src/magic.h.in5051===================================================================5052--- contrib/file/src/magic.h.in (revision 284174)5053+++ contrib/file/src/magic.h.in (working copy)5054@@ -96,11 +96,22 @@ int magic_setflags(magic_t, int);50555056int magic_version(void);5057int magic_load(magic_t, const char *);5058+int magic_load_buffers(magic_t, void **, size_t *, size_t);5059+5060int magic_compile(magic_t, const char *);5061int magic_check(magic_t, const char *);5062int magic_list(magic_t, const char *);5063int magic_errno(magic_t);50645065+#define MAGIC_PARAM_INDIR_MAX 05066+#define MAGIC_PARAM_NAME_MAX 15067+#define MAGIC_PARAM_ELF_PHNUM_MAX 25068+#define MAGIC_PARAM_ELF_SHNUM_MAX 35069+#define MAGIC_PARAM_ELF_NOTES_MAX 45070+5071+int magic_setparam(magic_t, int, const void *);5072+int magic_getparam(magic_t, int, void *);5073+5074#ifdef __cplusplus5075};5076#endif5077Index: contrib/file/src/pread.c5078===================================================================5079--- contrib/file/src/pread.c (revision 284174)5080+++ contrib/file/src/pread.c (working copy)5081@@ -1,6 +1,6 @@5082#include "file.h"5083#ifndef lint5084-FILE_RCSID("@(#)$File: pread.c,v 1.2 2013/04/02 16:23:07 christos Exp $")5085+FILE_RCSID("@(#)$File: pread.c,v 1.3 2014/09/15 19:11:25 christos Exp $")5086#endif /* lint */5087#include <fcntl.h>5088#include <unistd.h>5089@@ -7,8 +7,17 @@50905091ssize_t5092pread(int fd, void *buf, size_t len, off_t off) {5093- if (lseek(fd, off, SEEK_SET) == (off_t)-1)5094+ off_t old;5095+ ssize_t rv;5096+5097+ if ((old = lseek(fd, off, SEEK_SET)) == -1)5098return -1;50995100- return read(fd, buf, len);5101+ if ((rv = read(fd, buf, len)) == -1)5102+ return -1;5103+5104+ if (lseek(fd, old, SEEK_SET) == -1)5105+ return -1;5106+5107+ return rv;5108}5109Index: contrib/file/src/readcdf.c5110===================================================================5111--- contrib/file/src/readcdf.c (revision 284174)5112+++ contrib/file/src/readcdf.c (working copy)5113@@ -26,7 +26,7 @@5114#include "file.h"51155116#ifndef lint5117-FILE_RCSID("@(#)$File: readcdf.c,v 1.44 2014/05/14 23:22:48 christos Exp $")5118+FILE_RCSID("@(#)$File: readcdf.c,v 1.49 2014/12/04 15:56:46 christos Exp $")5119#endif51205121#include <assert.h>5122@@ -35,9 +35,6 @@5123#include <string.h>5124#include <time.h>5125#include <ctype.h>5126-#if defined(HAVE_LOCALE_H)5127-#include <locale.h>5128-#endif51295130#include "cdf.h"5131#include "magic.h"5132@@ -75,7 +72,7 @@ static const struct cv {5133const char *mime;5134} clsid2mime[] = {5135{5136- { 0x00000000000c1084LLU, 0x46000000000000c0LLU },5137+ { 0x00000000000c1084ULL, 0x46000000000000c0ULL },5138"x-msi",5139},5140{ { 0, 0 },5141@@ -83,7 +80,7 @@ static const struct cv {5142},5143}, clsid2desc[] = {5144{5145- { 0x00000000000c1084LLU, 0x46000000000000c0LLU },5146+ { 0x00000000000c1084ULL, 0x46000000000000c0ULL },5147"MSI Installer",5148},5149{ { 0, 0 },5150@@ -107,20 +104,23 @@ cdf_app_to_mime(const char *vbuf, const struct nv5151{5152size_t i;5153const char *rv = NULL;5154- char *old_lc_ctype;5155+#ifdef USE_C_LOCALE5156+ locale_t old_lc_ctype, c_lc_ctype;51575158- old_lc_ctype = setlocale(LC_CTYPE, NULL);5159+ c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);5160+ assert(c_lc_ctype != NULL);5161+ old_lc_ctype = uselocale(c_lc_ctype);5162assert(old_lc_ctype != NULL);5163- old_lc_ctype = strdup(old_lc_ctype);5164- assert(old_lc_ctype != NULL);5165- (void)setlocale(LC_CTYPE, "C");5166+#endif5167for (i = 0; nv[i].pattern != NULL; i++)5168if (strcasestr(vbuf, nv[i].pattern) != NULL) {5169rv = nv[i].mime;5170break;5171}5172- (void)setlocale(LC_CTYPE, old_lc_ctype);5173- free(old_lc_ctype);5174+#ifdef USE_C_LOCALE5175+ (void)uselocale(old_lc_ctype);5176+ freelocale(c_lc_ctype);5177+#endif5178return rv;5179}51805181@@ -241,6 +241,37 @@ cdf_file_property_info(struct magic_set *ms, const5182}51835184private int5185+cdf_file_catalog(struct magic_set *ms, const cdf_header_t *h,5186+ const cdf_stream_t *sst)5187+{5188+ cdf_catalog_t *cat;5189+ size_t i;5190+ char buf[256];5191+ cdf_catalog_entry_t *ce;5192+5193+ if (NOTMIME(ms)) {5194+ if (file_printf(ms, "Microsoft Thumbs.db [") == -1)5195+ return -1;5196+ if (cdf_unpack_catalog(h, sst, &cat) == -1)5197+ return -1;5198+ ce = cat->cat_e;5199+ /* skip first entry since it has a , or paren */5200+ for (i = 1; i < cat->cat_num; i++)5201+ if (file_printf(ms, "%s%s",5202+ cdf_u16tos8(buf, ce[i].ce_namlen, ce[i].ce_name),5203+ i == cat->cat_num - 1 ? "]" : ", ") == -1) {5204+ free(cat);5205+ return -1;5206+ }5207+ free(cat);5208+ } else {5209+ if (file_printf(ms, "application/CDFV2") == -1)5210+ return -1;5211+ }5212+ return 1;5213+}5214+5215+private int5216cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,5217const cdf_stream_t *sst, const cdf_directory_t *root_storage)5218{5219@@ -285,11 +316,12 @@ cdf_file_summary_info(struct magic_set *ms, const5220if (root_storage) {5221str = cdf_clsid_to_mime(root_storage->d_storage_uuid,5222clsid2desc);5223- if (str)5224+ if (str) {5225if (file_printf(ms, ", %s", str) == -1)5226return -2;5227}5228}5229+ }52305231m = cdf_file_property_info(ms, info, count, root_storage);5232free(info);5233@@ -302,11 +334,11 @@ private char *5234format_clsid(char *buf, size_t len, const uint64_t uuid[2]) {5235snprintf(buf, len, "%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4"5236PRIx64 "-%.12" PRIx64,5237- (uuid[0] >> 32) & (uint64_t)0x000000000ffffffffLLU,5238- (uuid[0] >> 16) & (uint64_t)0x0000000000000ffffLLU,5239- (uuid[0] >> 0) & (uint64_t)0x0000000000000ffffLLU,5240- (uuid[1] >> 48) & (uint64_t)0x0000000000000ffffLLU,5241- (uuid[1] >> 0) & (uint64_t)0x0000fffffffffffffLLU);5242+ (uuid[0] >> 32) & (uint64_t)0x000000000ffffffffULL,5243+ (uuid[0] >> 16) & (uint64_t)0x0000000000000ffffULL,5244+ (uuid[0] >> 0) & (uint64_t)0x0000000000000ffffULL,5245+ (uuid[1] >> 48) & (uint64_t)0x0000000000000ffffULL,5246+ (uuid[1] >> 0) & (uint64_t)0x0000fffffffffffffULL);5247return buf;5248}5249#endif5250@@ -323,6 +355,7 @@ file_trycdf(struct magic_set *ms, int fd, const un5251int i;5252const char *expn = "";5253const char *corrupt = "corrupt: ";5254+ const cdf_directory_t *root_storage;52555256info.i_fd = fd;5257info.i_buf = buf;5258@@ -356,7 +389,6 @@ file_trycdf(struct magic_set *ms, int fd, const un5259goto out2;5260}52615262- const cdf_directory_t *root_storage;5263if ((i = cdf_read_short_stream(&info, &h, &sat, &dir, &sst,5264&root_storage)) == -1) {5265expn = "Cannot read short stream";5266@@ -404,8 +436,24 @@ file_trycdf(struct magic_set *ms, int fd, const un5267if ((i = cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,5268&scn)) == -1) {5269if (errno == ESRCH) {5270- corrupt = expn;5271- expn = "No summary info";5272+ if ((i = cdf_read_catalog(&info, &h, &sat, &ssat, &sst,5273+ &dir, &scn)) == -1) {5274+ corrupt = expn;5275+ if ((i = cdf_read_encrypted_package(&info, &h,5276+ &sat, &ssat, &sst, &dir, &scn)) == -1)5277+ expn = "No summary info";5278+ else {5279+ expn = "Encrypted";5280+ i = -1;5281+ }5282+ goto out4;5283+ }5284+#ifdef CDF_DEBUG5285+ cdf_dump_catalog(&h, &scn);5286+#endif5287+ if ((i = cdf_file_catalog(ms, &h, &scn))5288+ < 0)5289+ expn = "Can't expand catalog";5290} else {5291expn = "Cannot read summary info";5292}5293@@ -464,7 +512,8 @@ out0:5294if (file_printf(ms, ", %s%s", corrupt, expn) == -1)5295return -1;5296} else {5297- if (file_printf(ms, "application/CDFV2-corrupt") == -1)5298+ if (file_printf(ms, "application/CDFV2-%s",5299+ *corrupt ? "corrupt" : "encrypted") == -1)5300return -1;5301}5302i = 1;5303Index: contrib/file/src/readelf.c5304===================================================================5305--- contrib/file/src/readelf.c (revision 284174)5306+++ contrib/file/src/readelf.c (working copy)5307@@ -27,7 +27,7 @@5308#include "file.h"53095310#ifndef lint5311-FILE_RCSID("@(#)$File: readelf.c,v 1.103 2014/05/02 02:25:10 christos Exp $")5312+FILE_RCSID("@(#)$File: readelf.c,v 1.117 2014/12/16 23:29:42 christos Exp $")5313#endif53145315#ifdef BUILTIN_ELF5316@@ -43,14 +43,14 @@53175318#ifdef ELFCORE5319private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,5320- off_t, int *);5321+ off_t, int *, uint16_t *);5322#endif5323private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,5324- off_t, int *, int);5325+ off_t, int, int *, uint16_t *);5326private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,5327- off_t, int *, int, int);5328+ off_t, int, int, int *, uint16_t *);5329private size_t donote(struct magic_set *, void *, size_t, size_t, int,5330- int, size_t, int *);5331+ int, size_t, int *, uint16_t *);53325333#define ELF_ALIGN(a) ((((a) + align - 1) / align) * align)53345335@@ -60,13 +60,14 @@ private uint16_t getu16(int, uint16_t);5336private uint32_t getu32(int, uint32_t);5337private uint64_t getu64(int, uint64_t);53385339-#define MAX_PHNUM 2565340-#define MAX_SHNUM 10245341+#define MAX_PHNUM 1285342+#define MAX_SHNUM 327685343+#define SIZE_UNKNOWN ((off_t)-1)53445345private int5346toomany(struct magic_set *ms, const char *name, uint16_t num)5347{5348- if (file_printf(ms, ", too many %s header sections (%u)", name, num5349+ if (file_printf(ms, ", too many %s (%u)", name, num5350) == -1)5351return -1;5352return 0;5353@@ -292,15 +293,19 @@ private const char os_style_names[][8] = {5354"NetBSD",5355};53565357-#define FLAGS_DID_CORE 0x015358-#define FLAGS_DID_NOTE 0x025359-#define FLAGS_DID_BUILD_ID 0x045360-#define FLAGS_DID_CORE_STYLE 0x085361-#define FLAGS_IS_CORE 0x105362+#define FLAGS_DID_CORE 0x0015363+#define FLAGS_DID_OS_NOTE 0x0025364+#define FLAGS_DID_BUILD_ID 0x0045365+#define FLAGS_DID_CORE_STYLE 0x0085366+#define FLAGS_DID_NETBSD_PAX 0x0105367+#define FLAGS_DID_NETBSD_MARCH 0x0205368+#define FLAGS_DID_NETBSD_CMODEL 0x0405369+#define FLAGS_DID_NETBSD_UNKNOWN 0x0805370+#define FLAGS_IS_CORE 0x10053715372private int5373dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,5374- int num, size_t size, off_t fsize, int *flags)5375+ int num, size_t size, off_t fsize, int *flags, uint16_t *notecount)5376{5377Elf32_Phdr ph32;5378Elf64_Phdr ph64;5379@@ -318,13 +323,13 @@ dophn_core(struct magic_set *ms, int clazz, int sw5380* Loop through all the program headers.5381*/5382for ( ; num; num--) {5383- if (pread(fd, xph_addr, xph_sizeof, off) == -1) {5384+ if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {5385file_badread(ms);5386return -1;5387}5388off += size;53895390- if (xph_offset > fsize) {5391+ if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {5392/* Perhaps warn here */5393continue;5394}5395@@ -346,7 +351,7 @@ dophn_core(struct magic_set *ms, int clazz, int sw5396if (offset >= (size_t)bufsize)5397break;5398offset = donote(ms, nbuf, offset, (size_t)bufsize,5399- clazz, swap, 4, flags);5400+ clazz, swap, 4, flags, notecount);5401if (offset == 0)5402break;54035404@@ -476,132 +481,127 @@ do_note_freebsd_version(struct magic_set *ms, int5405}5406}54075408-private size_t5409-donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,5410- int clazz, int swap, size_t align, int *flags)5411+private int5412+do_bid_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,5413+ int swap __attribute__((__unused__)), uint32_t namesz, uint32_t descsz,5414+ size_t noff, size_t doff, int *flags)5415{5416- Elf32_Nhdr nh32;5417- Elf64_Nhdr nh64;5418- size_t noff, doff;5419-#ifdef ELFCORE5420- int os_style = -1;5421-#endif5422- uint32_t namesz, descsz;5423- unsigned char *nbuf = CAST(unsigned char *, vbuf);5424-5425- if (xnh_sizeof + offset > size) {5426- /*5427- * We're out of note headers.5428- */5429- return xnh_sizeof + offset;5430+ if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&5431+ type == NT_GNU_BUILD_ID && (descsz == 16 || descsz == 20)) {5432+ uint8_t desc[20];5433+ uint32_t i;5434+ *flags |= FLAGS_DID_BUILD_ID;5435+ if (file_printf(ms, ", BuildID[%s]=", descsz == 16 ? "md5/uuid" :5436+ "sha1") == -1)5437+ return 1;5438+ (void)memcpy(desc, &nbuf[doff], descsz);5439+ for (i = 0; i < descsz; i++)5440+ if (file_printf(ms, "%02x", desc[i]) == -1)5441+ return 1;5442+ return 1;5443}5444+ return 0;5445+}54465447- (void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof);5448- offset += xnh_sizeof;5449-5450- namesz = xnh_namesz;5451- descsz = xnh_descsz;5452- if ((namesz == 0) && (descsz == 0)) {5453- /*5454- * We're out of note headers.5455- */5456- return (offset >= size) ? offset : size;5457- }5458-5459- if (namesz & 0x80000000) {5460- (void)file_printf(ms, ", bad note name size 0x%lx",5461- (unsigned long)namesz);5462- return 0;5463- }5464-5465- if (descsz & 0x80000000) {5466- (void)file_printf(ms, ", bad note description size 0x%lx",5467- (unsigned long)descsz);5468- return 0;5469- }5470-5471-5472- noff = offset;5473- doff = ELF_ALIGN(offset + namesz);5474-5475- if (offset + namesz > size) {5476- /*5477- * We're past the end of the buffer.5478- */5479- return doff;5480- }5481-5482- offset = ELF_ALIGN(doff + descsz);5483- if (doff + descsz > size) {5484- /*5485- * We're past the end of the buffer.5486- */5487- return (offset >= size) ? offset : size;5488- }5489-5490- if ((*flags & (FLAGS_DID_NOTE|FLAGS_DID_BUILD_ID)) ==5491- (FLAGS_DID_NOTE|FLAGS_DID_BUILD_ID))5492- goto core;5493-5494+private int5495+do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,5496+ int swap, uint32_t namesz, uint32_t descsz,5497+ size_t noff, size_t doff, int *flags)5498+{5499if (namesz == 5 && strcmp((char *)&nbuf[noff], "SuSE") == 0 &&5500- xnh_type == NT_GNU_VERSION && descsz == 2) {5501+ type == NT_GNU_VERSION && descsz == 2) {5502+ *flags |= FLAGS_DID_OS_NOTE;5503file_printf(ms, ", for SuSE %d.%d", nbuf[doff], nbuf[doff + 1]);5504+ return 1;5505}5506+5507if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&5508- xnh_type == NT_GNU_VERSION && descsz == 16) {5509+ type == NT_GNU_VERSION && descsz == 16) {5510uint32_t desc[4];5511(void)memcpy(desc, &nbuf[doff], sizeof(desc));55125513+ *flags |= FLAGS_DID_OS_NOTE;5514if (file_printf(ms, ", for GNU/") == -1)5515- return size;5516+ return 1;5517switch (elf_getu32(swap, desc[0])) {5518case GNU_OS_LINUX:5519if (file_printf(ms, "Linux") == -1)5520- return size;5521+ return 1;5522break;5523case GNU_OS_HURD:5524if (file_printf(ms, "Hurd") == -1)5525- return size;5526+ return 1;5527break;5528case GNU_OS_SOLARIS:5529if (file_printf(ms, "Solaris") == -1)5530- return size;5531+ return 1;5532break;5533case GNU_OS_KFREEBSD:5534if (file_printf(ms, "kFreeBSD") == -1)5535- return size;5536+ return 1;5537break;5538case GNU_OS_KNETBSD:5539if (file_printf(ms, "kNetBSD") == -1)5540- return size;5541+ return 1;5542break;5543default:5544if (file_printf(ms, "<unknown>") == -1)5545- return size;5546+ return 1;5547}5548if (file_printf(ms, " %d.%d.%d", elf_getu32(swap, desc[1]),5549elf_getu32(swap, desc[2]), elf_getu32(swap, desc[3])) == -1)5550- return size;5551- *flags |= FLAGS_DID_NOTE;5552- return size;5553+ return 1;5554+ return 1;5555}55565557- if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&5558- xnh_type == NT_GNU_BUILD_ID && (descsz == 16 || descsz == 20)) {5559- uint8_t desc[20];5560- uint32_t i;5561- if (file_printf(ms, ", BuildID[%s]=", descsz == 16 ? "md5/uuid" :5562- "sha1") == -1)5563- return size;5564- (void)memcpy(desc, &nbuf[doff], descsz);5565- for (i = 0; i < descsz; i++)5566- if (file_printf(ms, "%02x", desc[i]) == -1)5567- return size;5568- *flags |= FLAGS_DID_BUILD_ID;5569+ if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) {5570+ if (type == NT_NETBSD_VERSION && descsz == 4) {5571+ *flags |= FLAGS_DID_OS_NOTE;5572+ do_note_netbsd_version(ms, swap, &nbuf[doff]);5573+ return 1;5574+ }5575}55765577+ if (namesz == 8 && strcmp((char *)&nbuf[noff], "FreeBSD") == 0) {5578+ if (type == NT_FREEBSD_VERSION && descsz == 4) {5579+ *flags |= FLAGS_DID_OS_NOTE;5580+ do_note_freebsd_version(ms, swap, &nbuf[doff]);5581+ return 1;5582+ }5583+ }5584+5585+ if (namesz == 8 && strcmp((char *)&nbuf[noff], "OpenBSD") == 0 &&5586+ type == NT_OPENBSD_VERSION && descsz == 4) {5587+ *flags |= FLAGS_DID_OS_NOTE;5588+ if (file_printf(ms, ", for OpenBSD") == -1)5589+ return 1;5590+ /* Content of note is always 0 */5591+ return 1;5592+ }5593+5594+ if (namesz == 10 && strcmp((char *)&nbuf[noff], "DragonFly") == 0 &&5595+ type == NT_DRAGONFLY_VERSION && descsz == 4) {5596+ uint32_t desc;5597+ *flags |= FLAGS_DID_OS_NOTE;5598+ if (file_printf(ms, ", for DragonFly") == -1)5599+ return 1;5600+ (void)memcpy(&desc, &nbuf[doff], sizeof(desc));5601+ desc = elf_getu32(swap, desc);5602+ if (file_printf(ms, " %d.%d.%d", desc / 100000,5603+ desc / 10000 % 10, desc % 10000) == -1)5604+ return 1;5605+ return 1;5606+ }5607+ return 0;5608+}5609+5610+private int5611+do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,5612+ int swap, uint32_t namesz, uint32_t descsz,5613+ size_t noff, size_t doff, int *flags)5614+{5615if (namesz == 4 && strcmp((char *)&nbuf[noff], "PaX") == 0 &&5616- xnh_type == NT_NETBSD_PAX && descsz == 4) {5617+ type == NT_NETBSD_PAX && descsz == 4) {5618static const char *pax[] = {5619"+mprotect",5620"-mprotect",5621@@ -614,11 +614,12 @@ do_note_freebsd_version(struct magic_set *ms, int5622size_t i;5623int did = 0;56245625+ *flags |= FLAGS_DID_NETBSD_PAX;5626(void)memcpy(&desc, &nbuf[doff], sizeof(desc));5627desc = elf_getu32(swap, desc);56285629if (desc && file_printf(ms, ", PaX: ") == -1)5630- return size;5631+ return 1;56325633for (i = 0; i < __arraycount(pax); i++) {5634if (((1 << i) & desc) == 0)5635@@ -625,69 +626,20 @@ do_note_freebsd_version(struct magic_set *ms, int5636continue;5637if (file_printf(ms, "%s%s", did++ ? "," : "",5638pax[i]) == -1)5639- return size;5640+ return 1;5641}5642+ return 1;5643}5644+ return 0;5645+}56465647- if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) {5648- switch (xnh_type) {5649- case NT_NETBSD_VERSION:5650- if (descsz == 4) {5651- do_note_netbsd_version(ms, swap, &nbuf[doff]);5652- *flags |= FLAGS_DID_NOTE;5653- return size;5654- }5655- break;5656- case NT_NETBSD_MARCH:5657- if (file_printf(ms, ", compiled for: %.*s", (int)descsz,5658- (const char *)&nbuf[doff]) == -1)5659- return size;5660- break;5661- case NT_NETBSD_CMODEL:5662- if (file_printf(ms, ", compiler model: %.*s",5663- (int)descsz, (const char *)&nbuf[doff]) == -1)5664- return size;5665- break;5666- default:5667- if (file_printf(ms, ", note=%u", xnh_type) == -1)5668- return size;5669- break;5670- }5671- return size;5672- }5673-5674- if (namesz == 8 && strcmp((char *)&nbuf[noff], "FreeBSD") == 0) {5675- if (xnh_type == NT_FREEBSD_VERSION && descsz == 4) {5676- do_note_freebsd_version(ms, swap, &nbuf[doff]);5677- *flags |= FLAGS_DID_NOTE;5678- return size;5679- }5680- }5681-5682- if (namesz == 8 && strcmp((char *)&nbuf[noff], "OpenBSD") == 0 &&5683- xnh_type == NT_OPENBSD_VERSION && descsz == 4) {5684- if (file_printf(ms, ", for OpenBSD") == -1)5685- return size;5686- /* Content of note is always 0 */5687- *flags |= FLAGS_DID_NOTE;5688- return size;5689- }5690-5691- if (namesz == 10 && strcmp((char *)&nbuf[noff], "DragonFly") == 0 &&5692- xnh_type == NT_DRAGONFLY_VERSION && descsz == 4) {5693- uint32_t desc;5694- if (file_printf(ms, ", for DragonFly") == -1)5695- return size;5696- (void)memcpy(&desc, &nbuf[doff], sizeof(desc));5697- desc = elf_getu32(swap, desc);5698- if (file_printf(ms, " %d.%d.%d", desc / 100000,5699- desc / 10000 % 10, desc % 10000) == -1)5700- return size;5701- *flags |= FLAGS_DID_NOTE;5702- return size;5703- }5704-5705-core:5706+private int5707+do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,5708+ int swap, uint32_t namesz, uint32_t descsz,5709+ size_t noff, size_t doff, int *flags, size_t size, int clazz)5710+{5711+#ifdef ELFCORE5712+ int os_style = -1;5713/*5714* Sigh. The 2.0.36 kernel in Debian 2.1, at5715* least, doesn't correctly implement name5716@@ -716,20 +668,17 @@ do_note_freebsd_version(struct magic_set *ms, int5717os_style = OS_STYLE_NETBSD;5718}57195720-#ifdef ELFCORE5721- if ((*flags & FLAGS_DID_CORE) != 0)5722- return size;5723-5724if (os_style != -1 && (*flags & FLAGS_DID_CORE_STYLE) == 0) {5725if (file_printf(ms, ", %s-style", os_style_names[os_style])5726== -1)5727- return size;5728+ return 1;5729*flags |= FLAGS_DID_CORE_STYLE;5730}57315732switch (os_style) {5733case OS_STYLE_NETBSD:5734- if (xnh_type == NT_NETBSD_CORE_PROCINFO) {5735+ if (type == NT_NETBSD_CORE_PROCINFO) {5736+ char sbuf[512];5737uint32_t signo;5738/*5739* Extract the program name. It is at5740@@ -737,8 +686,9 @@ do_note_freebsd_version(struct magic_set *ms, int5741* including the terminating NUL.5742*/5743if (file_printf(ms, ", from '%.31s'",5744- &nbuf[doff + 0x7c]) == -1)5745- return size;5746+ file_printable(sbuf, sizeof(sbuf),5747+ (const char *)&nbuf[doff + 0x7c])) == -1)5748+ return 1;57495750/*5751* Extract the signal number. It is at5752@@ -748,14 +698,14 @@ do_note_freebsd_version(struct magic_set *ms, int5753sizeof(signo));5754if (file_printf(ms, " (signal %u)",5755elf_getu32(swap, signo)) == -1)5756- return size;5757+ return 1;5758*flags |= FLAGS_DID_CORE;5759- return size;5760+ return 1;5761}5762break;57635764default:5765- if (xnh_type == NT_PRPSINFO && *flags & FLAGS_IS_CORE) {5766+ if (type == NT_PRPSINFO && *flags & FLAGS_IS_CORE) {5767size_t i, j;5768unsigned char c;5769/*5770@@ -823,7 +773,7 @@ do_note_freebsd_version(struct magic_set *ms, int5771* Try next offsets, in case this match is5772* in the middle of a string.5773*/5774- for (k = i + 1 ; k < NOFFSETS ; k++) {5775+ for (k = i + 1 ; k < NOFFSETS; k++) {5776size_t no;5777int adjust = 1;5778if (prpsoffsets(k) >= prpsoffsets(i))5779@@ -848,9 +798,9 @@ do_note_freebsd_version(struct magic_set *ms, int5780cp--;5781if (file_printf(ms, ", from '%.*s'",5782(int)(cp - cname), cname) == -1)5783- return size;5784+ return 1;5785*flags |= FLAGS_DID_CORE;5786- return size;5787+ return 1;57885789tryanother:5790;5791@@ -859,6 +809,129 @@ do_note_freebsd_version(struct magic_set *ms, int5792break;5793}5794#endif5795+ return 0;5796+}5797+5798+private size_t5799+donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,5800+ int clazz, int swap, size_t align, int *flags, uint16_t *notecount)5801+{5802+ Elf32_Nhdr nh32;5803+ Elf64_Nhdr nh64;5804+ size_t noff, doff;5805+ uint32_t namesz, descsz;5806+ unsigned char *nbuf = CAST(unsigned char *, vbuf);5807+5808+ if (*notecount == 0)5809+ return 0;5810+ --*notecount;5811+5812+ if (xnh_sizeof + offset > size) {5813+ /*5814+ * We're out of note headers.5815+ */5816+ return xnh_sizeof + offset;5817+ }5818+5819+ (void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof);5820+ offset += xnh_sizeof;5821+5822+ namesz = xnh_namesz;5823+ descsz = xnh_descsz;5824+ if ((namesz == 0) && (descsz == 0)) {5825+ /*5826+ * We're out of note headers.5827+ */5828+ return (offset >= size) ? offset : size;5829+ }5830+5831+ if (namesz & 0x80000000) {5832+ (void)file_printf(ms, ", bad note name size 0x%lx",5833+ (unsigned long)namesz);5834+ return 0;5835+ }5836+5837+ if (descsz & 0x80000000) {5838+ (void)file_printf(ms, ", bad note description size 0x%lx",5839+ (unsigned long)descsz);5840+ return 0;5841+ }5842+5843+ noff = offset;5844+ doff = ELF_ALIGN(offset + namesz);5845+5846+ if (offset + namesz > size) {5847+ /*5848+ * We're past the end of the buffer.5849+ */5850+ return doff;5851+ }5852+5853+ offset = ELF_ALIGN(doff + descsz);5854+ if (doff + descsz > size) {5855+ /*5856+ * We're past the end of the buffer.5857+ */5858+ return (offset >= size) ? offset : size;5859+ }5860+5861+ if ((*flags & FLAGS_DID_OS_NOTE) == 0) {5862+ if (do_os_note(ms, nbuf, xnh_type, swap,5863+ namesz, descsz, noff, doff, flags))5864+ return size;5865+ }5866+5867+ if ((*flags & FLAGS_DID_BUILD_ID) == 0) {5868+ if (do_bid_note(ms, nbuf, xnh_type, swap,5869+ namesz, descsz, noff, doff, flags))5870+ return size;5871+ }5872+5873+ if ((*flags & FLAGS_DID_NETBSD_PAX) == 0) {5874+ if (do_pax_note(ms, nbuf, xnh_type, swap,5875+ namesz, descsz, noff, doff, flags))5876+ return size;5877+ }5878+5879+ if ((*flags & FLAGS_DID_CORE) == 0) {5880+ if (do_core_note(ms, nbuf, xnh_type, swap,5881+ namesz, descsz, noff, doff, flags, size, clazz))5882+ return size;5883+ }5884+5885+ if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) {5886+ if (descsz > 100)5887+ descsz = 100;5888+ switch (xnh_type) {5889+ case NT_NETBSD_VERSION:5890+ return size;5891+ case NT_NETBSD_MARCH:5892+ if (*flags & FLAGS_DID_NETBSD_MARCH)5893+ return size;5894+ *flags |= FLAGS_DID_NETBSD_MARCH;5895+ if (file_printf(ms, ", compiled for: %.*s",5896+ (int)descsz, (const char *)&nbuf[doff]) == -1)5897+ return size;5898+ break;5899+ case NT_NETBSD_CMODEL:5900+ if (*flags & FLAGS_DID_NETBSD_CMODEL)5901+ return size;5902+ *flags |= FLAGS_DID_NETBSD_CMODEL;5903+ if (file_printf(ms, ", compiler model: %.*s",5904+ (int)descsz, (const char *)&nbuf[doff]) == -1)5905+ return size;5906+ break;5907+ default:5908+ if (*flags & FLAGS_DID_NETBSD_UNKNOWN)5909+ return size;5910+ *flags |= FLAGS_DID_NETBSD_UNKNOWN;5911+ if (file_printf(ms, ", note=%u", xnh_type) == -1)5912+ return size;5913+ break;5914+ }5915+ return size;5916+ }5917+5918return offset;5919}59205921@@ -914,7 +987,8 @@ static const cap_desc_t cap_desc_386[] = {59225923private int5924doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,5925- size_t size, off_t fsize, int *flags, int mach, int strtab)5926+ size_t size, off_t fsize, int mach, int strtab, int *flags,5927+ uint16_t *notecount)5928{5929Elf32_Shdr sh32;5930Elf64_Shdr sh64;5931@@ -925,6 +999,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i5932uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */5933uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */5934char name[50];5935+ ssize_t namesize;59365937if (size != xsh_sizeof) {5938if (file_printf(ms, ", corrupted section header size") == -1)5939@@ -933,7 +1008,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i5940}59415942/* Read offset of name section to be able to read section names later */5943- if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) == -1) {5944+ if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) < (ssize_t)xsh_sizeof) {5945file_badread(ms);5946return -1;5947}5948@@ -941,15 +1016,15 @@ doshn(struct magic_set *ms, int clazz, int swap, i59495950for ( ; num; num--) {5951/* Read the name of this section. */5952- if (pread(fd, name, sizeof(name), name_off + xsh_name) == -1) {5953+ if ((namesize = pread(fd, name, sizeof(name) - 1, name_off + xsh_name)) == -1) {5954file_badread(ms);5955return -1;5956}5957- name[sizeof(name) - 1] = '\0';5958+ name[namesize] = '\0';5959if (strcmp(name, ".debug_info") == 0)5960stripped = 0;59615962- if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) {5963+ if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {5964file_badread(ms);5965return -1;5966}5967@@ -964,7 +1039,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i5968stripped = 0;5969break;5970default:5971- if (xsh_offset > fsize) {5972+ if (fsize != SIZE_UNKNOWN && xsh_offset > fsize) {5973/* Perhaps warn here */5974continue;5975}5976@@ -979,7 +1054,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i5977" for note");5978return -1;5979}5980- if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) {5981+ if (pread(fd, nbuf, xsh_size, xsh_offset) < (ssize_t)xsh_size) {5982file_badread(ms);5983free(nbuf);5984return -1;5985@@ -990,7 +1065,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i5986if (noff >= (off_t)xsh_size)5987break;5988noff = donote(ms, nbuf, (size_t)noff,5989- xsh_size, clazz, swap, 4, flags);5990+ xsh_size, clazz, swap, 4, flags, notecount);5991if (noff == 0)5992break;5993}5994@@ -1157,13 +1232,15 @@ doshn(struct magic_set *ms, int clazz, int swap, i5995*/5996private int5997dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,5998- int num, size_t size, off_t fsize, int *flags, int sh_num)5999+ int num, size_t size, off_t fsize, int sh_num, int *flags,6000+ uint16_t *notecount)6001{6002Elf32_Phdr ph32;6003Elf64_Phdr ph64;6004const char *linking_style = "statically";6005- const char *shared_libraries = "";6006+ const char *interp = "";6007unsigned char nbuf[BUFSIZ];6008+ char ibuf[BUFSIZ];6009ssize_t bufsize;6010size_t offset, align, len;60116012@@ -1174,12 +1251,14 @@ dophn_exec(struct magic_set *ms, int clazz, int sw6013}60146015for ( ; num; num--) {6016- if (pread(fd, xph_addr, xph_sizeof, off) == -1) {6017+ if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {6018file_badread(ms);6019return -1;6020}60216022off += size;6023+ bufsize = 0;6024+ align = 4;60256026/* Things we can determine before we seek */6027switch (xph_type) {6028@@ -1186,11 +1265,29 @@ dophn_exec(struct magic_set *ms, int clazz, int sw6029case PT_DYNAMIC:6030linking_style = "dynamically";6031break;6032+ case PT_NOTE:6033+ if (sh_num) /* Did this through section headers */6034+ continue;6035+ if (((align = xph_align) & 0x80000000UL) != 0 ||6036+ align < 4) {6037+ if (file_printf(ms,6038+ ", invalid note alignment 0x%lx",6039+ (unsigned long)align) == -1)6040+ return -1;6041+ align = 4;6042+ }6043+ /*FALLTHROUGH*/6044case PT_INTERP:6045- shared_libraries = " (uses shared libs)";6046+ len = xph_filesz < sizeof(nbuf) ? xph_filesz6047+ : sizeof(nbuf);6048+ bufsize = pread(fd, nbuf, len, xph_offset);6049+ if (bufsize == -1) {6050+ file_badread(ms);6051+ return -1;6052+ }6053break;6054default:6055- if (xph_offset > fsize) {6056+ if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {6057/* Maybe warn here? */6058continue;6059}6060@@ -1199,27 +1296,18 @@ dophn_exec(struct magic_set *ms, int clazz, int sw60616062/* Things we can determine when we seek */6063switch (xph_type) {6064+ case PT_INTERP:6065+ if (bufsize && nbuf[0]) {6066+ nbuf[bufsize - 1] = '\0';6067+ interp = (const char *)nbuf;6068+ } else6069+ interp = "*empty*";6070+ break;6071case PT_NOTE:6072- if ((align = xph_align) & 0x80000000UL) {6073- if (file_printf(ms,6074- ", invalid note alignment 0x%lx",6075- (unsigned long)align) == -1)6076- return -1;6077- align = 4;6078- }6079- if (sh_num)6080- break;6081/*6082* This is a PT_NOTE section; loop through all the notes6083* in the section.6084*/6085- len = xph_filesz < sizeof(nbuf) ? xph_filesz6086- : sizeof(nbuf);6087- bufsize = pread(fd, nbuf, len, xph_offset);6088- if (bufsize == -1) {6089- file_badread(ms);6090- return -1;6091- }6092offset = 0;6093for (;;) {6094if (offset >= (size_t)bufsize)6095@@ -1226,7 +1314,7 @@ dophn_exec(struct magic_set *ms, int clazz, int sw6096break;6097offset = donote(ms, nbuf, offset,6098(size_t)bufsize, clazz, swap, align,6099- flags);6100+ flags, notecount);6101if (offset == 0)6102break;6103}6104@@ -1235,9 +1323,13 @@ dophn_exec(struct magic_set *ms, int clazz, int sw6105break;6106}6107}6108- if (file_printf(ms, ", %s linked%s", linking_style, shared_libraries)6109+ if (file_printf(ms, ", %s linked", linking_style)6110== -1)6111- return -1;6112+ return -1;6113+ if (interp[0])6114+ if (file_printf(ms, ", interpreter %s",6115+ file_printable(ibuf, sizeof(ibuf), interp)) == -1)6116+ return -1;6117return 0;6118}61196120@@ -1257,7 +1349,7 @@ file_tryelf(struct magic_set *ms, int fd, const un6121int flags = 0;6122Elf32_Ehdr elf32hdr;6123Elf64_Ehdr elf64hdr;6124- uint16_t type, phnum, shnum;6125+ uint16_t type, phnum, shnum, notecount;61266127if (ms->flags & (MAGIC_MIME|MAGIC_APPLE))6128return 0;6129@@ -1283,7 +1375,10 @@ file_tryelf(struct magic_set *ms, int fd, const un6130file_badread(ms);6131return -1;6132}6133- fsize = st.st_size;6134+ if (S_ISREG(st.st_mode) || st.st_size != 0)6135+ fsize = st.st_size;6136+ else6137+ fsize = SIZE_UNKNOWN;61386139clazz = buf[EI_CLASS];61406141Index: contrib/file/src/softmagic.c6142===================================================================6143--- contrib/file/src/softmagic.c (revision 284174)6144+++ contrib/file/src/softmagic.c (working copy)6145@@ -32,7 +32,7 @@6146#include "file.h"61476148#ifndef lint6149-FILE_RCSID("@(#)$File: softmagic.c,v 1.191 2014/06/04 17:36:34 christos Exp $")6150+FILE_RCSID("@(#)$File: softmagic.c,v 1.206 2015/01/01 17:07:34 christos Exp $")6151#endif /* lint */61526153#include "magic.h"6154@@ -41,17 +41,13 @@6155#include <ctype.h>6156#include <stdlib.h>6157#include <time.h>6158-#if defined(HAVE_LOCALE_H)6159-#include <locale.h>6160-#endif61616162-6163private int match(struct magic_set *, struct magic *, uint32_t,6164- const unsigned char *, size_t, size_t, int, int, int, int, int *, int *,6165- int *);6166+ const unsigned char *, size_t, size_t, int, int, int, uint16_t,6167+ uint16_t *, int *, int *, int *);6168private int mget(struct magic_set *, const unsigned char *,6169- struct magic *, size_t, size_t, unsigned int, int, int, int, int, int *,6170- int *, int *);6171+ struct magic *, size_t, size_t, unsigned int, int, int, int, uint16_t,6172+ uint16_t *, int *, int *, int *);6173private int magiccheck(struct magic_set *, struct magic *);6174private int32_t mprint(struct magic_set *, struct magic *);6175private int32_t moffset(struct magic_set *, struct magic *);6176@@ -68,8 +64,6 @@ private void cvt_64(union VALUETYPE *, const struc61776178#define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o)))61796180-#define MAX_RECURSION_LEVEL 106181-6182/*6183* softmagic - lookup one file in parsed, in-memory copy of database6184* Passed the name and FILE * of one file to be typed.6185@@ -77,14 +71,21 @@ private void cvt_64(union VALUETYPE *, const struc6186/*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */6187protected int6188file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,6189- size_t level, int mode, int text)6190+ uint16_t indir_level, uint16_t *name_count, int mode, int text)6191{6192struct mlist *ml;6193int rv, printed_something = 0, need_separator = 0;6194+ uint16_t nc;6195+6196+ if (name_count == NULL) {6197+ nc = 0;6198+ name_count = &nc;6199+ }6200+6201for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)6202if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode,6203- text, 0, level, &printed_something, &need_separator,6204- NULL)) != 0)6205+ text, 0, indir_level, name_count,6206+ &printed_something, &need_separator, NULL)) != 0)6207return rv;62086209return 0;6210@@ -101,8 +102,8 @@ file_fmtcheck(struct magic_set *ms, const struct m6211const char *ptr = fmtcheck(m->desc, def);6212if (ptr == def)6213file_magerror(ms,6214- "%s, %zu: format `%s' does not match with `%s'",6215- file, line, m->desc, def);6216+ "%s, %" SIZE_T_FORMAT "u: format `%s' does not match"6217+ " with `%s'", file, line, m->desc, def);6218return ptr;6219}6220#else6221@@ -139,8 +140,8 @@ file_fmtcheck(struct magic_set *ms, const struct m6222private int6223match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,6224const unsigned char *s, size_t nbytes, size_t offset, int mode, int text,6225- int flip, int recursion_level, int *printed_something, int *need_separator,6226- int *returnval)6227+ int flip, uint16_t indir_level, uint16_t *name_count,6228+ int *printed_something, int *need_separator, int *returnval)6229{6230uint32_t magindex = 0;6231unsigned int cont_level = 0;6232@@ -177,8 +178,8 @@ match(struct magic_set *ms, struct magic *magic, u62336234/* if main entry matches, print it... */6235switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text,6236- flip, recursion_level + 1, printed_something,6237- need_separator, returnval)) {6238+ flip, indir_level, name_count,6239+ printed_something, need_separator, returnval)) {6240case -1:6241return -1;6242case 0:6243@@ -238,9 +239,9 @@ match(struct magic_set *ms, struct magic *magic, u6244if (file_check_mem(ms, ++cont_level) == -1)6245return -1;62466247- while (++magindex < nmagic &&6248- magic[magindex].cont_level != 0) {6249- m = &magic[magindex];6250+ while (magindex + 1 < nmagic &&6251+ magic[magindex + 1].cont_level != 0) {6252+ m = &magic[++magindex];6253ms->line = m->lineno; /* for messages */62546255if (cont_level < m->cont_level)6256@@ -266,8 +267,8 @@ match(struct magic_set *ms, struct magic *magic, u6257}6258#endif6259switch (mget(ms, s, m, nbytes, offset, cont_level, mode,6260- text, flip, recursion_level + 1, printed_something,6261- need_separator, returnval)) {6262+ text, flip, indir_level, name_count,6263+ printed_something, need_separator, returnval)) {6264case -1:6265return -1;6266case 0:6267@@ -410,7 +411,7 @@ mprint(struct magic_set *ms, struct magic *m)6268float vf;6269double vd;6270int64_t t = 0;6271- char buf[128], tbuf[26];6272+ char buf[128], tbuf[26], sbuf[512];6273union VALUETYPE *p = &ms->ms_value;62746275switch (m->type) {6276@@ -504,7 +505,9 @@ mprint(struct magic_set *ms, struct magic *m)6277case FILE_BESTRING16:6278case FILE_LESTRING16:6279if (m->reln == '=' || m->reln == '!') {6280- if (file_printf(ms, F(ms, m, "%s"), m->value.s) == -1)6281+ if (file_printf(ms, F(ms, m, "%s"),6282+ file_printable(sbuf, sizeof(sbuf), m->value.s))6283+ == -1)6284return -1;6285t = ms->offset + m->vallen;6286}6287@@ -530,7 +533,8 @@ mprint(struct magic_set *ms, struct magic *m)6288*++last = '\0';6289}62906291- if (file_printf(ms, F(ms, m, "%s"), str) == -1)6292+ if (file_printf(ms, F(ms, m, "%s"),6293+ file_printable(sbuf, sizeof(sbuf), str)) == -1)6294return -1;62956296if (m->type == FILE_PSTRING)6297@@ -634,7 +638,8 @@ mprint(struct magic_set *ms, struct magic *m)6298file_oomem(ms, ms->search.rm_len);6299return -1;6300}6301- rval = file_printf(ms, F(ms, m, "%s"), cp);6302+ rval = file_printf(ms, F(ms, m, "%s"),6303+ file_printable(sbuf, sizeof(sbuf), cp));6304free(cp);63056306if (rval == -1)6307@@ -648,7 +653,8 @@ mprint(struct magic_set *ms, struct magic *m)6308}63096310case FILE_SEARCH:6311- if (file_printf(ms, F(ms, m, "%s"), m->value.s) == -1)6312+ if (file_printf(ms, F(ms, m, "%s"),6313+ file_printable(sbuf, sizeof(sbuf), m->value.s)) == -1)6314return -1;6315if ((m->str_flags & REGEX_OFFSET_START))6316t = ms->search.offset;6317@@ -946,14 +952,17 @@ mconvert(struct magic_set *ms, struct magic *m, in6318size_t sz = file_pstring_length_size(m);6319char *ptr1 = p->s, *ptr2 = ptr1 + sz;6320size_t len = file_pstring_get_length(m, ptr1);6321- if (len >= sizeof(p->s)) {6322+ sz = sizeof(p->s) - sz; /* maximum length of string */6323+ if (len >= sz) {6324/*6325* The size of the pascal string length (sz)6326* is 1, 2, or 4. We need at least 1 byte for NUL6327* termination, but we've already truncated the6328* string by p->s, so we need to deduct sz.6329+ * Because we can use one of the bytes of the length6330+ * after we shifted as NUL termination.6331*/6332- len = sizeof(p->s) - sz;6333+ len = sz;6334}6335while (len--)6336*ptr1++ = *ptr2++;6337@@ -1063,7 +1072,7 @@ mconvert(struct magic_set *ms, struct magic *m, in6338private void6339mdebug(uint32_t offset, const char *str, size_t len)6340{6341- (void) fprintf(stderr, "mget/%zu @%d: ", len, offset);6342+ (void) fprintf(stderr, "mget/%" SIZE_T_FORMAT "u @%d: ", len, offset);6343file_showstr(stderr, str, len);6344(void) fputc('\n', stderr);6345(void) fputc('\n', stderr);6346@@ -1193,8 +1202,8 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, in6347private int6348mget(struct magic_set *ms, const unsigned char *s, struct magic *m,6349size_t nbytes, size_t o, unsigned int cont_level, int mode, int text,6350- int flip, int recursion_level, int *printed_something,6351- int *need_separator, int *returnval)6352+ int flip, uint16_t indir_level, uint16_t *name_count,6353+ int *printed_something, int *need_separator, int *returnval)6354{6355uint32_t offset = ms->offset;6356uint32_t lhs;6357@@ -1204,18 +1213,28 @@ mget(struct magic_set *ms, const unsigned char *s,6358union VALUETYPE *p = &ms->ms_value;6359struct mlist ml;63606361- if (recursion_level >= MAX_RECURSION_LEVEL) {6362- file_error(ms, 0, "recursion nesting exceeded");6363+ if (indir_level >= ms->indir_max) {6364+ file_error(ms, 0, "indirect recursion nesting (%hu) exceeded",6365+ indir_level);6366return -1;6367}63686369+ if (*name_count >= ms->name_max) {6370+ file_error(ms, 0, "name use count (%hu) exceeded",6371+ *name_count);6372+ return -1;6373+ }6374+6375if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o),6376(uint32_t)nbytes, m) == -1)6377return -1;63786379if ((ms->flags & MAGIC_DEBUG) != 0) {6380- fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%zu, "6381- "nbytes=%zu)\n", m->type, m->flag, offset, o, nbytes);6382+ fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%"6383+ SIZE_T_FORMAT "u, " "nbytes=%" SIZE_T_FORMAT6384+ "u, il=%hu, nc=%hu)\n",6385+ m->type, m->flag, offset, o, nbytes,6386+ indir_level, *name_count);6387mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));6388#ifndef COMPILE_ONLY6389file_mdump(m);6390@@ -1646,6 +1665,8 @@ mget(struct magic_set *ms, const unsigned char *s,6391break;63926393case FILE_INDIRECT:6394+ if (m->str_flags & INDIRECT_RELATIVE)6395+ offset += o;6396if (offset == 0)6397return 0;63986399@@ -1656,7 +1677,7 @@ mget(struct magic_set *ms, const unsigned char *s,6400return -1;64016402rv = file_softmagic(ms, s + offset, nbytes - offset,6403- recursion_level, BINTEST, text);6404+ indir_level + 1, name_count, BINTEST, text);64056406if ((ms->flags & MAGIC_DEBUG) != 0)6407fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);6408@@ -1691,13 +1712,13 @@ mget(struct magic_set *ms, const unsigned char *s,6409file_error(ms, 0, "cannot find entry `%s'", rbuf);6410return -1;6411}6412-6413+ (*name_count)++;6414oneed_separator = *need_separator;6415if (m->flag & NOSPACE)6416*need_separator = 0;6417rv = match(ms, ml.magic, ml.nmagic, s, nbytes, offset + o,6418- mode, text, flip, recursion_level, printed_something,6419- need_separator, returnval);6420+ mode, text, flip, indir_level, name_count,6421+ printed_something, need_separator, returnval);6422if (rv != 1)6423*need_separator = oneed_separator;6424return rv;6425@@ -1952,6 +1973,7 @@ magiccheck(struct magic_set *ms, struct magic *m)6426case FILE_REGEX: {6427int rc;6428file_regex_t rx;6429+ const char *search;64306431if (ms->search.s == NULL)6432return 0;6433@@ -1968,19 +1990,31 @@ magiccheck(struct magic_set *ms, struct magic *m)6434size_t slen = ms->search.s_len;6435#ifndef REG_STARTEND6436#define REG_STARTEND 06437- char c;6438- if (slen != 0)6439- slen--;6440- c = ms->search.s[slen];6441- ((char *)(intptr_t)ms->search.s)[slen] = '\0';6442+ char *copy;6443+ if (slen != 0) {6444+ copy = malloc(slen);6445+ if (copy == NULL) {6446+ file_error(ms, errno,6447+ "can't allocate %" SIZE_T_FORMAT "u bytes",6448+ slen);6449+ return -1;6450+ }6451+ memcpy(copy, ms->search.s, slen);6452+ copy[--slen] = '\0';6453+ search = copy;6454+ } else {6455+ search = ms->search.s;6456+ copy = NULL;6457+ }6458#else6459+ search = ms->search.s;6460pmatch[0].rm_so = 0;6461pmatch[0].rm_eo = slen;6462#endif6463- rc = file_regexec(&rx, (const char *)ms->search.s,6464+ rc = file_regexec(&rx, (const char *)search,64651, pmatch, REG_STARTEND);6466#if REG_STARTEND == 06467- ((char *)(intptr_t)ms->search.s)[l] = c;6468+ free(copy);6469#endif6470switch (rc) {6471case 0:6472Index: contrib/file/src/vasprintf.c6473===================================================================6474--- contrib/file/src/vasprintf.c (revision 284174)6475+++ contrib/file/src/vasprintf.c (working copy)6476@@ -108,7 +108,7 @@ you use strange formats.6477#include "file.h"64786479#ifndef lint6480-FILE_RCSID("@(#)$File: vasprintf.c,v 1.12 2014/05/14 23:09:21 christos Exp $")6481+FILE_RCSID("@(#)$File: vasprintf.c,v 1.13 2014/12/04 15:56:46 christos Exp $")6482#endif /* lint */64836484#include <assert.h>6485@@ -633,11 +633,15 @@ int vasprintf(char **ptr, const char *format_strin6486#ifdef va_copy6487va_copy (s.vargs, vargs);6488#else6489-#ifdef __va_copy6490+# ifdef __va_copy6491__va_copy (s.vargs, vargs);6492-#else6493+# else6494+# ifdef WIN326495+ s.vargs = vargs;6496+# else6497memcpy (&s.vargs, &vargs, sizeof (s.va_args));6498-#endif /* __va_copy */6499+# endif /* WIN32 */6500+# endif /* __va_copy */6501#endif /* va_copy */6502s.maxlen = (size_t)INT_MAX;65036504Index: lib/libmagic/config.h6505===================================================================6506--- lib/libmagic/config.h (revision 284174)6507+++ lib/libmagic/config.h (working copy)6508@@ -1,5 +1,13 @@6509/* $FreeBSD$ */65106511+/* Get __FreeBSD_version. */6512+#include <osreldate.h>6513+6514+/* Only specific versions of FreeBSD support xlocale */6515+#if __FreeBSD_version >= 1000002 || (__FreeBSD_version < 1000000 && __FreeBSD_version >= 900506)6516+#define FREEBSD_XLOCALE_SUPPORT 16517+#endif6518+6519/* config.h. Generated from config.h.in by configure. */6520/* config.h.in. Generated from configure.ac by autoheader. */65216522@@ -47,6 +55,11 @@6523/* Define to 1 if you have the `fork' function. */6524#define HAVE_FORK 165256526+/* Define to 1 if you have the `freelocale' function. */6527+#ifdef FREEBSD_XLOCALE_SUPPORT6528+#define HAVE_FREELOCALE 16529+#endif6530+6531/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */6532#define HAVE_FSEEKO 165336534@@ -98,9 +111,17 @@6535/* Define to 1 if you have a working `mmap' system call. */6536#define HAVE_MMAP 165376538+/* Define to 1 if you have the `newlocale' function. */6539+#ifdef FREEBSD_XLOCALE_SUPPORT6540+#define HAVE_NEWLOCALE 16541+#endif6542+6543/* Define to 1 if you have the `pread' function. */6544#define HAVE_PREAD 165456546+/* Define to 1 if you have the `setlocale' function. */6547+#define HAVE_SETLOCALE 16548+6549/* Define to 1 if you have the <stddef.h> header file. */6550#define HAVE_STDDEF_H 165516552@@ -185,6 +206,11 @@6553/* Define to 1 if you have the <unistd.h> header file. */6554#define HAVE_UNISTD_H 165556556+/* Define to 1 if you have the `uselocale' function. */6557+#ifdef FREEBSD_XLOCALE_SUPPORT6558+#define HAVE_USELOCALE 16559+#endif6560+6561/* Define to 1 if you have the `utime' function. */6562#define HAVE_UTIME 165636564@@ -222,6 +248,11 @@6565/* Define to 1 if `vfork' works. */6566#define HAVE_WORKING_VFORK 165676568+/* Define to 1 if you have the <xlocale.h> header file. */6569+#ifdef FREEBSD_XLOCALE_SUPPORT6570+#define HAVE_XLOCALE_H 16571+#endif6572+6573/* Define to 1 if you have the <zlib.h> header file. */6574#define HAVE_ZLIB_H 165756576@@ -247,7 +278,7 @@6577#define PACKAGE_NAME "file"65786579/* Define to the full name and version of this package. */6580-#define PACKAGE_STRING "file 5.19"6581+#define PACKAGE_STRING "file 5.22"65826583/* Define to the one symbol short name of this package. */6584#define PACKAGE_TARNAME "file"6585@@ -256,7 +287,7 @@6586#define PACKAGE_URL ""65876588/* Define to the version of this package. */6589-#define PACKAGE_VERSION "5.19"6590+#define PACKAGE_VERSION "5.22"65916592/* Define to 1 if you have the ANSI C header files. */6593#define STDC_HEADERS 16594@@ -287,7 +318,7 @@659565966597/* Version number of package */6598-#define VERSION "5.19"6599+#define VERSION "5.22"66006601/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most6602significant byte first (like Motorola and SPARC, unlike Intel). */660366046605