Skip to content

gh-127847: Fix position in the special-cased zipfile seek#127856

Merged
jaraco merged 7 commits into
python:mainfrom
dimaryaz:zipfile_position
Dec 24, 2024
Merged

gh-127847: Fix position in the special-cased zipfile seek#127856
jaraco merged 7 commits into
python:mainfrom
dimaryaz:zipfile_position

Conversation

@dimaryaz

@dimaryaz dimaryaz commented Dec 12, 2024

Copy link
Copy Markdown
Contributor

@ghost

ghost commented Dec 12, 2024

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app

bedevere-app Bot commented Dec 12, 2024

Copy link
Copy Markdown

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.

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

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.

Comment thread Misc/NEWS.d/next/Library/2024-12-12-07-27-51.gh-issue-127847.ksfNKM.rst Outdated
Comment thread Lib/test/test_zipfile/test_core.py Outdated
Comment thread Lib/test/test_zipfile/test_core.py Outdated
@ZeroIntensity ZeroIntensity added needs backport to 3.12 only 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

danifus commented Dec 13, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

danifus commented Dec 14, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

Just rebased, and everything passed now.

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

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 :)

@jaraco jaraco left a comment

Copy link
Copy Markdown
Member

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
@miss-islington-app

Copy link
Copy Markdown

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 <dima@bucket.xxx>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
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 <dima@bucket.xxx>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
@bedevere-app

bedevere-app Bot commented Dec 24, 2024

Copy link
Copy Markdown

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

bedevere-app Bot commented Dec 24, 2024

Copy link
Copy Markdown

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 only 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 <dima@bucket.xxx>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
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 <dima@bucket.xxx>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
@ZeroIntensity

Copy link
Copy Markdown
Member

Congrats on your first contribution @dimaryaz

@dimaryaz

Copy link
Copy Markdown
Contributor Author

Thanks everyone!

@dimaryaz dimaryaz deleted the zipfile_position branch December 24, 2024 17:18
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
…on#127856)

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
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