From 0748fb436fbf71b68f90a38f980deff517daa18d Mon Sep 17 00:00:00 2001 From: bhawkins Date: Fri, 28 Mar 2025 17:18:01 -0700 Subject: [PATCH 1/2] fix overflow in size calculation --- pyrat/lib/ste/ste_io.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pyrat/lib/ste/ste_io.py b/pyrat/lib/ste/ste_io.py index 8320ae4..eefa599 100644 --- a/pyrat/lib/ste/ste_io.py +++ b/pyrat/lib/ste/ste_io.py @@ -394,7 +394,7 @@ def create(self, shape=None, header=None, **kwargs): self.Header.Rat.rattype = ctypes.c_int(kwargs['rattype']) # calculate the needed size of an empty file - n_bytes = reduce(lambda x, y: x * y, self.shape) * self.dtype.itemsize + n_bytes = 1000 + np.prod(self.shape) * self.dtype.itemsize # write the Header and truncate the file with open(self.filename, 'wb') as lun: @@ -532,8 +532,7 @@ def write(self, arr=[], **kwargs): self.Header.Rat.ndim = ctypes.c_int(len(self.shape)) self.Header.Rat.nchannel = ctypes.c_int(int(np.prod(self.shape[2:]))) - n_bytes_total = ( - 1000 + reduce(lambda x, y: x * y, self.shape) * self.dtype.itemsize) + n_bytes_total = 1000 + np.prod(self.shape) * self.dtype.itemsize with open(self.filename, 'wb') as lun: lun.write(self.Header) @@ -664,7 +663,7 @@ def append(self, arr): self._ioerror('The shape specified in the header %s and the shape of ' 'the array %s don\'t correspond to each other!' % (str(self.shape[1:]),str(arr.shape[1:]))) - n_bytes_total = 1000 + reduce(lambda x, y: x * y, self.shape) * arr.itemsize + n_bytes_total = 1000 + np.prod(self.shape) * self.dtype.itemsize with open(self.filename, 'r+b') as lun: lun.seek(0,2) From 1026f908154a0050e25e8a1b7c37360609f73401 Mon Sep 17 00:00:00 2001 From: bhawkins Date: Fri, 28 Mar 2025 17:31:13 -0700 Subject: [PATCH 2/2] fix copy/past error in previous commit --- pyrat/lib/ste/ste_io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrat/lib/ste/ste_io.py b/pyrat/lib/ste/ste_io.py index eefa599..b869860 100644 --- a/pyrat/lib/ste/ste_io.py +++ b/pyrat/lib/ste/ste_io.py @@ -394,7 +394,7 @@ def create(self, shape=None, header=None, **kwargs): self.Header.Rat.rattype = ctypes.c_int(kwargs['rattype']) # calculate the needed size of an empty file - n_bytes = 1000 + np.prod(self.shape) * self.dtype.itemsize + n_bytes = np.prod(self.shape) * self.dtype.itemsize # write the Header and truncate the file with open(self.filename, 'wb') as lun: