getPrime with invalid input causes Python to abort with fatal error

Bug #988431 reported by Legrandin on 2012-04-25
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python-Crypto
Undecided
Unassigned

Bug Description

The following code:

  from Crypto import Random
  from Crypto.Util.number import *

  getPrime(1, Random.new().read)

always makes python raise an exotic exception:

  Fatal Python error: PyEval_SaveThread: NULL tstate

Any Pycrypto version up to 2.5.0 on x86.

Legrandin (gooksankoo) on 2012-04-25
summary: - isPrime fails on invalid input
+ getPrime fails on invalid input

Here's the place where it fails:

#4 0x00007f343a5c2379 in isPrime (self=<optimized out>, args=<optimized out>, kwargs=<optimized out>) at src/_fastmath.c:1046
1046 Py_UNBLOCK_THREADS;

Dwayne Litzenberger (dlitz) wrote :

Found the offending code in rabinMillerTest:

        Py_BEGIN_ALLOW_THREADS;
        if ((mpz_tstbit (n, 0) == 0) || (mpz_cmp_ui (n, 3) < 0))
                return (mpz_cmp_ui (n, 2) == 0);

Dwayne Litzenberger (dlitz) wrote :
Changed in pycrypto:
status: New → Fix Committed
summary: - getPrime fails on invalid input
+ getPrime with invalid input causes Python to abort with fatal error
Dwayne Litzenberger (dlitz) wrote :

Fixed in PyCrypto 2.6.

Changed in pycrypto:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers