[File] Problem with LESHORT casting

Christos Zoulas christos at zoulas.com
Tue May 31 15:12:52 UTC 2022


On 2022-05-31 9:25 am, Greg Wildman wrote:
> Hello,
> 
> After upgrading from 5.39 to 5.40 I noticed a problem with the printing
> of unsigned shorts. I can "fix" the problem by using uleshort instead
> of leshort.
> 
> I created a test file with matching magic file.
> 
> echo -ne "TEST\xff\xff\x00\x80\xff\x7f^C> /tmp/test.bin
> 
> /tmp/magic
> -----------
> # TEST
> 0       string  TEST            Test File
>> 4      leshort x               \b, %u
>> 4      uleshort x              \b, %u
>> 6      leshort x               \b, %u
>> 6      uleshort x              \b, %u
>> 8      leshort x               \b, %u
>> 8      uleshort x              \b, %u
> 
> 
> with version 5.39
> 
> [dev at defender ~]# file -m /tmp/magic /tmp/test.bin
> /tmp/test.bin: Test File, 65535, 65535, 32768, 32768, 32767, 32767
> 
> with version 5.40 and 5.41
> 
> [dev at defender ~]# file -m /tmp/magic /tmp/test.bin
> /tmp/test.bin: Test File, 4294967295, 65535, 4294934528, 32768, 32767,
> 32767
> 
> I think it has something to do with the following commit but that is a
> guess on my part :)

Yes, 5.39 was incorrect. Now file has been changed to behave like 
regular c
code does:

#include <stdio.h>

int
main(void)
{
         short s = 65535;
         printf("%u\n", s);
         return 0;
}

Best,

christos


More information about the File mailing list