Subject: | File::MimeInfo::Magic host16 and host32 on non-bigendian hardware |
Date: | Wed, 01 Aug 2007 16:21:06 -0400 |
To: | bug-File-MimeInfo [...] rt.cpan.org |
From: | Chapman Flack <jflack [...] math.purdue.edu> |
Re: this comment in Magic.pm
# the word size is given for big endian to little endian conversion
# dunno whether we need to do that in perl
the answer is yes. :) I suggest replacing that comment with this code:
if ( $w > 1 ) {
my ( $utpl, $ptpl );
if ( 2 == $w ) {
( $utpl, $ptpl ) = ( 'n', 'S' );
}
elsif ( 4 == $w ) {
( $utpl, $ptpl ) = ( 'N', 'L' );
}
else {
die "Unsupported word size: $w octets";
}
$v = pack $ptpl, unpack $utpl, $v;
$m = pack $ptpl, unpack $utpl, $m if defined $m;
}
Note that bigendian and littleendian are not the only two choices
(see the doc for byteorder in the perl Config module); there are
also "weird-endian" machines. You want the proper conversion to
any machine's native order; the above code will do that.
Note also that the freedesktop database currently contains a
couple of known bugs
(https://bugs.freedesktop.org/show_bug.cgi?id=10334)
that are masked by this bug (things incorrectly marked host-order
in the database, that happen to work now because this code is
ignoring host-order anyway). You might want to wait to fix this
bug until after bug 10334 gets fixed in the database, to avoid
breaking recognition of java classes and jar-chives on non-
bigendian hardware. (However, there are other types in the
database that are correctly marked host-order, and this bug
already is breaking them.)
Chapman Flack
mathematics
Purdue