Skip to content

Commit e1a1dac

Browse files
committed
Skip saving too large arrays in "-binary" format (bug #67382).
* libinterp/corefcn/ls-oct-binary.cc (save_binary_data): Check number and size of dimensions and skip saving arrays that are too large for the file format.
1 parent a834dff commit e1a1dac

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

libinterp/corefcn/ls-oct-binary.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,28 @@ save_binary_data (std::ostream& os, const octave_value& tc,
341341
const std::string& name, const std::string& doc,
342342
bool mark_global, bool save_as_floats)
343343
{
344+
static octave_idx_type max_dim_val = std::numeric_limits<int32_t>::max () - 1;
345+
346+
dim_vector dv = tc.dims ();
347+
if (dv.ndims () > max_dim_val)
348+
{
349+
warning_with_id ("Octave:save:dimension-too-large",
350+
"save: skipping %s: number of dimensions too large for binary format",
351+
name.c_str ());
352+
return true;
353+
}
354+
355+
for (octave_idx_type i_dim = 0; i_dim < dv.ndims (); i_dim++)
356+
{
357+
if (dv(i_dim) > max_dim_val)
358+
{
359+
warning_with_id ("Octave:save:dimension-too-large",
360+
"save: skipping %s: dimensions too large for binary format",
361+
name.c_str ());
362+
return true;
363+
}
364+
}
365+
344366
int32_t name_len = name.length ();
345367

346368
os.write (reinterpret_cast<char *> (&name_len), 4);

0 commit comments

Comments
 (0)