Skip to content
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-127847: Fix position in the special-cased zipfile seek #127856

Merged
merged 7 commits into from
Dec 24, 2024

Conversation

dimaryaz
Copy link
Contributor

@dimaryaz dimaryaz commented Dec 12, 2024

Copy link

cpython-cla-bot bot commented Dec 12, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Dec 12, 2024

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 skip news label instead.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great first contribution, thanks :)

I have a few nitpicks, mostly related to some high-level triage tidbits.

Lib/test/test_zipfile/test_core.py Outdated Show resolved Hide resolved
Lib/test/test_zipfile/test_core.py Outdated Show resolved Hide resolved
@ZeroIntensity ZeroIntensity added needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels Dec 12, 2024
@ZeroIntensity ZeroIntensity requested a review from jaraco December 12, 2024 13:39
@danifus
Copy link
Contributor

danifus commented Dec 13, 2024

Nice tests and the bug report was great.

The fix I suggested was incomplete (I forgot _fileobj was an instance of _SharedFile until after I responded to you). The fix needs to go up a level of abstraction :p

_SharedFile should manage the position within the zip entry for us but it's seek implementation isn't resuming from its current position (like it does in read):

def seek(self, offset, whence=0):
with self._lock:
if self._writing():
raise ValueError("Can't reposition in the ZIP file while "
"there is an open writing handle on it. "
"Close the writing handle before trying to read.")
self._file.seek(offset, whence)
self._pos = self._file.tell()
return self._pos
def read(self, n=-1):
with self._lock:
if self._writing():
raise ValueError("Can't read from the ZIP file while there "
"is an open writing handle on it. "
"Close the writing handle before trying to read.")
self._file.seek(self._pos)
data = self._file.read(n)
self._pos = self._file.tell()
return data

seek should include something like self._file.seek(self._pos) like read does. This was hidden before the special cased ZIP_STORED seek as ZipExtFile.seek would use read to advance to the position if required (or seek back to the start of the file and read from there).

@dimaryaz
Copy link
Contributor Author

Ah, got it.

I used an if/else, just to avoid doing two seeks unnecessarily - do you think that's better?

(Though an extra seek worked fine, too, so I can change it to that.)

@danifus
Copy link
Contributor

danifus commented Dec 14, 2024

I like the single seek you've done. Nice work!

(The CI tool failed for macos-13 but that looks unrelated to these changes. The failing test was: test.test_multiprocessing_forkserver.test_processes. I'm not sure if it needs to be rerun before it can be merged?)

@dimaryaz
Copy link
Contributor Author

Just rebased, and everything passed now.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix :)

Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the clean contribution and others for the thorough review.

@jaraco jaraco enabled auto-merge (squash) December 24, 2024 15:34
@jaraco jaraco merged commit 7ed6c5c into python:main Dec 24, 2024
38 checks passed
@miss-islington-app
Copy link

Thanks @dimaryaz for the PR, and @jaraco for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 24, 2024
…onGH-127856)

---------
(cherry picked from commit 7ed6c5c)

Co-authored-by: Dima Ryazanov <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Jason R. Coombs <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 24, 2024
…onGH-127856)

---------
(cherry picked from commit 7ed6c5c)

Co-authored-by: Dima Ryazanov <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Jason R. Coombs <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Dec 24, 2024

GH-128225 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Dec 24, 2024
@bedevere-app
Copy link

bedevere-app bot commented Dec 24, 2024

GH-128226 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Dec 24, 2024
jaraco added a commit that referenced this pull request Dec 24, 2024
…127856) (#128226)

gh-127847: Fix position in the special-cased zipfile seek (GH-127856)

---------
(cherry picked from commit 7ed6c5c)

Co-authored-by: Dima Ryazanov <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Jason R. Coombs <[email protected]>
jaraco added a commit that referenced this pull request Dec 24, 2024
…127856) (#128225)

gh-127847: Fix position in the special-cased zipfile seek (GH-127856)

---------
(cherry picked from commit 7ed6c5c)

Co-authored-by: Dima Ryazanov <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Jason R. Coombs <[email protected]>
@ZeroIntensity
Copy link
Member

Congrats on your first contribution @dimaryaz

@dimaryaz
Copy link
Contributor Author

Thanks everyone!

@dimaryaz dimaryaz deleted the zipfile_position branch December 24, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants