diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.cc b/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.cc index 8167b02d5..64253e5e0 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.cc +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.cc @@ -127,11 +127,19 @@ GDS2Reader::get_record () return rec_id; } +void +GDS2Reader::record_underflow_error () +{ + error (tl::to_string (tr ("Record too short"))); +} + inline int GDS2Reader::get_int () { unsigned char *b = mp_rec_buf + m_recptr; - m_recptr += 4; + if ((m_recptr += 4) > m_reclen) { + record_underflow_error (); + } int32_t l = *((int32_t *)b); gds2h (l); @@ -142,7 +150,9 @@ inline short GDS2Reader::get_short () { unsigned char *b = mp_rec_buf + m_recptr; - m_recptr += 2; + if ((m_recptr += 2) > m_reclen) { + record_underflow_error (); + } int16_t s = *((int16_t *)b); gds2h (s); @@ -153,7 +163,9 @@ inline unsigned short GDS2Reader::get_ushort () { unsigned char *b = mp_rec_buf + m_recptr; - m_recptr += 2; + if ((m_recptr += 2) > m_reclen) { + record_underflow_error (); + } uint16_t s = *((uint16_t *)b); gds2h ((int16_t &) s); @@ -164,7 +176,9 @@ inline double GDS2Reader::get_double () { unsigned char *b = mp_rec_buf + m_recptr; - m_recptr += 8; + if ((m_recptr += 8) > m_reclen) { + record_underflow_error (); + } uint32_t l0 = ((uint32_t *)b) [0]; gds2h ((int32_t &) l0); diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.h b/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.h index 33cce1401..17eb2b504 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.h +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.h @@ -106,6 +106,8 @@ private: virtual void get_time (unsigned int *mod_time, unsigned int *access_time); virtual GDS2XY *get_xy_data (unsigned int &length); virtual void progress_checkpoint (); + + void record_underflow_error (); }; } diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2ReaderBase.cc b/src/plugins/streamers/gds2/db_plugin/dbGDS2ReaderBase.cc index 90e84d65d..ad6eed607 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2ReaderBase.cc +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2ReaderBase.cc @@ -278,6 +278,10 @@ GDS2ReaderBase::do_read (db::Layout &layout) get_string (m_cellname); + if (m_cellname.empty ()) { + error (tl::to_string (tr ("Empty cell name"))); + } + // if the first cell is the dummy cell containing the context information // read this cell in a special way and store the context information separately. if (first_cell && m_cellname == "$$$CONTEXT_INFO$$$") {