]> granicus.if.org Git - file/commitdiff
PR/455: Add feature to report only on contents of compressed data, not the
authorChristos Zoulas <christos@zoulas.com>
Wed, 3 Jun 2015 18:21:24 +0000 (18:21 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 3 Jun 2015 18:21:24 +0000 (18:21 +0000)
compression itself.

ChangeLog
doc/file.man
doc/libmagic.man
src/compress.c
src/file.c
src/file_opts.h
src/magic.h.in

index d0bb6608c9bcf3359b53adb549f39cccc9b279a1..5cd5c204d783059e6df3c8b16d5c05e343d0ad20 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+
+2015-06-03  14:30  Christos Zoulas <christos@zoulas.com>
+
+       * PR/455: Implement -Z, look inside, but don't report on compression
+       * PR/454: Fix allocation error on bad magic.
+
 2015-05-29  10:30  Christos Zoulas <christos@zoulas.com>
 
        * handle MAGIC_CONTINUE everywhere, not just in softmagic
index bba4bc487151973410086cf2dbeb112c8f10c7b6..3f0344ea33e416d4cf3b3603de7217840c284866 100644 (file)
@@ -1,5 +1,5 @@
-.\" $File: file.man,v 1.115 2015/05/29 14:27:31 christos Exp $
-.Dd May 29, 2015
+.\" $File: file.man,v 1.116 2015/06/03 18:21:24 christos Exp $
+.Dd June 3, 2015
 .Dt FILE __CSECTION__
 .Os
 .Sh NAME
@@ -8,7 +8,7 @@
 .Sh SYNOPSIS
 .Nm
 .Bk -words
-.Op Fl bcEhiklLNnprsvz0
+.Op Fl bcEhiklLNnprsvzZ0
 .Op Fl Fl apple
 .Op Fl Fl extension
 .Op Fl Fl mime-encoding
@@ -346,6 +346,9 @@ since on some systems it reports a zero size for raw disk partitions.
 Print the version of the program and exit.
 .It Fl z , Fl Fl uncompress
 Try to look inside compressed files.
+.It Fl Z , Fl Fl uncompress-noreport
+Try to look inside compressed files, but report information about the contents
+only not the compression.
 .It Fl 0 , Fl Fl print0
 Output a null character
 .Sq \e0
index 4f3ef5cb41267e2f153c9f46addf736be80e09f4..64170a31b2ed959d688426a2538a54a5b0905910 100644 (file)
@@ -1,4 +1,4 @@
-.\" $File: libmagic.man,v 1.36 2015/04/10 15:36:01 christos Exp $
+.\" $File: libmagic.man,v 1.37 2015/06/03 18:21:24 christos Exp $
 .\"
 .\" Copyright (c) Christos Zoulas 2003.
 .\" All Rights Reserved.
@@ -25,7 +25,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd April 9, 2015
+.Dd June 3, 2015
 .Dt LIBMAGIC 3
 .Os
 .Sh NAME
@@ -134,6 +134,8 @@ as real errors, instead of printing them in the magic buffer.
 Return the Apple creator and type.
 .It Dv MAGIC_EXTENSION
 Return a slash-separated list of extensions for this file type.
+.It Dv MAGIC_COMPRESS_TRANSP
+Don't report on compression, only report about the uncompressed data.
 .It Dv MAGIC_NO_CHECK_APPTYPE
 Don't check for
 .Dv EMX
index 593ad63074de76f5e431510b0679508d023de5a6..539031e3490b67e67e938dec128dc814c4892317 100644 (file)
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.79 2015/03/27 17:35:39 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.80 2015/06/03 18:21:24 christos Exp $")
 #endif
 
 #include "magic.h"
@@ -130,7 +130,8 @@ file_zmagic(struct magic_set *ms, int fd, const char *name,
                        if (file_buffer(ms, -1, name, newbuf, nsz) == -1)
                                goto error;
 
-                       if (mime == MAGIC_MIME || mime == 0) {
+                       if ((ms->flags & MAGIC_COMPRESS_TRANSP) == 0 &&
+                           (mime == MAGIC_MIME || mime == 0)) {
                                if (file_printf(ms, mime ?
                                    " compressed-encoding=" : " (") == -1)
                                        goto error;
index 45202a0daf4861bc1345a9b64221495f7fa280c4..2b15e21232d1afde6c3f11208f93f4b67ed78390 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: file.c,v 1.163 2015/04/09 20:01:41 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.164 2015/06/03 18:21:24 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -68,9 +68,9 @@ int getopt_long(int argc, char * const *argv, const char *optstring, const struc
 #endif
 
 #ifdef S_IFLNK
-#define FILE_FLAGS "-bcEhikLlNnprsvz0"
+#define FILE_FLAGS "-bcEhikLlNnprsvzZ0"
 #else
-#define FILE_FLAGS "-bcEiklNnprsvz0"
+#define FILE_FLAGS "-bcEiklNnprsvzZ0"
 #endif
 
 # define USAGE  \
@@ -98,7 +98,7 @@ private const struct option long_options[] = {
 #undef OPT_LONGONLY
     {0, 0, NULL, 0}
 };
-#define OPTSTRING      "bcCde:Ef:F:hiklLm:nNpP:rsvz0"
+#define OPTSTRING      "bcCde:Ef:F:hiklLm:nNpP:rsvzZ0"
 
 private const struct {
        const char *name;
@@ -284,6 +284,10 @@ main(int argc, char *argv[])
                case 'z':
                        flags |= MAGIC_COMPRESS;
                        break;
+
+               case 'Z':
+                       flags |= MAGIC_COMPRESS|MAGIC_COMPRESS_TRANSP;
+                       break;
 #ifdef S_IFLNK
                case 'L':
                        flags |= MAGIC_SYMLINK;
index 317cb328ba9d0a59ead9308d00c95ca71ff38fc8..036505fe1dd5c04da03d37866a1cf304b42ee1bd 100644 (file)
@@ -17,6 +17,7 @@ OPT('v', "version", 0, "              output version information and exit\n")
 OPT('m', "magic-file", 1, " LIST      use LIST as a colon-separated list of magic\n"
     "                               number files\n")
 OPT('z', "uncompress", 0, "           try to look inside compressed files\n")
+OPT('Z', "uncompress-noreport", 0, "  only print the contents of compressed files\n")
 OPT('b', "brief", 0, "                do not prepend filenames to output lines\n")
 OPT('c', "checking-printout", 0, "    print the parsed form of the magic file, use in\n"
     "                               conjunction with -m to debug a new magic file\n"
index ba7884cbe7f9d3da4fd741ed2ac9fa6c302c3f90..500bdbdd13804e20765bad5514ce931dd8c3170b 100644 (file)
@@ -44,7 +44,9 @@
 #define MAGIC_MIME             (MAGIC_MIME_TYPE|MAGIC_MIME_ENCODING)
 #define        MAGIC_APPLE             0x0000800 /* Return the Apple creator/type */
 #define        MAGIC_EXTENSION         0x1000000 /* Return a /-separated list of
-                                          * extensions  */
+                                          * extensions */
+#define MAGIC_COMPRESS_TRANSP  0x2000000 /* Check inside compressed files
+                                          * but not report compression */
 #define MAGIC_NODESC           (MAGIC_EXTENSION|MAGIC_MIME|MAGIC_APPLE)
 
 #define        MAGIC_NO_CHECK_COMPRESS 0x0001000 /* Don't check for compressed files */