Package: file
Version: 4.12-1
Severity: important
Tags: patch

I'm used to find file types of pipes, either using the output of zcat
or passing whole filesystems to stdin of file.

Since I upgraded to sarge, file tries to read the whole of stdin and
save it to a temporary file, forcing me to cut data adding a dd in the
pipe.

When inspecting the code, I found file reads the whole of the pipe
(file_pipe2file) in order to dissect ELF files, but it does it even
when the file is known not to be ELF.

By simply moving the check for ELFMAG[0123] before calling pipe2file
I recover the old behavior I loved, without loss in functionality.

Disclaimer: yes I found "-s", but it's asymettric: stdin always works.
Moreover, -s doesn't fix the problem with "bzcat <bigfile> | file -".


--- file-4.12/src/readelf.c     2004-11-24 18:38:24.000000000 +0100
+++ file-4.12-fixpipe/src/readelf.c     2005-12-28 21:55:09.000000000 +0100
@@ -751,22 +751,24 @@
        int class;
        int swap;
 
-       /*
-        * If we cannot seek, it must be a pipe, socket or fifo.
-        */
-       if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
-               fd = file_pipe2file(ms, fd, buf, nbytes);
+       /* Return if it's not ELF (so we avoid pipe2file unless needed) */
+       if (buf[EI_MAG0] != ELFMAG0
+           || (buf[EI_MAG1] != ELFMAG1 && buf[EI_MAG1] != OLFMAG1)
+           || buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3)
+           return 0;
 
        /*
         * ELF executables have multiple section headers in arbitrary
         * file locations and thus file(1) cannot determine it from easily.
         * Instead we traverse thru all section headers until a symbol table
-        * one is found or else the binary is stripped.
+        * one is found or else the binary is stripped. So whole file is needed
         */
-       if (buf[EI_MAG0] != ELFMAG0
-           || (buf[EI_MAG1] != ELFMAG1 && buf[EI_MAG1] != OLFMAG1)
-           || buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3)
-           return 0;
+
+       /*
+        * If we cannot seek, it must be a pipe, socket or fifo.
+        */
+       if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
+               fd = file_pipe2file(ms, fd, buf, nbytes);
 
 
        class = buf[4];


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to