From 4b0475661d9f0cadf210c4c3e5fd3533c10512fe Mon Sep 17 00:00:00 2001 From: tbeu Date: Sat, 19 Oct 2024 21:35:02 +0200 Subject: [PATCH] Fix illegal memory access As reported by https://issues.oss-fuzz.com/42535678 --- src/mat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mat.c b/src/mat.c index b217e73a..69a9921f 100644 --- a/src/mat.c +++ b/src/mat.c @@ -2444,7 +2444,9 @@ Mat_VarPrint(const matvar_t *matvar, int printdata) const char *im = (const char *)complex_data->Im; for ( i = 0; i < (size_t)sparse->njc - 1; i++ ) { for ( j = sparse->jc[i]; - j < (size_t)sparse->jc[i + 1] && j < (size_t)sparse->ndata; j++ ) { + j < (size_t)sparse->jc[i + 1] && j < (size_t)sparse->ndata && + j < (size_t)sparse->nir; + j++ ) { printf(" (%u,%" SIZE_T_FMTSTR ") ", sparse->ir[j] + 1, i + 1); Mat_PrintNumber(matvar->data_type, re + j * stride); printf(" + ");