- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 688
 
Closed
Labels
Description
Steps To Reproduce
P.<x, y> = PolynomialRing(ZZ)
(x + y).monomial_coefficient(x - x)
Expected Behavior
Raise ValueError with error text.
Actual Behavior
Segmentation fault.
Additional Information
There is a missing check for zero monomial in monomial_coefficient() for multivariate polynomial:
sage/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Lines 2947 to 3001 in c9dd1e8
| def monomial_coefficient(self, MPolynomial_libsingular mon): | |
| """ | |
| Return the coefficient in the base ring of the monomial mon in | |
| ``self``, where mon must have the same parent as ``self``. | |
| This function contrasts with the function ``coefficient`` | |
| which returns the coefficient of a monomial viewing this | |
| polynomial in a polynomial ring over a base ring having fewer | |
| variables. | |
| INPUT: | |
| - ``mon`` -- a monomial | |
| OUTPUT: coefficient in base ring | |
| .. SEEALSO:: | |
| For coefficients in a base ring of fewer variables, | |
| look at ``coefficient``. | |
| EXAMPLES:: | |
| sage: P.<x,y> = QQ[] | |
| The parent of the return is a member of the base ring. | |
| sage: f = 2 * x * y | |
| sage: c = f.monomial_coefficient(x*y); c | |
| 2 | |
| sage: c.parent() | |
| Rational Field | |
| sage: f = y^2 + y^2*x - x^9 - 7*x + 5*x*y | |
| sage: f.monomial_coefficient(y^2) | |
| 1 | |
| sage: f.monomial_coefficient(x*y) | |
| 5 | |
| sage: f.monomial_coefficient(x^9) | |
| -1 | |
| sage: f.monomial_coefficient(x^10) | |
| 0 | |
| """ | |
| cdef poly *p = self._poly | |
| cdef poly *m = mon._poly | |
| cdef ring *r = self._parent_ring | |
| if mon._parent is not self._parent: | |
| raise TypeError("mon must have same parent as self.") | |
| while p: | |
| if p_ExpVectorEqual(p, m, r) == 1: | |
| return si2sa(p_GetCoeff(p, r), r, self._parent._base) | |
| p = pNext(p) | |
| return self._parent._base._zero_element | 
Value mon._poly == NULL is passed to Singular and then NULL dereference occurs:
Environment
- OS: Ubuntu 22.04, macOS Ventura 13.0.1
 - Sage Version: SageMath version 10.6.beta2
 
Checklist
- I have searched the existing issues for a bug report that matches the one I want to file, without success.
 - I have read the documentation and troubleshoot guide