Skip to content

Commit

Permalink
Fix #494
Browse files Browse the repository at this point in the history
Python 3.11 introduced a length limitation in int -> str conversion as a
solution to CVE-2020-10735. This impacts galois to create FieldArray
with very large primes.

Example:

>>> import galois
>>> p = galois.mersenne_primes()[23]
>>> gf = galois.GF(p)

The solution does not impact unaffected versions of Python because
sys.set_int_max_str_digits() was introduced in Python 3.11.
  • Loading branch information
iyanmv authored and mhostetter committed Jul 17, 2023
1 parent 6a3e2c5 commit 04fc7ef
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/galois/_databases/_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from __future__ import annotations

import sys
import sqlite3
from pathlib import Path

Expand Down Expand Up @@ -43,6 +44,14 @@ def fetch(self, n: int) -> tuple[list[int], list[int], int]:
Returns:
A tuple containing the prime factors and multiplicities.
"""
# Integer string conversion length limitation since Python 3.11
# https://github.com/mhostetter/galois/issues/494
if hasattr(sys, "set_int_max_str_digits"):
default_limit = sys.get_int_max_str_digits()
sys.set_int_max_str_digits(0)
n = str(n)
sys.set_int_max_str_digits(default_limit)

self.cursor.execute(
"""
SELECT factors, multiplicities, composite
Expand Down

0 comments on commit 04fc7ef

Please sign in to comment.