sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.43k stars 478 forks source link

`xgcd` segfaults for `Polynomial_zmod_flint` #38537

Closed GiacomoPope closed 2 months ago

GiacomoPope commented 2 months ago

Steps To Reproduce

sage: k = Zmod(2**16)
sage: R.<x> = k[]
sage: u = x + 10161
sage: v = x + 10681
sage: type(u)
<class 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint'>
sage: u.gcd(v)
1
sage: 
sage: pari(u).gcd(pari(v))
Mod(65016, 65536)
sage: 
sage: pari(u).gcdext(pari(v))
---------------------------------------------------------------------------
PariError                                 Traceback (most recent call last)
Cell In[8], line 1
----> 1 pari(u).gcdext(pari(v))

File cypari2/auto_gen.pxi:12932, in cypari2.gen.Gen_base.gcdext()

File /private/var/tmp/sage-10.4-current/local/var/lib/sage/venv-python3.12.4/lib/python3.12/site-packages/cypari2/handle_error.pyx:211, in cypari2.handle_error._pari_err_handle()
    209     pari_error_string = s.decode('ascii') + ": " + pari_error_string
    210 
--> 211 raise PariError(errnum, pari_error_string, clone_gen_noclear(E))
    212 
    213 

PariError: impossible inverse in Fl_inv: Mod(65016, 65536)
sage: u.xgcd(v)
Flint exception (Impossible inverse):
    Cannot invert modulo 8*8192
------------------------------------------------------------------------
(no backtrace available)
------------------------------------------------------------------------
Unhandled SIGABRT: An abort() occurred.
This probably occurred because a *compiled* module has a bug
in it and is not properly wrapped with sig_on(), sig_off().
Python will now terminate.
------------------------------------------------------------------------
/usr/local/bin/sage: line 37: 29554 Abort trap: 6           /usr/bin/env "PYTHONUSERBASE=$USERBASE" "$SYMLINK"/venv/bin/sage "$@"

Expected Behavior

Non-invertibility should be caught as an error

Actual Behavior

Segfault

Additional Information

No response

Environment

- **OS**: MacOS
- **Sage Version**: 10.4

Checklist

GiacomoPope commented 2 months ago

38538 catches the segfault, which is the most important bit, but there's a second issue with flint and pari returning different values here, which will be harder to fix.

vincentmacri commented 2 months ago

38538 catches the segfault, which is the most important bit, but there's a second issue with flint and pari returning different values here, which will be harder to fix.

Can you open anther GitHub issue for the second issue?

GiacomoPope commented 2 months ago

Sure thing, this has been captured in https://github.com/sagemath/sage/issues/38559