Skip to content

Commit

Permalink
PR/455: Add feature to report only on contents of compressed data, no…
Browse files Browse the repository at this point in the history
…t the

compression itself.
  • Loading branch information
zoulasc committed Jun 3, 2015
1 parent 6713ca4 commit bda61b6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
6 changes: 6 additions & 0 deletions 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
Expand Down
9 changes: 6 additions & 3 deletions 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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions 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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/compress.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions src/file.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/file_opts.h
Expand Up @@ -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")

This comment has been minimized.

Copy link
@juikim

juikim Jun 11, 2015

This broke long options, i.e., --apple, --extension, --mime-type, and --mime-encoding are now 11, 12, 13, and 14 respectively.

--- src/file.c
+++ src/file.c
@@ -187,16 +187,16 @@ main(int argc, char *argv[])
                        case 0:
                                help();
                                break;
-                       case 10:
+                       case 11:
                                flags |= MAGIC_APPLE;
                                break;
-                       case 11:
+                       case 12:
                                flags |= MAGIC_EXTENSION;
                                break;
-                       case 12:
+                       case 13:
                                flags |= MAGIC_MIME_TYPE;
                                break;
-                       case 13:
+                       case 14:
                                flags |= MAGIC_MIME_ENCODING;
                                break;
                        }
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"
Expand Down
4 changes: 3 additions & 1 deletion src/magic.h.in
Expand Up @@ -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 */
Expand Down

0 comments on commit bda61b6

Please sign in to comment.