File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -5782,8 +5782,10 @@ PHP_FUNCTION(array_multisort)
57825782 * of the input arrays + 1. The last column is UNDEF to indicate the end
57835783 * of the row. It also stores the original position for stable sorting. */
57845784 indirect = (Bucket * * )safe_emalloc (array_size , sizeof (Bucket * ), 0 );
5785+ /* Move num_arrays multiplication to size because it's essentially impossible to overflow. */
5786+ Bucket * indirects = (Bucket * )safe_emalloc (array_size , sizeof (Bucket ) * (num_arrays + 1 ), 0 );
57855787 for (i = 0 ; i < array_size ; i ++ ) {
5786- indirect [i ] = ( Bucket * ) safe_emalloc (( num_arrays + 1 ), sizeof ( Bucket ), 0 );
5788+ indirect [i ] = indirects + ( i * ( num_arrays + 1 ));
57875789 }
57885790 for (i = 0 ; i < num_arrays ; i ++ ) {
57895791 k = 0 ;
@@ -5847,9 +5849,7 @@ PHP_FUNCTION(array_multisort)
58475849 RETVAL_TRUE ;
58485850
58495851clean_up :
5850- for (i = 0 ; i < array_size ; i ++ ) {
5851- efree (indirect [i ]);
5852- }
5852+ efree (indirects );
58535853 efree (indirect );
58545854 efree (func );
58555855 efree (arrays );
You can’t perform that action at this time.
0 commit comments