Skip to content

Commit

Permalink
Trac #16807: Overflow error in conversion Integer -> FiniteFieldEleme…
Browse files Browse the repository at this point in the history
…nt_pari_ffelt

As reported by Samuel Neves on [https://groups.google.com/forum/#!topic
/sage-support/ARJ3-5EFhrs sage-support], the following raises a PARI
error due to an overflow in converting from `t_INT` to long:
{{{
p = previous_prime(2^64)
F.<x> = GF(p^2)
x * 2**63
}}}
The problem is that the conversion is done using PARI's `itos` (`t_INT`
to signed long) instead of `itou` (`t_INT` to unsigned long).

URL: http://trac.sagemath.org/16807
Reported by: pbruin
Ticket author(s): Peter Bruin
Reviewer(s): Jeroen Demeyer
  • Loading branch information
Release Manager authored and vbraun committed Aug 13, 2014
2 parents 7d50824 + 596fc84 commit 974c1c1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/sage/rings/finite_rings/element_pari_ffelt.pyx
Expand Up @@ -49,7 +49,19 @@ cdef GEN _INT_to_FFELT(GEN g, GEN x) except NULL:
Convert the t_INT `x` to an element of the field of definition of
the t_FFELT `g`.
This function must be called within pari_catch_sig_on() ... pari_catch_sig_off().
This function must be called within ``pari_catch_sig_on()``
... ``pari_catch_sig_off()``.
TESTS:
Converting large integers to finite field elements does not lead
to overflow errors (see :trac:`16807`)::
sage: p = previous_prime(2^64)
sage: F.<x> = GF(p^2)
sage: x * 2^63
9223372036854775808*x
"""
cdef GEN f, p = gel(g, 4), result
cdef long t
Expand All @@ -71,7 +83,7 @@ cdef GEN _INT_to_FFELT(GEN g, GEN x) except NULL:
elif t == t_FF_Flxq:
f = cgetg(3, t_VECSMALL)
set_gel(f, 1, gmael(g, 2, 1))
f[2] = itos(x)
f[2] = itou(x)
else:
pari_catch_sig_off()
raise TypeError("unknown PARI finite field type")
Expand Down

0 comments on commit 974c1c1

Please sign in to comment.