From: Reuben Thomas Date: Sun, 21 Jul 2013 21:06:41 +0000 (+0000) Subject: Prevent bogus extra encoding output. X-Git-Tag: FILE5_15~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc23593b5924937fccc80dabdd7d8ae5c1f06008;p=file Prevent bogus extra encoding output. --- diff --git a/src/compress.c b/src/compress.c index 22960808..c30bfcdc 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.69 2012/08/26 10:21:37 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.70 2012/11/07 17:54:48 christos Exp $") #endif #include "magic.h" @@ -121,14 +121,12 @@ file_zmagic(struct magic_set *ms, int fd, const char *name, if (file_printf(ms, mime ? " compressed-encoding=" : " (") == -1) goto error; + if (file_buffer(ms, -1, NULL, buf, nbytes) == -1) + goto error; + if (!mime && file_printf(ms, ")") == -1) + goto error; } - if ((mime == 0 || mime & MAGIC_MIME_ENCODING) && - file_buffer(ms, -1, NULL, buf, nbytes) == -1) - goto error; - - if (!mime && file_printf(ms, ")") == -1) - goto error; rv = 1; break; } diff --git a/src/funcs.c b/src/funcs.c index f11e94de..ff55b79c 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: funcs.c,v 1.60 2011/12/08 12:38:24 rrt Exp $") +FILE_RCSID("@(#)$File: funcs.c,v 1.61 2012/10/30 23:11:51 christos Exp $") #endif /* lint */ #include "magic.h" @@ -207,7 +207,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu if ((m = file_zmagic(ms, fd, inname, ubuf, nb)) != 0) { if ((ms->flags & MAGIC_DEBUG) != 0) (void)fprintf(stderr, "zmagic %d\n", m); - goto done; + goto done_encoding; } #endif /* Check if we have a tar file */ @@ -290,6 +290,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu if (file_printf(ms, "%s", code_mime) == -1) rv = -1; } + done_encoding: free(u8buf); if (rv) return rv;