mirror of https://github.com/KLayout/klayout.git
GDS2 reader: robustness against some broken files - should not segfault
This commit is contained in:
parent
c28fd425db
commit
de2ace4be3
|
|
@ -127,11 +127,19 @@ GDS2Reader::get_record ()
|
||||||
return rec_id;
|
return rec_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GDS2Reader::record_underflow_error ()
|
||||||
|
{
|
||||||
|
error (tl::to_string (tr ("Record too short")));
|
||||||
|
}
|
||||||
|
|
||||||
inline int
|
inline int
|
||||||
GDS2Reader::get_int ()
|
GDS2Reader::get_int ()
|
||||||
{
|
{
|
||||||
unsigned char *b = mp_rec_buf + m_recptr;
|
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);
|
int32_t l = *((int32_t *)b);
|
||||||
gds2h (l);
|
gds2h (l);
|
||||||
|
|
@ -142,7 +150,9 @@ inline short
|
||||||
GDS2Reader::get_short ()
|
GDS2Reader::get_short ()
|
||||||
{
|
{
|
||||||
unsigned char *b = mp_rec_buf + m_recptr;
|
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);
|
int16_t s = *((int16_t *)b);
|
||||||
gds2h (s);
|
gds2h (s);
|
||||||
|
|
@ -153,7 +163,9 @@ inline unsigned short
|
||||||
GDS2Reader::get_ushort ()
|
GDS2Reader::get_ushort ()
|
||||||
{
|
{
|
||||||
unsigned char *b = mp_rec_buf + m_recptr;
|
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);
|
uint16_t s = *((uint16_t *)b);
|
||||||
gds2h ((int16_t &) s);
|
gds2h ((int16_t &) s);
|
||||||
|
|
@ -164,7 +176,9 @@ inline double
|
||||||
GDS2Reader::get_double ()
|
GDS2Reader::get_double ()
|
||||||
{
|
{
|
||||||
unsigned char *b = mp_rec_buf + m_recptr;
|
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];
|
uint32_t l0 = ((uint32_t *)b) [0];
|
||||||
gds2h ((int32_t &) l0);
|
gds2h ((int32_t &) l0);
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,8 @@ private:
|
||||||
virtual void get_time (unsigned int *mod_time, unsigned int *access_time);
|
virtual void get_time (unsigned int *mod_time, unsigned int *access_time);
|
||||||
virtual GDS2XY *get_xy_data (unsigned int &length);
|
virtual GDS2XY *get_xy_data (unsigned int &length);
|
||||||
virtual void progress_checkpoint ();
|
virtual void progress_checkpoint ();
|
||||||
|
|
||||||
|
void record_underflow_error ();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,10 @@ GDS2ReaderBase::do_read (db::Layout &layout)
|
||||||
|
|
||||||
get_string (m_cellname);
|
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
|
// 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.
|
// read this cell in a special way and store the context information separately.
|
||||||
if (first_cell && m_cellname == "$$$CONTEXT_INFO$$$") {
|
if (first_cell && m_cellname == "$$$CONTEXT_INFO$$$") {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue