Segmentation fault in mpz_ui_pow_ui

In the Parma Polyhedron Library, using GMP 4.1.4, calls to mpz_ui_pow_ui with large exponents are resulting in segmentation faults.
Below is a small test program which reproduces the fault.
/* gmp-pow.c -- test mpz_ui_pow_ui */
#include <stdio.h> #include <stdlib.h> #include <gmp.h>
int main () { // FIX 2.95 gmp-pow.c:13: parse error before `z' //printf ("GMP (version %s) mpz_ui_pow_ui test:\n\n", gmp_version);
mpz_t z; mpz_init (z);
#define NUM1 12345678
printf ("10^%li\n", (long) NUM1); mpz_ui_pow_ui (z, 10, NUM1);
#define NUM2 123456789
printf ("10^%li\n", (long) NUM2); mpz_ui_pow_ui (z, 10, NUM2);
return EXIT_SUCCESS; }
Here is the test program output and a backtrace, from GDB.
(gdb) r Starting program: /home/matt/src/tests/c/gmp-pow 10^12345678 10^123456789
Program received signal SIGSEGV, Segmentation fault. __gmpz_n_pow_ui (r=0xbf84e330, bp=0xbf84e314, bsize=1, e=15432098) at n_pow_ui.c:459 (gdb) bt #0 __gmpz_n_pow_ui (r=0xbf84e330, bp=0xbf84e314, bsize=1, e=15432098) at n_pow_ui.c:459 #1 0xb7f0e53c in __gmpz_ui_pow_ui (r=0xbe6d4224, b=10, e=3194831396) at ui_pow_ui.c:47 #2 0x08048562 in main () at gmp-pow.c:24 (gdb)
The test program was compiled with commands like
gcc -g -I. gmp-pow.c .libs/libgmp.a -o gmp-pow
and the fault occurred when GMP was compiled with all versions of GCC that were tried. Most of these versions are listed below, with the associated GMP configure command(s) and the outputs of `uname -a', ./config.guess and ./configfsf.guess. `make check' on GMP passed in all cases.
2.95.4 20011002 (Debian prerelease) ./configure --enable-debugging CC=/usr/bin/gcc-2.95 CPPFLAGS=-fexceptionsa Linux cspcx95 2.6.13.2 #1 Fri Sep 30 19:00:13 BST 2005 i686 GNU/Linux athlon-pc-linux-gnu i686-pc-linux-gnu
3.3.3 20040412 (Red Hat Linux 3.3.3-7) ./configure --enable-cxx --enable-debugging CPPFLAGS=-fexceptions ./configure Linux cslin117.csunix.comp.leeds.ac.uk 2.6.10 #1 SMP Wed Jan 26 16:43:28 GMT 2005 i686 i686 i386 GNU/Linux pentium4-pc-linux-gnu i686-pc-linux-gnu
3.3.5 (Debian 1:3.3.5-8) ./configure --enable-cxx --enable-debugging CPPFLAGS=-fexceptions Linux cspcx95 2.6.13.2 #1 Fri Sep 30 19:00:13 BST 2005 i686 GNU/Linux athlon-pc-linux-gnu i686-pc-linux-gnu
3.4.4 20041218 (prerelease) (Debian 3.4.3-6) ./configure --enable-cxx --enable-debugging CC=/usr/bin/gcc-3.4 CXX=/usr/bin/g++-3.4 CPPFLAGS=-fexceptions Linux cspcx95 2.6.13.2 #1 Fri Sep 30 19:00:13 BST 2005 i686 GNU/Linux athlon-pc-linux-gnu i686-pc-linux-gnu
Thanks.

Matthew Mundell mattm@comp.leeds.ac.uk writes:
In the Parma Polyhedron Library, using GMP 4.1.4, calls to mpz_ui_pow_ui with large exponents are resulting in segmentation faults.
I suspect this is Q3 from http://swox.com/gmp/#FAQ. Can you please confirm?

Torbjorn Granlund tege@swox.com writes:
Matthew Mundell mattm@comp.leeds.ac.uk writes:
In the Parma Polyhedron Library, using GMP 4.1.4, calls to mpz_ui_pow_ui with large exponents are resulting in segmentation faults.
I suspect this is Q3 from http://swox.com/gmp/#FAQ. Can you please confirm?
Yes, it is, thank you.
-*- mode: compilation; default-directory: "~/src/tests/c/" -*- ulimit -s 8388608 && gmp-pow 10^12345678 10^123456789
Compilation finished at Fri Oct 7 16:44:28

Matthew Mundell mattm@comp.leeds.ac.uk writes:
Torbjorn Granlund tege@swox.com writes:
Matthew Mundell mattm@comp.leeds.ac.uk writes:
In the Parma Polyhedron Library, using GMP 4.1.4, calls to mpz_ui_pow_ui with large exponents are resulting in segmentation faults.
I suspect this is Q3 from http://swox.com/gmp/#FAQ. Can you please confirm?
Yes, it is, thank you.
-*- mode: compilation; default-directory: "~/src/tests/c/" -*- ulimit -s 8388608 && gmp-pow 10^12345678 10^123456789
It is a misfeature of all current GMP releases that they allocate arbitrary amonts of memory from the stack. This behaviour will change in the next major GMP release.
participants (2)
-
Matthew Mundell
-
Torbjorn Granlund