Catch some possible seg faults when opening invalid xtc files.

This commit is contained in:
Niels Müller
2016-06-06 16:59:16 +02:00
parent b16e4aac11
commit 208a51acfe

View File

@ -67,6 +67,9 @@ cdef array get_xtc_index(t_fileio *fio):
return cache[:-1]
class XTCError(Exception): pass
cdef class XTCReader:
cdef:
t_fileio *fio
@ -158,6 +161,11 @@ cdef class XTCReader:
real time, prec
rvec *x
if not os.path.exists(filename):
raise OSError('File not found: {}'.format(filename))
if filename.decode().split('.')[-1] != 'xtc':
raise XTCError('File is not of xtc type: {}'.format(filename))
self.fio = open_xtc(filename, b'r')
read_first_xtc(self.fio, &self.natoms, &step, &time, box, &x, &prec, &_bOK)