From: Christos Zoulas Date: Wed, 26 Jun 2019 20:31:31 +0000 (+0000) Subject: Limit the CSV test to text files and say so... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ea7485b69eb7fb7290744eda7bccb68fc06d6b4a;p=file Limit the CSV test to text files and say so... --- diff --git a/src/file.h b/src/file.h index e3c88569..947f2089 100644 --- a/src/file.h +++ b/src/file.h @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$File: file.h,v 1.207 2019/06/08 22:16:24 christos Exp $ + * @(#)$File: file.h,v 1.208 2019/06/26 20:31:31 christos Exp $ */ #ifndef __file_h__ @@ -479,7 +479,7 @@ protected int file_ascmagic_with_encoding(struct magic_set *, protected int file_encoding(struct magic_set *, const struct buffer *, unichar **, size_t *, const char **, const char **, const char **); protected int file_is_json(struct magic_set *, const struct buffer *); -protected int file_is_csv(struct magic_set *, const struct buffer *); +protected int file_is_csv(struct magic_set *, const struct buffer *, int); protected int file_is_tar(struct magic_set *, const struct buffer *); protected int file_softmagic(struct magic_set *, const struct buffer *, uint16_t *, uint16_t *, int, int); diff --git a/src/funcs.c b/src/funcs.c index 33df4194..069e4d04 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.105 2019/06/08 22:16:24 christos Exp $") +FILE_RCSID("@(#)$File: funcs.c,v 1.106 2019/06/26 20:31:31 christos Exp $") #endif /* lint */ #include "magic.h" @@ -285,7 +285,7 @@ file_buffer(struct magic_set *ms, int fd, struct stat *st, /* Check if we have a CSV file */ if ((ms->flags & MAGIC_NO_CHECK_CSV) == 0) { - m = file_is_csv(ms, &b); + m = file_is_csv(ms, &b, looks_text); if ((ms->flags & MAGIC_DEBUG) != 0) (void)fprintf(stderr, "[try csv %d]\n", m); if (m) { diff --git a/src/is_csv.c b/src/is_csv.c index 961975d9..0081088c 100644 --- a/src/is_csv.c +++ b/src/is_csv.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: is_csv.c,v 1.3 2019/06/24 23:40:03 christos Exp $") +FILE_RCSID("@(#)$File: is_csv.c,v 1.4 2019/06/26 20:31:31 christos Exp $") #endif #include @@ -131,12 +131,14 @@ csv_parse(const unsigned char *uc, const unsigned char *ue) #ifndef TEST int -file_is_csv(struct magic_set *ms, const struct buffer *b) +file_is_csv(struct magic_set *ms, const struct buffer *b, int looks_text) { const unsigned char *uc = CAST(const unsigned char *, b->fbuf); const unsigned char *ue = uc + b->flen; int mime = ms->flags & MAGIC_MIME; + if (!looks_text) + return 0; if ((ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION)) != 0) return 0; @@ -153,7 +155,7 @@ file_is_csv(struct magic_set *ms, const struct buffer *b) return 1; } - if (file_printf(ms, "CSV data") == -1) + if (file_printf(ms, "CSV text") == -1) return -1; return 1;