wfeldt / FirmwareUpdateKit

Create boot images for DOS-based firmware updates.
0 stars 0 forks source link

perl error: Cannot pack NaN with 'C' #3

Open jdelvare opened 2 months ago

jdelvare commented 2 months ago

FUK no longer works for me (openSUSE Leap 15.5). No matter what options I pass, I get the following error:

Use of uninitialized value in pattern match (m//) at /usr/lib/perl5/5.26.1/Math/BigInt.pm line 1516.
Use of uninitialized value in string eq at /usr/lib/perl5/5.26.1/Math/BigInt.pm line 1518.
Use of uninitialized value in pattern match (m//) at /usr/lib/perl5/5.26.1/Math/BigInt.pm line 1527.
Cannot pack NaN with 'C' at /usr/bin/fuk line 281.

I figured out that perl module Math-BigInt was missing on my system, after installing it, the first 3 errors went away (that would be fixed by adding the proper dependency to the openSUSE package) but the last error is still present and fatal.

This corresponds to the following piece of code:

      my $mbr = pack (
        "Z446CCCCCCCCVVZ48v",
        $self->{mbr},                 # boot code, if any
        0x80,                         # bootflag                       <-- line 281
        $h_0,                         # head start
        (($c_0 >> 8) << 6) + $s_0,    # cyl/sector start, low
        $c_0 & 0xff,                  # cyl/sector start, hi
        $type,                        # partition type
        $h_1,                         # head last
        (($c_1 >> 8) << 6) + $s_1,    # cyl/sector last, low
        $c_1 & 0xff,                  # cyl/sector last, hi
        $p_0,                         # partition offset
        $p_1,                         # partition size
        "", 0xaa55
      );

0x80 looks like a very valid number to me, so I do not understand the error message and have now idea how to fix it.

jdelvare commented 1 month ago

I investigated this further. The error message was misleading, the problem is not actually with line 281 but a few lines later, and is caused by $c_0 not being an integer. The computations lead to $c_0 = 0.25, which isn't a value perl is willing to perform bit-wise operations on.

I must say I still do not understand how this can possibly happen, as this piece of code is within use bigint; scope, so all computations should lead to integer results. For testing purposes, I replaced that statement with use integer; and it fixed the problem.

So this might be a bug in perl rather than FUK.