From 8e23c896432b31f6d56f5f711db67b62a6ea9679 Mon Sep 17 00:00:00 2001 From: Rik Date: Wed, 20 May 2020 21:43:17 +0100 Subject: [PATCH] Fix segfault when loading a single string from an hdf5 file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Origin: vendor, https://hg.savannah.gnu.org/hgweb/octave/rev/9646d752c76c Bug: https://savannah.gnu.org/bugs/index.php?58268 Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=959109 Forwarded: not-needed Acked-by: Rafael Laboissière Last-Update: 2016-04-30 Gbp-Pq: Name load-hdf5-string-crash.patch --- libinterp/octave-value/ov-str-mat.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libinterp/octave-value/ov-str-mat.cc b/libinterp/octave-value/ov-str-mat.cc index f86a451f..161492c1 100644 --- a/libinterp/octave-value/ov-str-mat.cc +++ b/libinterp/octave-value/ov-str-mat.cc @@ -680,9 +680,8 @@ octave_char_matrix_str::load_hdf5 (octave_hdf5_id loc_id, const char *name) } else { - // This is cruft for backward compatibility and easy data - // importation - if (rank == 0) //FIXME: Does rank==0 even exist for strings in HDF5? + // This is cruft for backward compatibility and easy data importation + if (rank == 0) { // a single string: int slen = H5Tget_size (type_hid); @@ -695,9 +694,8 @@ octave_char_matrix_str::load_hdf5 (octave_hdf5_id loc_id, const char *name) } else { - OCTAVE_LOCAL_BUFFER (char, s, slen); - // create datatype for (null-terminated) string - // to read into: + OCTAVE_LOCAL_BUFFER (char, s, slen+1); + // create datatype for (null-terminated) string to read into: hid_t st_id = H5Tcopy (H5T_C_S1); H5Tset_size (st_id, slen+1); if (H5Dread (data_hid, st_id, octave_H5S_ALL, -- 2.30.2