Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#8423 closed Bugs (worksforme)

miller_rabin_test core dump

Reported by: robbieye@… Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.53.0 Severity: Problem
Keywords: miller rabin primality Cc:

Description

When running the following code in Ubuntu 12.04 (gcc 4.6) with Boost 1.53.0, the program had a core-dump in miller_rabin_test().

The program was doing primality test on 2(25) + 1 when it crashed. Values such as 2(24) + 1 or 2(26) + 1 do not cause such problems.

Thanks in advance for looking into it.

-Rob


#include <iostream>

#include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/miller_rabin.hpp> #include <boost/multiprecision/random.hpp>

namespace mp = boost::multiprecision;

typedef mp::cpp_int BIGNUM;

int main(int argc, char* argv[]) {

Test primality of 2(25) + 1 BIGNUM num = (BIGNUM(1) << (1u << 5)) + 1; boost::random::mt19937 prng(clock());

std::cout << "Running primality test for : " << num; bool isPrime = mp::miller_rabin_test(num, 25, prng);

std::cout << ", result : "

<< (isPrime ? "" : "not ") << "prime." << std::endl;

return 0;

}

Change History (3)

comment:1 by anonymous, 10 years ago

Here's the properly formatted code. Please ignore the malformed snippet above.

#include <iostream>

#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/miller_rabin.hpp>
#include <boost/multiprecision/random.hpp>

namespace mp = boost::multiprecision;

typedef mp::cpp_int BIGNUM;

int
main(int argc, char* argv[])
{
    // Test primality for 2^(2^5) + 1
    BIGNUM num = (BIGNUM(1) << (1u << 5)) + 1;
    boost::random::mt19937 prng(clock());

    std::cout << "Running primality test for : " << num; 
    bool isPrime = mp::miller_rabin_test(num, 25, prng);

    std::cout << ", result : "
	      << (isPrime ? "" : "not ")
	      << "prime."
	      << std::endl;

    return 0;
}

comment:2 by John Maddock, 10 years ago

Resolution: worksforme
Status: newclosed

Confirmed the issue was in 1.53, also that it's already been fixed for the next release.

comment:3 by stephan@…, 8 years ago

On my 64-bit machine, it crashed for 2(26)+1. I can confirm it's fixed in 1.54. Thanks for documenting the issue (saved me some time) and for fixing it!

Note: See TracTickets for help on using tickets.