From bda61b688a61c93ce03f0fb8bf0d17258ea40d33 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Wed, 3 Jun 2015 18:21:24 +0000 Subject: [PATCH] PR/455: Add feature to report only on contents of compressed data, not the compression itself. --- ChangeLog | 6 ++++++ doc/file.man | 9 ++++++--- doc/libmagic.man | 6 ++++-- src/compress.c | 5 +++-- src/file.c | 12 ++++++++---- src/file_opts.h | 1 + src/magic.h.in | 4 +++- 7 files changed, 31 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index d0bb6608c9..5cd5c204d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ + +2015-06-03 14:30 Christos Zoulas + + * 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 * handle MAGIC_CONTINUE everywhere, not just in softmagic diff --git a/doc/file.man b/doc/file.man index f6db6cf866..69b9a80d86 100644 --- a/doc/file.man +++ b/doc/file.man @@ -1,5 +1,5 @@ -.\" $File: file.man,v 1.114 2015/04/10 15:36:01 christos Exp $ -.Dd May 29, 2015 +.\" $File: file.man,v 1.115 2015/05/29 14:27:31 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 diff --git a/doc/libmagic.man b/doc/libmagic.man index eccb1a9774..a5c8e2e177 100644 --- a/doc/libmagic.man +++ b/doc/libmagic.man @@ -1,4 +1,4 @@ -.\" $File: libmagic.man,v 1.35 2015/04/09 20:01:40 christos Exp $ +.\" $File: libmagic.man,v 1.36 2015/04/10 15:36:01 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 diff --git a/src/compress.c b/src/compress.c index 5eda5403e2..faba644267 100644 --- a/src/compress.c +++ b/src/compress.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.78 2015/01/02 21:29:39 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.79 2015/03/27 17:35:39 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; diff --git a/src/file.c b/src/file.c index fbbf0ccefa..f60dde0df1 100644 --- a/src/file.c +++ b/src/file.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: file.c,v 1.162 2015/02/09 20:15:50 christos Exp $") +FILE_RCSID("@(#)$File: file.c,v 1.163 2015/04/09 20:01:41 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; diff --git a/src/file_opts.h b/src/file_opts.h index 317cb328ba..036505fe1d 100644 --- a/src/file_opts.h +++ b/src/file_opts.h @@ -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" diff --git a/src/magic.h.in b/src/magic.h.in index ba7884cbe7..500bdbdd13 100644 --- a/src/magic.h.in +++ b/src/magic.h.in @@ -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 */