Mercurial > octave
changeset 28368:6870068fb34e
Emit an error if m-file size is >512 MB to prevent segfault in interpreter (bug #58345).
* oct-parse.yy (): Get a sys::file_stat object for m-file anch check whether
size exceeds 512MB.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 25 May 2020 15:03:47 -0700 |
parents | d4b71e99c2be |
children | 248f7cc8dc74 |
files | libinterp/parse-tree/oct-parse.yy |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.yy Mon May 25 14:57:30 2020 -0700 +++ b/libinterp/parse-tree/oct-parse.yy Mon May 25 15:03:47 2020 -0700 @@ -4769,7 +4769,20 @@ FILE *ffile = nullptr; if (! full_file.empty ()) + { + // Check that m-file is not overly large which can segfault interpreter. + const int max_file_size = 512 * 1024 * 1024; // 512 MB + sys::file_stat fs (full_file); + + if (fs && fs.size () > max_file_size) + { + error ("file '%s' is too large, > 512 MB", full_file.c_str ()); + + return octave_value (); + } + ffile = sys::fopen (full_file, "rb"); + } if (! ffile) {