[Issue 16264] BigInt multiplication crashes on 64-bit (biguintnoasm.d(276): Range violation)

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jul 11 20:36:18 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16264

--- Comment #4 from Kirill Kryukov <kkryukov at gmail.com> ---
Actually I've no idea why the 32-bit compile works with my initial test. If I
add the following unittest into biguintcore.d, and compile in 32-bit (dmd.exe
-main -unittest biguintcore.d), it crashes too.

unittest
{
    BigUint a, b;

    a.fromDecimalString(
`207672245542926038535480439528441949928508406405023044025560363701392340829` ~
`852529131306106648201340460604257466180580583656068555417076345439694125326` ~
`843947164365500055567495554645796102453565953360564114634705366335703491527` ~
`429426780005741168078089657359833601261803592920462081364401456331489106355` ~
`199133982282631108670436696758342051198891939367812305559960349479160308314` ~
`068518200681530999860641597181672463704794566473241690395901768680673716414` ~
`243691584391572899147223065906633310537507956952626106509069491302359792769` ~
`378934570685117202046921464019396759638376362935855896435623442486036961070` ~
`534574698959398017332214518246531363445309522357827985468581166065335726996` ~
`711467464306784543112544076165391268106101754253962102479935962248302404638` ~
`21737237102628470475027851189594709504`);

    b.fromDecimalString(
`335690982744637013564796917901053301979460129353374296317539383938630086938` ~
`465898213033510992292836631752875403891802201862860531801760096359705447768` ~
`957432600293361240407059207520920532482429912948952142341440301429494694368` ~
`264560802292927144211230021750155988283029753927847924288850436812178022006` ~
`408597793414273953252832688620479083497367463977081627995406363446761896298` ~
`967177607401918269561385622811274398143647535024987050366350585544531063531` ~
`7118554808325723941557169427279911052268935775`);

    BigDigit[] cdata = new BigDigit[a.uintLength() + b.uintLength()];

    mulInternal(cdata, a.data, b.data);  // Crashes
}

Also, this test is a bit further reduction.

Note that the crash disappears if you change the operand sizes (by adding or
removing a few lines in either a or b), so it's specific to particular length
of the operands.

The crash message is now more specific: 

"core.exception.AssertError at m\biguintcore.d(1190): Bigint Internal Error:
Asymmetric Karatsuba"

So I think it's related to how mulInternal divides the operands before calling
mulKaratsuba.

However, this bug is now probably applies to both 32-bit and 64-bit!

This blocks D's BigUint (and be extension BigInt) use in any non-toy
calculation.

--


More information about the Digitalmars-d-bugs mailing list