Correctly handle null termination of comments in spexical files

This commit is contained in:
frederic committed 2026-10-05 17:25:20 +02:00
1 parent 2713ff1a6c
commit 7faf261965
1 file changed
+3
+3
View File
@@ -72,6 +72,8 @@ class SpeXICAL:
self.pixel_mask = self._load_frame(np.uint16) self.pixel_mask = self._load_frame(np.uint16)
self.comment = self._file.read(self.file_size - self._min_size) self.comment = self._file.read(self.file_size - self._min_size)
if self.comment[-1] == b'\x00':
self.comment = self.comment[:-1]
self._file.close() self._file.close()
self._file = None self._file = None
@@ -128,6 +130,7 @@ class SpeXICAL:
self._store_frame(self.pixel_mask) self._store_frame(self.pixel_mask)
self._file.write(self.comment) self._file.write(self.comment)
if self.comment[-1] != b'\x00':
self._file.write(b'\x00') self._file.write(b'\x00')
self._file.close() self._file.close()
self._file = None self._file = None