Skip to content

Commit

Permalink
gh-38490: prevent crash in order_from_multiple() due to rounding error
Browse files Browse the repository at this point in the history
    
Due to what appears to be rounding errors, the value of `k` here can be
zero, which results in the list `L` being split as `L1 == []` and `L2 ==
L`. This causes an error in the next recursive call.

Simple workaround: If either `L1` or `L2` would end up being empty, we
split the lists in the middle instead.

Resolves #38489.
    
URL: #38490
Reported by: Lorenz Panny
Reviewer(s):
  • Loading branch information
Release Manager committed Aug 27, 2024
2 parents ecea5cb + 0b172b1 commit 60f3816
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/sage/groups/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,17 @@ def order_from_multiple(P, m, plist=None, factorization=None, check=True,
sage: K.<a> = GF(3^60)
sage: order_from_multiple(a, 3^60 - 1, operation='*', check=False)
42391158275216203514294433200
TESTS:
Check that :issue:`38489` is fixed::
sage: from sage.groups.generic import order_from_multiple
sage: plist = [43, 257, 547, 881]
sage: m = prod(plist[:-1])
sage: elt = Zmod(m)(plist[-1])
sage: order_from_multiple(elt, m, plist=plist)
6044897
"""
Z = integer_ring.ZZ

Expand Down Expand Up @@ -1325,6 +1336,8 @@ def _order_from_multiple_helper(Q, L, S):
if abs(sum_left + v - (S / 2)) > abs(sum_left - (S / 2)):
break
sum_left += v
if not 0 < k < l:
k = l // 2
L1 = L[:k]
L2 = L[k:]
# recursive calls
Expand Down

0 comments on commit 60f3816

Please sign in to comment.