From 0ee918eb3642eef0c2f2f5f1833ab6bb6a7e671d Mon Sep 17 00:00:00 2001 From: Ed Slavich Date: Fri, 15 Jan 2021 12:05:41 -0500 Subject: [PATCH 1/3] Fix buffer assignment in compression.py --- asdf/compression.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/asdf/compression.py b/asdf/compression.py index 5b59bd416..f8a2a5f6c 100644 --- a/asdf/compression.py +++ b/asdf/compression.py @@ -203,11 +203,7 @@ def decompress(fd, used_size, data_size, compression): raise ValueError("Decompressed data too long") elif i + len(decoded) < data_size: raise ValueError("Decompressed data too short") - # Previous versions of numpy permitted assignment of an - # empty bytes object to an empty array range, but starting - # with numpy 1.20 this raises an error. - elif len(decoded) > 0: - buffer[i:i+len(decoded)] = decoded + buffer.data[i:i+len(decoded)] = decoded return buffer From a00d4a8502a2ab3e19a946a4bb3480309d5011fa Mon Sep 17 00:00:00 2001 From: Ed Slavich Date: Fri, 15 Jan 2021 12:18:18 -0500 Subject: [PATCH 2/3] Check decompressed data size when flush is unavailable --- asdf/compression.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/asdf/compression.py b/asdf/compression.py index f8a2a5f6c..ad257d5e2 100644 --- a/asdf/compression.py +++ b/asdf/compression.py @@ -201,9 +201,11 @@ def decompress(fd, used_size, data_size, compression): decoded = decoder.flush() if i + len(decoded) > data_size: raise ValueError("Decompressed data too long") - elif i + len(decoded) < data_size: - raise ValueError("Decompressed data too short") buffer.data[i:i+len(decoded)] = decoded + i += len(decoded) + + if i < data_size: + raise ValueError("Decompressed data too short") return buffer From 09e1cb8a0fb9e4556227240e930c38ee8f09a786 Mon Sep 17 00:00:00 2001 From: Ed Slavich Date: Fri, 15 Jan 2021 12:37:56 -0500 Subject: [PATCH 3/3] Update changelog --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index ddba2e124..8b8748121 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,7 +3,7 @@ - Fix bug causing test collection failures in some environments. [#889] -- Fix bug when decompressing arrays with numpy 1.20. [#901] +- Fix bug when decompressing arrays with numpy 1.20. [#901, #909] 2.7.1 (2020-08-18) ------------------