From 7faf26196561f64127820ac39bfa450ab5087f27 Mon Sep 17 00:00:00 2001 From: Frederic Van Assche Date: Mon, 5 Oct 2026 17:25:20 +0200 Subject: [PATCH] Correctly handle null termination of comments in spexical files --- src/spexipy/spexical.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/spexipy/spexical.py b/src/spexipy/spexical.py index 80cd0f3..a641f78 100644 --- a/src/spexipy/spexical.py +++ b/src/spexipy/spexical.py @@ -72,6 +72,8 @@ class SpeXICAL: self.pixel_mask = self._load_frame(np.uint16) 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 = None @@ -128,6 +130,7 @@ class SpeXICAL: self._store_frame(self.pixel_mask) self._file.write(self.comment) - self._file.write(b'\x00') + if self.comment[-1] != b'\x00': + self._file.write(b'\x00') self._file.close() self._file = None