Hello,

could you try with a recent snapshot from https://gmplib.org/download/snapshot/ ?

If you built GMP yourself, did you run `make check` afterwards?


On Thu, 8 Jun 2023, Philip Riebold wrote:

Hi,


I think I may have come across an error in mpz_probab_prime_p() It seems to

occasionally cause a segmentation fault either when repeatedly run with the

same arguments or with increasing values of the first argument.


I initially came across the bug when I was trying to find the closest primes

10^n, 2*10^n or 5*10^n when the program would crash after listing the
first

few dozen/hundred results.


The platform is a 16GB M2 Mac Air.


The test program below, pt3.c is the simplest I could produce to demonstrate

the problem.


The first argument 20000000000000000011 is the smallest value I found which

caused the error.


When I ran pt3 100 times the for() loop executed between 4 and 4684 times

before crashing.


GMP version 6.2.1

=====================

Philip:gmp_error philip$ cat pt3.c

#include <stdio.h>

#include <string.h>

#include <gmp.h>


int main(void)

{

   setbuf(stdout,NULL);

   mpz_t test;


   for(int n = 1; n <= 1000; n++) {

       printf("%4d\n", n);

       mpz_init(test);

       mpz_set_str(test, "20000000000000000011", 10);

       int res = mpz_probab_prime_p(test, 100);

       mpz_clear(test);

       if(res != 1)

           printf("res = %d\n", res);

   }

   printf("hmmm, it hasn't failed\n");

}

Philip:gmp_error philip$

=====================

Philip:gmp_error philip$ cc -v

Apple clang version 14.0.3 (clang-1403.0.22.14.1)

Target: arm64-apple-darwin22.5.0

Thread model: posix

InstalledDir:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Philip:gmp_error philip$

=====================

Philip:gmp_error philip$ uname -a

Darwin Philip 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:43 PDT
2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T8112 arm64

Philip:gmp_error philip$

=====================

Philip:gmp-6.2.1 philip$ ./config.guess

aarch64-apple-darwin22.5.0

Philip:gmp-6.2.1 philip$

=====================

Philip:gmp-6.2.1 philip$ ./configfsf.guess

aarch64-apple-darwin22.5.0

Philip:gmp-6.2.1 philip$

=====================

Philip:gmp_error philip$ cc -o pt3 pt3.c -lgmp

Philip:gmp_error philip$ ./pt3

  1

  2

  3

  4

  ⋮

143

144

145

146

Segmentation fault: 11

Philip:gmp_error philip$

=====================


If there's anything I can do to help please ask.


TTFN

Philip Riebold


--
Marc Glisse
_______________________________________________
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs

Reply via email to