getPrime with invalid input causes Python to abort with fatal error

Bug #988431 reported by Legrandin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python-Crypto
Fix Released
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)
summary: - isPrime fails on invalid input
+ getPrime fails on invalid input
Revision history for this message
Darsey Litzenberger (dlitz) wrote : Re: 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;

Revision history for this message
Darsey 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);

Revision history for this message
Darsey 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
Revision history for this message
Darsey 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  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.