Invalid read in mpz_powm_ui

Zimmermann Paul Paul.Zimmermann at loria.fr
Wed Dec 5 15:16:17 CET 2012


       Hi,

the following code gives with the development version of GMP and valgrind
on a Core 2 (tested with the gmp-5.0.90-2012120 snapshot on
core2-unknown-linux-gnu):

==5867== 1 errors in context 1 of 1:
==5867== Invalid read of size 8
==5867==    at 0x400CCA: __gmpz_powm_ui (in /tmp/a.out)
==5867==    by 0x4007C6: main (in /tmp/a.out)
==5867==  Address 0x51f1088 is 8 bytes before a block of size 8 alloc'd
==5867==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5867==    by 0x414AF8: __gmp_default_allocate (in /tmp/a.out)
==5867==    by 0x400824: __gmpz_init (in /tmp/a.out)
==5867==    by 0x400783: main (in /tmp/a.out)

We noticed this because we test GNU MPFR (and GNU MPC) against the mercurial
version of GMP. The first broken build was on 2012-11-05 00:07:32, maybe this
can help to isolate the issue.

Paul

PS: aren't the nightly builds of GMP tested against valgrind?

#include "gmp.h"

int
main()
{
  mpz_t r, my;

  mpz_init (r);
  mpz_init (my);
  mpz_set_ui (r, 2);
  mpz_set_ui (my, 16071820756403931195UL);
  mpz_powm_ui (r, r, 2, my);
  mpz_clear (r);
  mpz_clear (my);
}


More information about the gmp-bugs mailing list