Commit a6b0cd84 authored by Evan Pretti's avatar Evan Pretti
Browse files

Improve DCD header validation check

parent cc158237
...@@ -85,10 +85,9 @@ class DCDFile(object): ...@@ -85,10 +85,9 @@ class DCDFile(object):
boxFlag = 1 boxFlag = 1
if append: if append:
file.seek(0, os.SEEK_SET) file.seek(0, os.SEEK_SET)
headerBytes = struct.unpack('<i', file.read(4))[0] headerMagic = file.read(8)
headerMagic = file.read(4) if headerMagic[4:8] != b'CORD' or struct.unpack('<i', headerMagic[:4])[0] != 84:
if headerBytes != 84 or headerMagic != b'CORD': raise ValueError('Cannot append to file with invalid DCD header')
raise ValueError('Cannot append to DCD file with invalid header')
self._modelCount = struct.unpack('<i', file.read(4))[0] self._modelCount = struct.unpack('<i', file.read(4))[0]
file.seek(92, os.SEEK_SET) file.seek(92, os.SEEK_SET)
commentsBytes = struct.unpack('<i', file.read(4))[0] commentsBytes = struct.unpack('<i', file.read(4))[0]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment