[File] display of negativ long OK, but wrong for short integer

Jörg Jenderek joerg.jen.der.ek at gmx.net
Tue Mar 9 16:20:03 UTC 2021


Hello.
some days ago wanted to change some magic lines for file command
version 5.39. I get an unexpected behaviour

To reproduce the behaviour i use a short simple file TEST89abcdef.bin
starting with 4 byte string TEST followed by 4 byte hexadecimal 89abcdef.

The magic file test-magic.txt consist of the following lines:
0	string		TEST	TEST FOUND
>4	lelong		x	\b, long 0x%8.8x
>4	lelong		<0	negative
>4	lelong		x	%i
>4	ulelong		x	unsigned %u
>6	leshort		x	\b, short 0x%4.4x
>6	leshort		<0	<0
>6	leshort		x	%i
>6	uleshort	x	unsigned %i

When running command `file -m test-magic.txt  TEST89abcdef.bin` i get
an output like:

TEST89abcdef.bin:
TEST FOUND,
long 0xefcdab89 negative -271733879 unsigned 4023233417,
short 0xefcd <0 61389 unsigned 61389

For long value efcdab89 in hexadecimal this value is shown correctly
as unsigned 4023233417 and as negative value -271733879.

When i do the same procedure for 2 byte short integer, the value
efcd in hexadecimal is shown correctly as 61389 as unsigned integer,
but the same is shown for signed variant instead of negative value
-16711.

I do not know if i am too stupid to understand the printf syntax or
if this is a bug in the program.

Thanks for advise and help.
Jörg Jenderek
--
Jörg Jenderek


More information about the File mailing list