The issue is LC_CTYPE related. file tries to print a name field
identified within the file but do no specify a suitable source character
ncoding making libc vasprintf barf on invalid UTF-8 encoding.
$ LC_CTYPE=C file testfile
testfile: DOS executable (device driver), name: \276kM
$ LC_CTYPE=en_US.UTF-8 file testfile
testfile: ERROR: DOS executable (device driver)vasprintf failed
(Invalid or incomplete multibyte or wide character)
The culpit is vasprintf which fails to print %.8s with garbage data in
UTF-8 locale. Not sure why it ends up handling that as multibyte at all
(it's not %ls) but probably related to the size specifier.
Sample test program triggering the issue when run in UTF-8 locale:
-- testprintf.c --
#include <locale.h>
#include <stdio.h>
int main(int argc, char **argv)
{
char name[] = { 0xBE, 0xF3, 0x6B, 0x4D, 0x00, 0x00, 0x00, 0x00 };
char *buf = NULL;
int len;
setlocale(LC_ALL, "");
len = asprintf(&buf, "%%s: %s\n", name);
if (len >= 0)
write(1, buf, len);
else
perror("vasprintf");
len = asprintf(&buf, "%%.8s: %.8s\n", name);
if (len >= 0)
write(1, buf, len);
else
perror("vasprintf");
}
-- end --
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]