Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-nibabel for openSUSE:Factory 
checked in at 2026-11-13 18:35:47
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-nibabel (Old)
 and      /work/SRC/openSUSE:Factory/.python-nibabel.new.1251 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-nibabel"

Fri Nov 13 18:35:47 2026 rev:19 rq:1397295 version:5.5.0

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-nibabel/python-nibabel.changes    
2026-10-15 12:20:35.336194842 +0200
+++ /work/SRC/openSUSE:Factory/.python-nibabel.new.1251/python-nibabel.changes  
2026-11-13 18:40:09.498556963 +0100
@@ -1,0 +2,19 @@
+Fri Nov 13 09:40:19 UTC 2026 - Markéta Machová <[email protected]>
+
+- Update to 5.5.0
+  * The FilterMultiOrient frame filter allows extracting a volume of
+    consistent orientation from a DICOM containing mixed orienations
+  * get_fdata now returns complex128 arrays by default for complex
+    images
+  * Cifti2 *Axis classes now accept any Integral indices, allowing
+    them to be indexed by NumPy integers
+  * Support for empty BrainModelAxis
+  * Support for rescaling N-to-N affines in rescale_affine
+  * Drop support for Python 3.10, Numpy < 2.0
+  * Many bugfixes, see upstream notes
+- CVE-2026-118590: Denial of Service via uncontrolled memory
+  allocation (bsc#1289568)
+  * CVE-2026-118590.patch
+- Drop support-python-315.patch, not needed anymore
+
+-------------------------------------------------------------------

Old:
----
  nibabel-5.4.2.tar.gz
  support-python-315.patch

New:
----
  CVE-2026-118590.patch
  nibabel-5.5.0.tar.gz

----------(Old B)----------
  Old:  * CVE-2026-118590.patch
- Drop support-python-315.patch, not needed anymore
----------(Old E)----------

----------(New B)----------
  New:  allocation (bsc#1289568)
  * CVE-2026-118590.patch
- Drop support-python-315.patch, not needed anymore
----------(New E)----------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-nibabel.spec ++++++
--- /var/tmp/diff_new_pack.fnnHuu/_old  2026-11-13 18:40:10.415595762 +0100
+++ /var/tmp/diff_new_pack.fnnHuu/_new  2026-11-13 18:40:10.417595847 +0100
@@ -23,23 +23,23 @@
 %bcond_with libalternatives
 %endif
 Name:           python-nibabel
-Version:        5.4.2
+Version:        5.5.0
 Release:        0
 Summary:        Tool to access multiple neuroimaging data formats
 License:        MIT
 URL:            https://nipy.org/nibabel
 # SourceRepository: https://github.com/nipy/nibabel
 Source:         
https://files.pythonhosted.org/packages/source/n/nibabel/nibabel-%{version}.tar.gz
-# PATCH-FIX-UPSTREAM gh#nipy/nibabel#1569
-Patch0:         support-python-315.patch
-BuildRequires:  %{python_module base >= 3.10}
+# PATCH-FIX-UPSTREAM CVE-2026-118590.patch bsc#1289568 gh#nipy/nibabel#1587
+Patch0:         CVE-2026-118590.patch
+BuildRequires:  %{python_module base >= 3.11}
 BuildRequires:  %{python_module hatch-vcs}
 BuildRequires:  %{python_module hatchling}
 BuildRequires:  %{python_module pip}
 BuildRequires:  fdupes
 BuildRequires:  python-rpm-macros
-Requires:       python-numpy >= 1.25
-Requires:       python-packaging >= 17
+Requires:       python-numpy >= 2.0
+Requires:       python-packaging >= 20
 Recommends:     python-Pillow
 Recommends:     python-h5py
 Recommends:     python-pydicom >= 1
@@ -62,11 +62,12 @@
 BuildRequires:  %{python_module Pillow}
 BuildRequires:  %{python_module h5py}
 BuildRequires:  %{python_module importlib-resources >= 5.12 if %python-base < 
3.12}
-BuildRequires:  %{python_module numpy >= 1.25}
-BuildRequires:  %{python_module packaging >= 17}
+BuildRequires:  %{python_module numpy >= 2.0}
+BuildRequires:  %{python_module packaging >= 20}
 BuildRequires:  %{python_module pydicom >= 1}
 BuildRequires:  %{python_module pytest-doctestplus}
 BuildRequires:  %{python_module pytest-httpserver}
+BuildRequires:  %{python_module pytest-run-parallel}
 BuildRequires:  %{python_module pytest-xdist}
 BuildRequires:  %{python_module pytest}
 BuildRequires:  %{python_module scipy}

++++++ CVE-2026-118590.patch ++++++
>From d7f7baead44478471bb13312c8cc97432316206e Mon Sep 17 00:00:00 2001
From: Pradeep Peddineni <[email protected]>
Date: Sat, 24 Oct 2026 11:54:08 -0400
Subject: [PATCH 1/3] BF: Check available data before allocating in
 array_from_file

A small file whose header claims a huge shape made array_from_file
allocate a buffer for the claimed size before finding out the data was
not there. For uncompressed streams, check the size first and raise the
usual short-read OSError. Closes gh-1566.
---
 nibabel/tests/test_nifti1.py      | 19 ++++++++++++++++
 nibabel/tests/test_volumeutils.py | 38 +++++++++++++++++++++++++++++++
 nibabel/volumeutils.py            | 28 +++++++++++++++++++----
 3 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/nibabel/tests/test_nifti1.py b/nibabel/tests/test_nifti1.py
index 77726874d1..774a5510ca 100644
--- a/nibabel/tests/test_nifti1.py
+++ b/nibabel/tests/test_nifti1.py
@@ -1639,3 +1639,22 @@ def test_large_nifti1():
     assert image_shape == data.shape
     n_ones = np.sum(data == 1.0)
     assert np.prod(image_shape) == n_ones
+
+
+def test_truncated_data_header_claims_large_shape():
+    # gh-1566: a tiny file whose header claims a huge data array can still be
+    # loaded for its header, but reading the data raises OSError up front
+    # instead of trying to allocate memory for the claimed size
+    hdr = Nifti1Header()
+    hdr.set_data_dtype(np.float64)
+    hdr.set_data_shape((32767, 32767, 1000))
+    with InTemporaryDirectory():
+        with open('short.nii', 'wb') as fobj:
+            hdr.write_to(fobj)
+            fobj.write(b'\x00' * 16)
+        img = load('short.nii')
+        assert img.shape == (32767, 32767, 1000)
+        with pytest.raises(OSError, match=r'Expected \d+ bytes, got 16 bytes'):
+            img.get_fdata()
+        with pytest.raises(OSError, match=r'Expected \d+ bytes, got 16 bytes'):
+            np.asanyarray(img.dataobj)
diff --git a/nibabel/tests/test_volumeutils.py 
b/nibabel/tests/test_volumeutils.py
index 8034d18fb2..e8097988c1 100644
--- a/nibabel/tests/test_volumeutils.py
+++ b/nibabel/tests/test_volumeutils.py
@@ -1231,6 +1231,44 @@ def read(self, n_bytes):
     )
 
 
+def test_array_from_file_short_before_allocating():
+    # gh-1566: a header claiming far more data than the file holds should give
+    # our OSError up front, not try to allocate a buffer for the claimed size
+    shape = (2**20,) * 3
+    dtype = np.dtype(np.int8)
+    n_bytes = 2**60
+    for mmap in (True, False):
+        bio = BytesIO(b'\x00' * 352)
+        with pytest.raises(OSError, match=f'Expected {n_bytes} bytes, got 342 
bytes'):
+            array_from_file(shape, dtype, bio, offset=10, mmap=mmap)
+    # Offset past the end of the data
+    with pytest.raises(OSError, match=f'Expected {n_bytes} bytes, got 0 
bytes'):
+        array_from_file(shape, dtype, BytesIO(b'\x00' * 10), offset=20)
+    with InTemporaryDirectory():
+        with open('short.bin', 'wb') as fobj:
+            fobj.write(b'\x00' * 352)
+        for mmap in (True, False):
+            with open('short.bin', 'rb') as fobj:
+                with pytest.raises(OSError, match=r'got 352 bytes from 
.*short\.bin'):
+                    array_from_file(shape, dtype, fobj, mmap=mmap)
+    # Exactly enough data still reads fine
+    arr = np.arange(24, dtype=np.int16).reshape((2, 3, 4))
+    bio = BytesIO(b'\x00' * 5 + arr.tobytes('F'))
+    assert_array_equal(array_from_file((2, 3, 4), arr.dtype, bio, offset=5, 
mmap=False), arr)
+
+
+def test_array_from_file_short_compressed():
+    # Compressed streams are not checked up front, but still report a short 
read
+    shape = (2, 3, 4)
+    dtype = np.dtype(np.float32)
+    with InTemporaryDirectory():
+        with Opener('short.gz', 'wb') as fobj:
+            fobj.write(b'\x00' * 10)
+        with Opener('short.gz', 'rb') as fobj:
+            with pytest.raises(OSError, match='Expected 96 bytes, got 10 
bytes'):
+                array_from_file(shape, dtype, fobj)
+
+
 def test__ftype4scaled_finite_warningfilters():
     # This test checks our ability to properly manage the thread-unsafe
     # warnings filter list.
diff --git a/nibabel/volumeutils.py b/nibabel/volumeutils.py
index 852006994e..d9d6e589a2 100644
--- a/nibabel/volumeutils.py
+++ b/nibabel/volumeutils.py
@@ -388,6 +388,13 @@ def _is_compressed_fobj(fobj: io.IOBase) -> bool:
     return isinstance(fobj, COMPRESSED_FILE_LIKES)
 
 
+def _short_read_message(n_bytes: int, n_read: int, infile: io.IOBase) -> str:
+    return (
+        f'Expected {n_bytes} bytes, got {n_read} bytes from '
+        f'{getattr(infile, "name", "object")}\n - could the file be damaged?'
+    )
+
+
 def array_from_file(
     shape: tuple[int, ...],
     in_dtype: np.dtype[DT],
@@ -457,6 +464,22 @@ def array_from_file(
     n_bytes = reduce(mul, shape) * in_dtype.itemsize
     if n_bytes == 0:
         return np.array([], in_dtype)
+    # Check there is enough data in the file before allocating a buffer for it.
+    # Otherwise a small file whose header claims a huge shape makes us allocate
+    # memory for data that isn't there.  Only done for uncompressed streams,
+    # where seeking to the end is cheap; for compressed streams it would mean
+    # decompressing the whole file.
+    if not _is_compressed_fobj(infile):
+        try:
+            infile.seek(0, 2)
+            n_available = max(infile.tell() - offset, 0)
+        except (AttributeError, TypeError, OSError):
+            # Minimal file-likes may lack tell() or whence; fall back to the
+            # check after reading
+            pass
+        else:
+            if n_available < n_bytes:
+                raise OSError(_short_read_message(n_bytes, n_available, 
infile))
     # Read data from file
     infile.seek(offset)
     if hasattr(infile, 'readinto'):
@@ -468,10 +491,7 @@ def array_from_file(
         n_read = len(data_bytes)
         needs_copy = True
     if n_bytes != n_read:
-        raise OSError(
-            f'Expected {n_bytes} bytes, got {n_read} bytes from '
-            f'{getattr(infile, "name", "object")}\n - could the file be 
damaged?'
-        )
+        raise OSError(_short_read_message(n_bytes, n_read, infile))
     arr: np.ndarray = np.ndarray(shape, in_dtype, buffer=data_bytes, 
order=order)
     if needs_copy:
         return arr.copy()

>From 9abe783d69d308c07680829bd0e56a798e274a97 Mon Sep 17 00:00:00 2001
From: Pradeep Peddineni <[email protected]>
Date: Mon, 9 Nov 2026 22:38:32 -0500
Subject: [PATCH 2/3] BF: Check available data before trying to memory-map it

On Windows, np.memmap of a file shorter than the requested mapping fails
with OSError (WinError 8) instead of the ValueError we catch, and on 32-bit
builds an overflowed length gives OverflowError. Run the size check before
the memmap attempt so short files get the same OSError on every platform.
---
 nibabel/volumeutils.py | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/nibabel/volumeutils.py b/nibabel/volumeutils.py
index d9d6e589a2..9f7042f2f3 100644
--- a/nibabel/volumeutils.py
+++ b/nibabel/volumeutils.py
@@ -450,26 +450,16 @@ def array_from_file(
     in_dtype = np.dtype(in_dtype)
     # Get file-like object from Opener instance
     infile = getattr(infile, 'fobj', infile)
-    if mmap and not _is_compressed_fobj(infile):
-        mode = 'c' if mmap is True else mmap
-        try:  # Try memmapping file on disk
-            return np.memmap(infile, in_dtype, mode=mode, shape=shape, 
order=order, offset=offset)
-            # The error raised by memmap, for different file types, has
-            # changed in different incarnations of the numpy routine
-        except (AttributeError, TypeError, ValueError):
-            pass
-    if len(shape) == 0:
-        return np.array([], in_dtype)
     # Use reduce and mul to work around numpy integer overflow
-    n_bytes = reduce(mul, shape) * in_dtype.itemsize
-    if n_bytes == 0:
-        return np.array([], in_dtype)
-    # Check there is enough data in the file before allocating a buffer for it.
-    # Otherwise a small file whose header claims a huge shape makes us allocate
-    # memory for data that isn't there.  Only done for uncompressed streams,
-    # where seeking to the end is cheap; for compressed streams it would mean
-    # decompressing the whole file.
-    if not _is_compressed_fobj(infile):
+    n_bytes = reduce(mul, shape) * in_dtype.itemsize if len(shape) else 0
+    # Check there is enough data in the file before memory-mapping it or
+    # allocating a buffer for it.  Otherwise a small file whose header claims a
+    # huge shape makes us allocate memory for data that isn't there, and memmap
+    # fails with platform-specific errors (OSError on Windows, OverflowError on
+    # 32-bit) instead of the ValueError caught below.  Only done for
+    # uncompressed streams, where seeking to the end is cheap; for compressed
+    # streams it would mean decompressing the whole file.
+    if n_bytes and not _is_compressed_fobj(infile):
         try:
             infile.seek(0, 2)
             n_available = max(infile.tell() - offset, 0)
@@ -480,6 +470,16 @@ def array_from_file(
         else:
             if n_available < n_bytes:
                 raise OSError(_short_read_message(n_bytes, n_available, 
infile))
+    if mmap and not _is_compressed_fobj(infile):
+        mode = 'c' if mmap is True else mmap
+        try:  # Try memmapping file on disk
+            return np.memmap(infile, in_dtype, mode=mode, shape=shape, 
order=order, offset=offset)
+            # The error raised by memmap, for different file types, has
+            # changed in different incarnations of the numpy routine
+        except (AttributeError, TypeError, ValueError):
+            pass
+    if n_bytes == 0:
+        return np.array([], in_dtype)
     # Read data from file
     infile.seek(offset)
     if hasattr(infile, 'readinto'):

>From 8952fd9bb9e19f1b4a9256547154bd55f3343802 Mon Sep 17 00:00:00 2001
From: Pradeep Peddineni <[email protected]>
Date: Tue, 10 Nov 2026 19:58:12 -0500
Subject: [PATCH 3/3] RF: Read into lazily allocated array instead of bytearray

bytearray zeroes its buffer, so a header claiming far more data than
a compressed stream holds commits the full claimed size before the
short read is detected. np.empty only commits pages as they are
written, so read into it directly. Read-only file-likes are read in
chunks, as read() may allocate the full request up front.

Limit the size check to the mmap branch, where it is still needed to
avoid platform-specific memmap errors on short files.
---
 nibabel/tests/test_nifti1.py      | 24 ++++++------
 nibabel/tests/test_volumeutils.py | 57 +++++++++++++++++++++++----
 nibabel/volumeutils.py            | 64 +++++++++++++++++++------------
 3 files changed, 102 insertions(+), 43 deletions(-)

diff --git a/nibabel/tests/test_nifti1.py b/nibabel/tests/test_nifti1.py
index 774a5510ca..07edcf515a 100644
--- a/nibabel/tests/test_nifti1.py
+++ b/nibabel/tests/test_nifti1.py
@@ -35,6 +35,7 @@
     load,
     slice_order_codes,
 )
+from nibabel.openers import ImageOpener
 from nibabel.optpkg import optional_package
 from nibabel.pkg_info import cmp_pkg_version
 from nibabel.spatialimages import HeaderDataError
@@ -1643,18 +1644,19 @@ def test_large_nifti1():
 
 def test_truncated_data_header_claims_large_shape():
     # gh-1566: a tiny file whose header claims a huge data array can still be
-    # loaded for its header, but reading the data raises OSError up front
-    # instead of trying to allocate memory for the claimed size
+    # loaded for its header, but reading the data raises OSError instead of
+    # trying to allocate memory for the claimed size, compressed or not
     hdr = Nifti1Header()
     hdr.set_data_dtype(np.float64)
     hdr.set_data_shape((32767, 32767, 1000))
     with InTemporaryDirectory():
-        with open('short.nii', 'wb') as fobj:
-            hdr.write_to(fobj)
-            fobj.write(b'\x00' * 16)
-        img = load('short.nii')
-        assert img.shape == (32767, 32767, 1000)
-        with pytest.raises(OSError, match=r'Expected \d+ bytes, got 16 bytes'):
-            img.get_fdata()
-        with pytest.raises(OSError, match=r'Expected \d+ bytes, got 16 bytes'):
-            np.asanyarray(img.dataobj)
+        for fname in ('short.nii', 'short.nii.gz'):
+            with ImageOpener(fname, 'wb') as fobj:
+                hdr.write_to(fobj)
+                fobj.write(b'\x00' * 16)
+            img = load(fname)
+            assert img.shape == (32767, 32767, 1000)
+            with pytest.raises(OSError, match=r'Expected \d+ bytes, got 16 
bytes'):
+                img.get_fdata()
+            with pytest.raises(OSError, match=r'Expected \d+ bytes, got 16 
bytes'):
+                np.asanyarray(img.dataobj)
diff --git a/nibabel/tests/test_volumeutils.py 
b/nibabel/tests/test_volumeutils.py
index e8097988c1..c1c302103b 100644
--- a/nibabel/tests/test_volumeutils.py
+++ b/nibabel/tests/test_volumeutils.py
@@ -1258,15 +1258,56 @@ def test_array_from_file_short_before_allocating():
 
 
 def test_array_from_file_short_compressed():
-    # Compressed streams are not checked up front, but still report a short 
read
-    shape = (2, 3, 4)
-    dtype = np.dtype(np.float32)
+    # gh-1566: compressed streams cannot be sized up front, so a header 
claiming
+    # a huge shape must fail on the short read without allocating for the
+    # claimed size.  2**32 bytes is usually lazily allocated, 2**60 bytes
+    # cannot be allocated at all; both should give our OSError
     with InTemporaryDirectory():
-        with Opener('short.gz', 'wb') as fobj:
-            fobj.write(b'\x00' * 10)
-        with Opener('short.gz', 'rb') as fobj:
-            with pytest.raises(OSError, match='Expected 96 bytes, got 10 
bytes'):
-                array_from_file(shape, dtype, fobj)
+        for ext in ('.gz', '.bz2'):
+            fname = f'short.bin{ext}'
+            with Opener(fname, 'wb') as fobj:
+                fobj.write(b'\x00' * 10)
+            for shape, dtype in (
+                ((2, 3, 4), np.float32),
+                ((2**16,) * 2, np.int8),
+                ((2**20,) * 3, np.int8),
+            ):
+                n_bytes = np.prod(shape, dtype=object) * 
np.dtype(dtype).itemsize
+                for mmap in (True, False):
+                    with Opener(fname, 'rb') as fobj:
+                        with pytest.raises(
+                            OSError, match=f'Expected {n_bytes} bytes, got 10 
bytes'
+                        ):
+                            array_from_file(shape, dtype, fobj, mmap=mmap)
+
+
+def test_array_from_file_chunks(monkeypatch):
+    # Data spanning several reads, with and without readinto
+    monkeypatch.setattr('nibabel.volumeutils._READ_CHUNK_SIZE', 7)
+    arr = np.arange(60, dtype='>i4').reshape((3, 4, 5))
+
+    class ReadOnly:  # file-like without readinto
+        def __init__(self, data):
+            self._bio = BytesIO(data)
+
+        def seek(self, pos):
+            self._bio.seek(pos)
+
+        def read(self, n_bytes):
+            return self._bio.read(n_bytes)
+
+    for order in 'FC':
+        data = b'\x00' * 3 + arr.tobytes(order)
+        for fobj in (BytesIO(data), ReadOnly(data)):
+            out = array_from_file(arr.shape, arr.dtype, fobj, offset=3, 
order=order, mmap=False)
+            assert_array_equal(out, arr)
+            assert out.flags.writeable
+        for fobj in (BytesIO(data[:-1]), ReadOnly(data[:-1])):
+            with pytest.raises(OSError, match='Expected 240 bytes, got 239 
bytes'):
+                array_from_file(arr.shape, arr.dtype, fobj, offset=3, 
order=order, mmap=False)
+    # If the data are there but too big to allocate, the allocation error 
stands
+    with pytest.raises((MemoryError, ValueError)):
+        array_from_file((2**20,) * 3, np.int8, BytesIO(b'\x00' * 10), 
mmap=False)
 
 
 def test__ftype4scaled_finite_warningfilters():
diff --git a/nibabel/volumeutils.py b/nibabel/volumeutils.py
index 9f7042f2f3..3091693347 100644
--- a/nibabel/volumeutils.py
+++ b/nibabel/volumeutils.py
@@ -388,6 +388,10 @@ def _is_compressed_fobj(fobj: io.IOBase) -> bool:
     return isinstance(fobj, COMPRESSED_FILE_LIKES)
 
 
+# Chunk size for reading from file-likes without readinto; see array_from_file
+_READ_CHUNK_SIZE = 2**22
+
+
 def _short_read_message(n_bytes: int, n_read: int, infile: io.IOBase) -> str:
     return (
         f'Expected {n_bytes} bytes, got {n_read} bytes from '
@@ -452,25 +456,20 @@ def array_from_file(
     infile = getattr(infile, 'fobj', infile)
     # Use reduce and mul to work around numpy integer overflow
     n_bytes = reduce(mul, shape) * in_dtype.itemsize if len(shape) else 0
-    # Check there is enough data in the file before memory-mapping it or
-    # allocating a buffer for it.  Otherwise a small file whose header claims a
-    # huge shape makes us allocate memory for data that isn't there, and memmap
-    # fails with platform-specific errors (OSError on Windows, OverflowError on
-    # 32-bit) instead of the ValueError caught below.  Only done for
-    # uncompressed streams, where seeking to the end is cheap; for compressed
-    # streams it would mean decompressing the whole file.
-    if n_bytes and not _is_compressed_fobj(infile):
+    if mmap and not _is_compressed_fobj(infile):
+        # Check the file holds the data before mapping it; mapping past the
+        # end raises platform-specific errors (OSError on Windows,
+        # OverflowError on 32-bit) rather than the ValueError caught below
         try:
             infile.seek(0, 2)
             n_available = max(infile.tell() - offset, 0)
         except (AttributeError, TypeError, OSError):
-            # Minimal file-likes may lack tell() or whence; fall back to the
-            # check after reading
+            # Minimal file-likes may lack tell() or whence, and cannot be
+            # mapped anyway
             pass
         else:
             if n_available < n_bytes:
                 raise OSError(_short_read_message(n_bytes, n_available, 
infile))
-    if mmap and not _is_compressed_fobj(infile):
         mode = 'c' if mmap is True else mmap
         try:  # Try memmapping file on disk
             return np.memmap(infile, in_dtype, mode=mode, shape=shape, 
order=order, offset=offset)
@@ -482,21 +481,38 @@ def array_from_file(
         return np.array([], in_dtype)
     # Read data from file
     infile.seek(offset)
-    if hasattr(infile, 'readinto'):
-        data_bytes = bytearray(n_bytes)
-        n_read = infile.readinto(data_bytes)
-        needs_copy = False
-    else:
-        data_bytes = infile.read(n_bytes)
-        n_read = len(data_bytes)
-        needs_copy = True
+    try:
+        # np.empty does not touch its memory, so pages are only committed as
+        # data are read into them.  A header claiming far more data than the
+        # stream holds then fails on the short read, without first allocating
+        # (as bytearray would) memory for the full claimed size.
+        data = np.empty(n_bytes, dtype=np.uint8)
+    except (MemoryError, ValueError):
+        # Too large to allocate at all; report a short read if that is the
+        # real problem
+        n_read = len(infile.read(_READ_CHUNK_SIZE))
+        if n_read < _READ_CHUNK_SIZE:
+            raise OSError(_short_read_message(n_bytes, n_read, infile)) from 
None
+        raise
+    buf = memoryview(data)
+    readinto = getattr(infile, 'readinto', None)
+    n_read = 0
+    while n_read < n_bytes:
+        if readinto is not None:
+            # readinto only writes what it reads, so no need to chunk, and
+            # many small calls are slow for indexed_gzip
+            n_chunk = readinto(buf[n_read:])
+        else:
+            # read() may allocate the whole request up front
+            chunk = infile.read(min(n_bytes - n_read, _READ_CHUNK_SIZE))
+            n_chunk = len(chunk)
+            buf[n_read : n_read + n_chunk] = chunk
+        if not n_chunk:
+            break
+        n_read += n_chunk
     if n_bytes != n_read:
         raise OSError(_short_read_message(n_bytes, n_read, infile))
-    arr: np.ndarray = np.ndarray(shape, in_dtype, buffer=data_bytes, 
order=order)
-    if needs_copy:
-        return arr.copy()
-    arr.flags.writeable = True
-    return arr
+    return np.ndarray(shape, in_dtype, buffer=data, order=order)
 
 
 def array_to_file(

++++++ nibabel-5.4.2.tar.gz -> nibabel-5.5.0.tar.gz ++++++
++++ 13824 lines of diff (skipped)

Reply via email to