Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash computing zero(ZZ[t]) - zero(ZZ) #1930

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

fingolfin
Copy link
Member

@fingolfin fingolfin commented Oct 27, 2024

The following lead to a crash (uncovered by Nemocas/AbstractAlgebra.jl#1867)

using Nemo
R, t = ZZ[:t]
zero(R) - ZZ(0)

The backtrace is always the same:

[57675] signal 11 (2): Segmentation fault: 11
in expression starting at REPL[4]:1
fmpz_neg at /Users/mhorn/.julia/artifacts/f76e8c291f81b2f313a6368345a2c17de479af1e/lib/libflint.19.0.dylib (unknown line)
sub! at /Users/mhorn/Projekte/OSCAR/Nemo.jl/src/flint/fmpz_poly.jl:878
- at /Users/mhorn/Projekte/OSCAR/Nemo.jl/src/flint/fmpz_poly.jl:153
...

This is due to a bug in FLINT's fmpz_poly_sub_fmpz, which does this:

void fmpz_poly_sub_fmpz(fmpz_poly_t res, const fmpz_poly_t poly, fmpz_t c)
{
    if (poly->length == 0)
    {
        fmpz_poly_set_fmpz(res, c);
        fmpz_neg(res->coeffs + 0, res->coeffs + 0);   // <- CRASH IS HERE
    }
    else
    {
        fmpz_poly_set(res, poly);
        fmpz_sub(res->coeffs + 0, res->coeffs + 0, c);
        _fmpz_poly_normalise(res);
    }
}

The problem is that even after the fmpz_poly_set_fmpz(res, c) we still have res->length == 0.

Fix for FLINT: flintlib/flint#2102

Copy link

codecov bot commented Oct 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.38%. Comparing base (9dd324d) to head (5544d49).
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1930      +/-   ##
==========================================
- Coverage   87.40%   87.38%   -0.03%     
==========================================
  Files          97       97              
  Lines       35642    35521     -121     
==========================================
- Hits        31154    31040     -114     
+ Misses       4488     4481       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

The following lead to a crash (uncovered by Nemocas/AbstractAlgebra.jl#1867)
```julia
using Nemo
R, t = ZZ[:t]
zero(R) - ZZ(0)
```
This is due to a bug in FLINT's `fmpz_poly_sub_fmpz`.
@fingolfin fingolfin force-pushed the mh/fmpz_poly_sub_fmpz-crash-fix branch from beec40c to 5544d49 Compare October 28, 2024 08:55
@fingolfin fingolfin merged commit ce4c582 into master Oct 28, 2024
21 of 22 checks passed
@fingolfin fingolfin deleted the mh/fmpz_poly_sub_fmpz-crash-fix branch October 28, 2024 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants