changeset 30917:84fa12727b43 stable

Avoid out-of-bounds indexing when checking for broadcastable inplace operators (bug #38466). * liboctave/numeric/bsxfun.h (is_valid_inplace_bsxfun): Check if non-singleton dimensions of the right hand side operator are broadcastable. Trailing dimensions are always treated as singleton.
author Markus Mützel <markus.muetzel@gmx.de>
date Fri, 08 Apr 2022 19:55:41 +0200
parents 1325f0c66460
children 297f32524dd8 e219aacda1e5
files liboctave/numeric/bsxfun.h
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/numeric/bsxfun.h	Fri Apr 08 13:48:13 2022 -0400
+++ b/liboctave/numeric/bsxfun.h	Fri Apr 08 19:55:41 2022 +0200
@@ -68,13 +68,13 @@
   if (r_nd < x_nd)
     return false;
 
-  for (int i = 0; i < r_nd; i++)
+  for (int i = 0; i < x_nd; i++)
     {
       octave_idx_type rk = rdv(i);
       octave_idx_type xk = xdv(i);
 
       // Only two valid conditions to check; can't stretch rk
-      if (! ((rk == xk) || (rk != 1 && xk == 1)))
+      if ((rk != xk) && xk != 1)
         return false;
     }