Fix out-of-bounds read in copy_poly_in_matrix for monomials - #379
Merged
mohabsafey merged 1 commit intoOct 2, 2026
Merged
Conversation
When a Groebner basis element whose leading monomial is hit by the multiplication by x_n is a monomial (length 1), copy_poly_in_matrix compared the exponent at lmb + (len - 2) * nv, i.e. lmb - nv, with the exponent following the leading term, which belongs to the next polynomial or lies past the end of bexp. This was reported by AddressSanitizer as a heap-buffer-overflow in the unit test fglm_build_matrixn_nonradical-radicalshape-31. A monomial has no tail, so its row in the multiplication matrix is zero; since dense_mat is zero-initialized, return early in that case. The same guard is added to copy_poly_in_matrixcol, which contains the same code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wegank
force-pushed
the
fix/copy-poly-in-matrix-oob
branch
from
October 1, 2026 23:31
227562d to
7879720
Compare
ederc
approved these changes
Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a Gröbner basis element whose leading monomial is hit by the multiplication by
x_nis a monomial (length 1),copy_poly_in_matrixcompared the exponent atlmb + (len - 2) * nv, i.e.lmb - nv, with the exponent following the leading term, which belongs to the next polynomial or lies past the end ofbexp.AddressSanitizer reports this as a heap-buffer-overflow in the unit test
fglm_build_matrixn_nonradical-radicalshape-31:A monomial has no tail, so its row in the multiplication matrix is zero; since
dense_matis zero-initialized by all callers, the function now returns early in that case. The same guard is added tocopy_poly_in_matrixcol, which contains identical code.Testing
make checkwith AddressSanitizer (LLVM clang,-g -O1 -fsanitize=address -fno-omit-frame-pointer,ASAN_OPTIONS=detect_leaks=0): 68/68 pass (previouslyfglm_build_matrixn_nonradical-radicalshape-31failed).make checkwith a normal-O2build: 68/68 pass.This change was made with the assistance of generative AI (Claude Code).
Co-authored-by: Claude Opus 5.5 noreply@anthropic.com
🤖 Generated with Claude Code