summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 4b6770483..179dbd8da 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -399,7 +399,9 @@ def load(file, mmap_mode=None, allow_pickle=True, fix_imports=True,
_ZIP_PREFIX = asbytes('PK\x03\x04')
N = len(format.MAGIC_PREFIX)
magic = fid.read(N)
- fid.seek(-N, 1) # back-up
+ # If the file size is less than N, we need to make sure not
+ # to seek past the beginning of the file
+ fid.seek(-min(N, len(magic)), 1) # back-up
if magic.startswith(_ZIP_PREFIX):
# zip-file (assume .npz)
# Transfer file ownership to NpzFile