-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-128131: Completely support random read access of uncompressed unencrypted files in ZipFile #128143
base: main
Are you sure you want to change the base?
Conversation
5ec1cff
commented
Dec 21, 2024
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: random access uncompressed unencrypted ZipExtFile #128131
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Closing as a duplicate of #128132. Please do not copy PRs made by others. Thanks. EDIT: It appears that this is either the same person or two people collaborating with each other. Anyway, please do not update two identical PRs. Thanks |
We discussed about this issue and decide that I submit the pr. vvb2060 has already closed his pr. Please reopen my pr, sorry for inconvenience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have tests for that please?
Misc/NEWS.d/next/Library/2024-12-21-03-20-12.gh-issue-128131.QpPmNt.rst
Outdated
Show resolved
Hide resolved
Added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the actual implementation until the tests are (hopefully) simpler.
…pPmNt.rst Co-authored-by: Bénédikt Tran <[email protected]>
add unittest
2c34891
to
57cb51c
Compare
Lib/test/test_zipfile/test_core.py
Outdated
b = fp.read(100) | ||
self.assertEqual(b, txt[:100]) | ||
|
||
# seek length must be greater than ZipExtFile.MIN_READ_SIZE (4096) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I would add something like self.assertLess(ZipExtFile.MIN_READ_SIZE, 5000)
to be sure that we update the tests if needed.
EDIT: check this outside the "with".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use ZipExtFile.MIN_READ_SIZE
directly ?
Misc/NEWS.d/next/Library/2024-12-21-03-20-12.gh-issue-128131.QpPmNt.rst
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address this comment: https://github.com/python/cpython/pull/128143/files#r1894920324.
Lib/test/test_zipfile/test_core.py
Outdated
arr = fp.read(100) | ||
self.assertEqual(fp.tell(), 10102) | ||
self.assertEqual(arr, txt[10002:10102]) | ||
self.assertLessEqual(sio.bytes_read - old_count, 4096, 'Redundant bytes were read during forward seek and read!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap the lines under 80-chars, e.g.:
diffcount = sio.bytes_read - old_count
self.assertLessEqual(diffcount, 4096, "forward seek: extra bytes read")
Lib/test/test_zipfile/test_core.py
Outdated
arr = fp.read(100) | ||
self.assertEqual(fp.tell(), 5199) | ||
self.assertEqual(arr, txt[5099:5199]) | ||
self.assertLessEqual(sio.bytes_read - old_count, 4096, 'Redundant bytes were read during backward seek and read!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto (message can be: "backward seek: extra bytes read")
# disable CRC checking after first seeking - it would be invalid | ||
self._expected_crc = None | ||
# seek actual file taking already buffered data into account | ||
read_offset -= len(self._readbuffer) - self._offset | ||
self._fileobj.seek(read_offset, os.SEEK_CUR) | ||
self._left -= read_offset | ||
self._compress_left -= read_offset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good catch that was a bug with read_offset > 0
. Are you able to make a test for this too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
692109a
to
67f05de
Compare