[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Binary recognition is to narrow.
From: |
Hideki IWAMOTO |
Subject: |
Re: Binary recognition is to narrow. |
Date: |
Thu, 19 Nov 2009 21:40:12 +0900 |
Hi.
> if (((float)strange)/size > 0.3f)
When an empty file is tested on old systems, SIGFPE may occur here.
The calculation of 0.0/0.0 should be avoided for portability.
On Wed, 18 Nov 2009 17:46:01 +0100 (CET), Erik Jonsson wrote...
> Hi all,
>
> The function is_binary is a bit naive and therefore tags to much as binary
> content. It is quite common with names in the first 32 bytes and it's also
> common with strange characters in names. Strange as in char > 127.
>
> I have rewritten the function a bit and think you probably should
> incorporate this fix or one of your own in a future release.
>
> Here is my version...
>
> static int
> is_binary(const char *path)
> {
> int ip;
> char buf[32];
> int i, c, size;
> int strange = 0;
>
> ip = open(path, O_RDONLY);
> if (ip < 0)
> die("cannot open file '%s' in read mode.", path);
> size = read(ip, buf, sizeof(buf));
> close(ip);
> if (size < 0)
> return 1;
> if (size >= 7 && locatestring(buf, "!<arch>", MATCH_AT_FIRST))
> return 1;
> for (i = 0; i < size; i++) {
> c = (unsigned char)buf[i];
> if (c <= 8)
> return 1;
> if (c >= 14 && c < 32)
> return 1;
> if (c > 128)
> strange++;
>
> }
> if (((float)strange)/size > 0.3f)
> return 1;
>
> return 0;
> }
>
>
>
>
> _______________________________________________
> Bug-global mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-global
----
Hideki IWAMOTO address@hidden
Re: Binary recognition is to narrow.,
Hideki IWAMOTO <=