Skip Menu |
 

This queue is for tickets about the Math-BigInt CPAN distribution.

Report information
The Basics
Id: 113310
Status: resolved
Priority: 0/
Queue: Math-BigInt

People
Owner: Nobody in particular
Requestors: craigberry [...] mac.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: OpenSSL test suite fails with Math::Bigint 1.999701
Date: Thu, 24 Mar 2016 12:00:34 -0500
To: bug-Math-Bigint [...] rt.cpan.org
From: "Craig A. Berry" <craigberry [...] mac.com>
Download (untitled) / with headers
text/plain 2.3k
The following program gives a different answer with Math::Bigint 1.999701 than it did with previous releases. The data and the operations on it are taken from the OpenSSL test suite, which succeeds when run with Perl 5.22.1, but (sometimes) fails when run with 5.23.x (any version since Math::Bigint 1.999701 was integrated into blead). It only fails sometimes because the data are generated using an RNG, and you don’t always get a data set that trips over this particular difference. When it does fail, there are dozens of failures, of which this is only one — let me know if more examples are of any use. I have not looked at the math here, just narrowed it down to the fact that something that used to give a result of 0x0 now gives a result of -0x1. $ cat testcase.pl use strict; use warnings; use Math::BigInt; my $operand1 = Math::BigInt->from_hex('-F7C3C3DADA0000FFA028FFFFFFFF4CFF737300000000003E3E'); my $operand2 = Math::BigInt->from_hex('4'); $operand1->bdiv($operand2); my $operand3 = Math::BigInt->from_hex('-3DF0F0F6B680003FE80A3FFFFFFFD33FDCDCC0000000000F8F'); $operand1->bsub($operand3); print $operand1->as_hex() . "\n"; exit ($operand1->as_hex() eq '0x0' ? 0 : 1); [end] I found this by using the above program to bisect blead and landing on: b4a10d33925c921a1cacc15a612f2afe75eb4492 is the first bad commit commit b4a10d33925c921a1cacc15a612f2afe75eb4492 Author: Peter John Acklam <pjacklam@online.no> Date: Tue Apr 14 15:20:14 2015 +0200 Correct bdiv() and bmod() in Math::BigInt and Math::BigFloat - The POD documentation, as well as the comments in the code, say that $x->bdiv($y) in list context should return quotient $q and remainder $r so that $x = $q * $y + $r, and that the remainder (modulo) $r should correspond to Perl's % operator as well as the bmod() method. This has not been the actual behaviour. This patch fixes this. - Clearer POD documentation for the bdiv() and bmod() methods. - Changed test files to match corrected behaviour. - Removed some duplicated tests. which upgraded blead to 1.999701 from 1.9997. The commit message talks only about changing behavior in list context, which I don’t see any of in the example I’ve provided. Show quoted text
________________________________________ Craig A. Berry mailto:craigberry@mac.com "... getting out of a sonnet is much more difficult than getting in." Brad Leithauser
Download (untitled) / with headers
text/plain 1009b
This was a bug that has now been fixed. It was one of countless cases where the code and documentation didn't match. The code did truncated division whereas the documentation said that floored division was used. I decided to change the code to match the documentation, rather than the other way around, to be consistent with core Perl, and so that division (/) and modulo (%) can be used together in a consistent way. With the new behaviour, the following is true for all finite x and finite and non-zero y: x = y * (x / y) + (x % y) The above was not always true with the old behaviour. Consider the simple case -5 / 4. -5 % 4 = 3 # core Perl and bmod() -5 / 4 = -1 # old behaviour of bdiv() -5 / 4 = -2 # new behaviour of bdiv() The only way the following can be true is if -5 / 4 = -2 -5 = 4 * (-5 / 4) + 3 For what it's worth, the new behaviour matches how integer division is done in Python $ python -c 'print(-5 / 4)' -2 $ python3 -c 'print(-5 // 4)' -2
Subject: Re: [rt.cpan.org #113310] OpenSSL test suite fails with Math::Bigint 1.999701
Date: Fri, 25 Mar 2016 10:28:09 -0500
To: bug-Math-BigInt [...] rt.cpan.org
From: "Craig A. Berry" <craigberry [...] mac.com>
Download (untitled) / with headers
text/plain 1.1k
OK, thanks. So if the new behavior is a correction, then presumably OpenSSL’s big number library needs the same correction or something needs clarification about whether it’s intentionally doing truncated division (the test that fails is a right shift test, so that may be the case). As far as I can tell, what they are doing is performing a series of calculations, printing out the result of each step, reversing the calculations with the expectation of a zero result, then reading in what’s been printed out and reproducing the reverse calculation using Math::BigInt. This based on a quick read of: <http://git.openssl.org/?p=openssl.git;a=blob;f=test/bntest.c;h=e58d94d1170e787ce94eb4b52a1759fef364c9f7;hb=HEAD#l1962> and <http://git.openssl.org/?p=openssl.git;a=blob;f=test/recipes/10-test_bn.t;h=7e728f4e16847b4eb487ab937dadbb0b2880d68c;hb=HEAD> I guess I will pass this along to openssl-dev and point to this ticket. OpenSSL 1.1.0 and Perl 5.24.0 are likely to be released around the same time in the next couple of months. Obviously it’s in no one’s interest to have random test failures that result from this particular combination.
Download (untitled) / with headers
text/plain 558b
On Fri Mar 25 11:28:31 2016, craigberry@mac.com wrote: Show quoted text
> I guess I will pass this along to openssl-dev and point to this > ticket. OpenSSL 1.1.0 and Perl 5.24.0 are likely to be released around > the same time in the next couple of months. Obviously it’s in no one’s > interest to have random test failures that result from this particular > combination.
I would very much appreciate it if you did pass this along to openssl-dev. I thought about implementing a btdiv() method that did truncated division, but I have given other changes higher priority.
Subject: Re: [rt.cpan.org #113310] OpenSSL test suite fails with Math::Bigint 1.999701
Date: Fri, 25 Mar 2016 16:01:35 -0500
To: bug-Math-BigInt [...] rt.cpan.org
From: "Craig A. Berry" <craigberry [...] mac.com>
Download (untitled) / with headers
text/plain 598b
Show quoted text
> On Mar 25, 2016, at 11:53 AM, Peter John Acklam via RT <bug-Math-BigInt@rt.cpan.org> wrote: > > I would very much appreciate it if you did pass this along to openssl-dev.
There is a ticket open there now: <http://rt.openssl.org/Ticket/Display.html?id=4485&user=guest&pass=guest> which shows up on the openssl-dev mailing list at: <https://mta.openssl.org/pipermail/openssl-dev/2016-March/006451.html> Show quoted text
________________________________________ Craig A. Berry mailto:craigberry@mac.com "... getting out of a sonnet is much more difficult than getting in." Brad Leithauser
This has been fixed by changing the OpenSSL test suite.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.