]> granicus.if.org Git - file/commitdiff
Allow extension and apple magic to go further in ascmagic so that search
authorChristos Zoulas <christos@zoulas.com>
Tue, 3 May 2016 16:10:37 +0000 (16:10 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 3 May 2016 16:10:37 +0000 (16:10 +0000)
magic gets a chance to do the binary tests.

src/ascmagic.c

index b9ab78953113dafe14738c1a905fd62f85b2a493..baa95aba2df52298451bbad556e5d5c30da11b4b 100644 (file)
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.94 2016/03/31 17:51:12 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.95 2016/05/03 16:10:37 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -79,9 +79,6 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
        const char *code_mime = NULL;
        const char *type = NULL;
 
-       if (ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION))
-               return 0;
-
        nbytes = trim_nuls(buf, nbytes);
 
        /* If file doesn't look like any sort of text, give up. */
@@ -123,9 +120,6 @@ file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
        size_t last_line_end = (size_t)-1;
        int has_long_lines = 0;
 
-       if (ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION))
-               return 0;
-
        nbytes = trim_nuls(buf, nbytes);
 
        /* If we have fewer than 2 bytes, give up. */
@@ -150,7 +144,11 @@ file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
                    (size_t)(utf8_end - utf8_buf), NULL, NULL,
                    TEXTTEST, text)) == 0)
                        rv = -1;
+               if ((ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION)))
+                       return rv == -1 ? 0 : 1;
        }
+       if ((ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION)))
+               return 0;
 
        /* Now try to discover other details about the file. */
        for (i = 0; i < ulen; i++) {