Mercurial > octave
comparison libinterp/octave-value/ov-str-mat.cc @ 28252:9646d752c76c stable
Fix segfault when loading a single string from an hdf5 file (bug #58268).
* ov-str-mat.cc (load_hdf5): Declare OCTAVE_LOCAL_BUFFER to be slen+1 to handle
the null termination byte. Remove FIXME questioning whether rank 0 strings
exist in HDF5 format, they do.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 28 Apr 2020 16:23:52 -0700 |
parents | c20b7290c778 |
children | f9201e7cbe00 0a5b15007766 |
comparison
equal
deleted
inserted
replaced
28238:50d83252f867 | 28252:9646d752c76c |
---|---|
678 H5Dclose (data_hid); | 678 H5Dclose (data_hid); |
679 return true; | 679 return true; |
680 } | 680 } |
681 else | 681 else |
682 { | 682 { |
683 // This is cruft for backward compatibility and easy data | 683 // This is cruft for backward compatibility and easy data importation |
684 // importation | 684 if (rank == 0) |
685 if (rank == 0) //FIXME: Does rank==0 even exist for strings in HDF5? | |
686 { | 685 { |
687 // a single string: | 686 // a single string: |
688 int slen = H5Tget_size (type_hid); | 687 int slen = H5Tget_size (type_hid); |
689 if (slen < 0) | 688 if (slen < 0) |
690 { | 689 { |
693 H5Dclose (data_hid); | 692 H5Dclose (data_hid); |
694 return false; | 693 return false; |
695 } | 694 } |
696 else | 695 else |
697 { | 696 { |
698 OCTAVE_LOCAL_BUFFER (char, s, slen); | 697 OCTAVE_LOCAL_BUFFER (char, s, slen+1); |
699 // create datatype for (null-terminated) string | 698 // create datatype for (null-terminated) string to read into: |
700 // to read into: | |
701 hid_t st_id = H5Tcopy (H5T_C_S1); | 699 hid_t st_id = H5Tcopy (H5T_C_S1); |
702 H5Tset_size (st_id, slen+1); | 700 H5Tset_size (st_id, slen+1); |
703 if (H5Dread (data_hid, st_id, octave_H5S_ALL, | 701 if (H5Dread (data_hid, st_id, octave_H5S_ALL, |
704 octave_H5S_ALL, octave_H5P_DEFAULT, s) < 0) | 702 octave_H5S_ALL, octave_H5P_DEFAULT, s) < 0) |
705 { | 703 { |