Skip to content

Commit 68f489e

Browse files
committed
BF - cover case of overflow error on setting glmin
On my laptop, setting too large ints to the i4 of glmax caused an overflow error.
1 parent f53c168 commit 68f489e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

nibabel/nifti1.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,13 @@ def set_data_shape(self, shape):
676676
hdr = self._structarr
677677
if (len(shape) == 3 and shape[1:] == (1, 1) and
678678
shape[0] > np.iinfo(hdr['dim'].dtype.base).max): # Freesurfer case
679-
hdr['glmin'] = shape[0]
680-
if hdr['glmin'] != shape[0]:
679+
try:
680+
hdr['glmin'] = shape[0]
681+
except OverflowError:
682+
overflow = True
683+
else:
684+
overflow = hdr['glmin'] != shape[0]
685+
if overflow:
681686
raise HeaderDataError('shape[0] %s does not fit in glmax datatype' %
682687
shape[0])
683688
warnings.warn('Using large vector Freesurfer hack; header will '

0 commit comments

Comments
 (0)