Skip to content

Commit e477b34

Browse files
author
Release Manager
committed
gh-40291: Prevent segfault on GF(2^e) dense matrix row/column swap
<!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> There is currently a problem with n x 0 and 0 x n matrices over GF(2^e). When performing row or column swaps, a segmentation fault is produced. The underlying issue seems to be within the M4RI library. Although the existing library code already has checks for these, they seem to be failing. A simple example to reproduce the problem is: sage: matrix.zero(GF(4),2,0).with_permuted_rows(Permutation([2,1])) The issue may be avoided in Sage by only performing swaps on non-empty rows and columns. I have added a simple condition to the swap logic for matrix_gf2e_dense Related issue raised in M4RI: malb/m4ri#32 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [X] The title is concise and informative. - [X] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None URL: #40291 Reported by: Biffo89 Reviewer(s): Vincent Neiger
2 parents d4f2905 + 95979a0 commit e477b34

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

build/pkgs/configure/checksums.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
tarball=configure-VERSION.tar.gz
2-
sha1=4e6ce95200c2209e5c4b0dc0c63b4c651d8a8821
3-
sha256=1854bd4325f94c25e4b5d13e0111892a145ec6e21bfe9836b0bcce06e1651b5f
2+
sha1=e36e22c26c8fbb4f64e5e59bd09f784acbd17eb5
3+
sha256=3787149372622b97561b0810c1a7f4d472c2a02696b5234e0da6ed4120ca9eb4
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10c19f1b79e14df2b856ba710d7b170e853b7bcb
1+
7f00f18349dd96ecfaae4c8b8a155f2978221bfc

src/sage/matrix/matrix_gf2e_dense.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
10851085
sage: B[2] == A[2]
10861086
True
10871087
"""
1088+
if self._ncols == 0:
1089+
return
10881090
mzed_row_swap(self._entries, row1, row2)
10891091

10901092
cdef swap_columns_c(self, Py_ssize_t col1, Py_ssize_t col2):
@@ -1123,6 +1125,8 @@ cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
11231125
sage: A.column(14) == B.column(0)
11241126
True
11251127
"""
1128+
if self._nrows == 0:
1129+
return
11261130
mzed_col_swap(self._entries, col1, col2)
11271131

11281132
def augment(self, right):

0 commit comments

Comments
 (0)