Skip to content

Commit

Permalink
sagemathgh-38490: prevent crash in order_from_multiple() due to round…
Browse files Browse the repository at this point in the history
…ing error

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 sagemath#38489.

URL: sagemath#38490
Reported by: Lorenz Panny
Reviewer(s):
  • Loading branch information
Release Manager committed Aug 11, 2024
2 parents b80f23f + 0b172b1 commit 378870f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tarball=configure-VERSION.tar.gz
sha1=e162e0f52da5eca0c01ddf4831edcea1acd72033
sha256=2033521228294e134368d69457d6e582706e84ff10bf3d6d0a57a2a4afad0a8b
sha1=7ae6149d44ba78586d234861a18856430f89c439
sha256=2417ae01c7f3ed65708a7fc937d9f2c4592252cbc35dceb3323445bd868bf8ee
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b178c10a7401b381b8ed2daab5aaf026436452c9
95fb8c3284c490325ef1e116f3a038a3467f5086
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 378870f

Please sign in to comment.