PR/405: file -bizL git-2.1.3.tar.xz broke because the xz decompressor
authorChristos Zoulas <christos@zoulas.com>
Thu, 11 Dec 2014 11:47:08 +0000 (11:47 +0000)
committerChristos Zoulas <christos@zoulas.com>
Thu, 11 Dec 2014 11:47:08 +0000 (11:47 +0000)
dies with SIGPIPE when we stop reading from it early. ignore SIGPIPE>

src/compress.c

index 4a6f42e8caa1b326165e8aa00d731f16d8eac189..3330a2be3714e392538ed5cb271b76f4669be2c7 100644 (file)
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.75 2014/12/04 15:56:46 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.76 2014/12/11 11:47:08 christos Exp $")
 #endif
 
 #include "magic.h"
@@ -45,6 +45,7 @@ FILE_RCSID("@(#)$File: compress.c,v 1.75 2014/12/04 15:56:46 christos Exp $")
 #endif
 #include <string.h>
 #include <errno.h>
+#include <signal.h>
 #if !defined(__MINGW32__) && !defined(WIN32)
 #include <sys/ioctl.h>
 #endif
@@ -103,10 +104,12 @@ file_zmagic(struct magic_set *ms, int fd, const char *name,
        size_t i, nsz;
        int rv = 0;
        int mime = ms->flags & MAGIC_MIME;
+       sig_t osigpipe;
 
        if ((ms->flags & MAGIC_COMPRESS) == 0)
                return 0;
 
+       osigpipe = signal(SIGPIPE, SIG_IGN);
        for (i = 0; i < ncompr; i++) {
                if (nbytes < compr[i].maglen)
                        continue;
@@ -133,6 +136,7 @@ file_zmagic(struct magic_set *ms, int fd, const char *name,
                }
        }
 error:
+       (void)signal(SIGPIPE, osigpipe);
        free(newbuf);
        ms->flags |= MAGIC_COMPRESS;
        return rv;