diff options
author | Jokimax <77680901+Jokimax@users.noreply.github.com> | 2023-10-24 21:15:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-24 21:15:42 (GMT) |
commit | c73b0f35602abf5f283bf64266641f19bc82fce0 (patch) | |
tree | 6ea01fed896eed84ea5c710604270b682588b8b9 /Lib/test/test_zipfile | |
parent | e5168ff3f8abe651d0a96d9e2d49028183e21b15 (diff) | |
download | cpython-c73b0f35602abf5f283bf64266641f19bc82fce0.zip cpython-c73b0f35602abf5f283bf64266641f19bc82fce0.tar.gz cpython-c73b0f35602abf5f283bf64266641f19bc82fce0.tar.bz2 |
gh-102956: Fix returning of empty byte strings after seek in zipfile … (#103565)
gh-102956: Fix returning of empty byte strings after seek in zipfile module. This was a regression in 3.12.0 due to a performance enhancement.
Diffstat (limited to 'Lib/test/test_zipfile')
-rw-r--r-- | Lib/test/test_zipfile/test_core.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py index 519d2ba..fb6b0b3 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -2246,6 +2246,22 @@ class OtherTests(unittest.TestCase): fp.seek(0, os.SEEK_SET) self.assertEqual(fp.tell(), 0) + def test_read_after_seek(self): + # Issue 102956: Make sure seek(x, os.SEEK_CUR) doesn't break read() + txt = b"Charge men!" + bloc = txt.find(b"men") + with zipfile.ZipFile(TESTFN, "w") as zipf: + zipf.writestr("foo.txt", txt) + with zipfile.ZipFile(TESTFN, mode="r") as zipf: + with zipf.open("foo.txt", "r") as fp: + fp.seek(bloc, os.SEEK_CUR) + self.assertEqual(fp.read(-1), b'men!') + with zipfile.ZipFile(TESTFN, mode="r") as zipf: + with zipf.open("foo.txt", "r") as fp: + fp.read(6) + fp.seek(1, os.SEEK_CUR) + self.assertEqual(fp.read(-1), b'men!') + @requires_bz2() def test_decompress_without_3rd_party_library(self): data = b'PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |