Skip to content

Fix integer overflows in the heuristic univariate gcd - #112

Merged
Ovascos merged 5 commits into
SRI-CSL:masterfrom
nlewycky:fix-gcd-heuristic-bound
Oct 22, 2026
Merged

Ovascos merged 5 commits into
SRI-CSL:masterfrom
nlewycky:fix-gcd-heuristic-bound

Conversation

@nlewycky

Copy link
Copy Markdown
Contributor

bound_valuation kept coefficient bit counts in an int, and the evaluation shifted coefficients by degree * n bits through an unsigned. Coefficients of 2^31 or more bits, or a degree * n of 2^32 or more, did not fit: the evaluation point or the shift came out wrong, so the gcd was wrong or reconstruct_polynomial wrote past its coefficient array. Count bits in size_t, and skip the heuristic (falling back to the subresultant gcd) when the shift does not fit in an unsigned.

bound_valuation kept coefficient bit counts in an int, and the evaluation
shifted coefficients by degree * n bits through an unsigned. Coefficients
of 2^31 or more bits, or a degree * n of 2^32 or more, did not fit: the
evaluation point or the shift came out wrong, so the gcd was wrong or
reconstruct_polynomial wrote past its coefficient array. Count bits in
size_t, and skip the heuristic (falling back to the subresultant gcd) when
the shift does not fit in an unsigned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ovascos Ovascos self-assigned this Oct 21, 2026
@ahmed-irfan
ahmed-irfan self-requested a review October 21, 2026 14:39

@ahmed-irfan ahmed-irfan left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. The guard stops the 32-bit shift overflow, and the new test covers the case.

Suggestions, not blocking:

  1. Remove bound_valuation@Base 1.3 from debian/libpoly0.symbols. The function is now static, so dpkg-gensymbols can fail.
  2. In reconstruct_polynomial, replace the assert with a check that returns 0. Release builds remove the assert.

nlewycky and others added 2 commits October 21, 2026 20:59
bound_valuation is now static, so libpoly.so.0 no longer exports it, and
dpkg-gensymbols would report the listed symbol as missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
reconstruct_polynomial asserted that the value has at most max_size
digits, and release builds compile the assert out, so a violation would
write past the dense polynomial. It now frees its temporaries and returns
0, and the heuristic treats that as a failed attempt (the next power, or
the subresultant fallback).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nlewycky
nlewycky force-pushed the fix-gcd-heuristic-bound branch from 3dd5673 to d390ef2 Compare October 22, 2026 04:00
@Ovascos
Ovascos merged commit 8779171 into SRI-CSL:master Oct 22, 2026
8 checks passed
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.

3 participants