GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.10] gh-123270: Replaced SanitizedNames with a more surgical fix. (GH-123354) by jaraco · Pull Request #123426 · python/cpython

Conversation

@jaraco

@jaraco jaraco commented Aug 28, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Applies changes from zipp 3.20.1 and jaraco/zippGH-124 (cherry picked from commit 2231286) (cherry picked from commit 17b77bb)

  • Issue: zipfile.Path regression #123270

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jaraco
[3.10] [3.11] pythongh-123270: Replaced SanitizedNames with a more su…
c94488e
…rgical fix. (pythonGH-123354)

Applies changes from zipp 3.20.1 and jaraco/zippGH-124
(cherry picked from commit 2231286)
(cherry picked from commit 17b77bb)

Co-authored-by: Jason R. Coombs <[email protected]>
This was referenced Aug 28, 2024
gh-123270: Replaced SanitizedNames with a more surgical fix. #123354
Merged
zipfile.Path regression #123270
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 28, 2024
@jaraco

jaraco commented Sep 2, 2024

Copy link
Copy Markdown
Member Author

The tested assertions are failing in the backport on Windows:

======================================================================
FAIL: test_backslash_not_separator (test.test_zipfile.TestPath)
In a zip file, backslashes are not separators.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\cpython\cpython\lib\test\test_zipfile.py", line 3329, in test_backslash_not_separator
    assert first.name == 'foo\\bar'
AssertionError

======================================================================
FAIL: test_unsupported_names (test.test_zipfile.TestPath)
Path segments with special characters are readable.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\cpython\cpython\lib\test\test_zipfile.py", line 3315, in test_unsupported_names
    assert next(contents).name == 'V: NMS.flac'
AssertionError

----------------------------------------------------------------------
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco

jaraco commented Sep 2, 2024

Copy link
Copy Markdown
Member Author

Since these same tests pass on zipp on Windows+Python 3.10, it must be the case that something else has changed in zipp that wasn't backported to Python 3.10. But what? I applied the latest code from zipp to CPython, and the diff doesn't reveal anything that would explain the failing tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco
Add some context to the assertion for troubleshooting.
87ac08d
@jaraco

jaraco commented Sep 2, 2024

Copy link
Copy Markdown
Member Author

Adding some additional information to the troubleshooting, it's slightly more clear what's happening:

======================================================================
FAIL: test_backslash_not_separator (test.test_zipfile.TestPath)
In a zip file, backslashes are not separators.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\cpython\cpython\lib\test\test_zipfile.py", line 3330, in test_backslash_not_separator
    assert first.name == 'foo\\bar', first.name
AssertionError: bar
======================================================================
FAIL: test_unsupported_names (test.test_zipfile.TestPath)
Path segments with special characters are readable.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\cpython\cpython\lib\test\test_zipfile.py", line 3316, in test_unsupported_names
    assert item.name == 'V: NMS.flac', item.name
AssertionError:  NMS.flac
----------------------------------------------------------------------
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco

jaraco commented Sep 2, 2024

Copy link
Copy Markdown
Member Author

Aha! That diff is relevant in how it handles .name on Windows (pathlib.Path vs. pathlib.PurePosixPath) as applied in jaraco/zipp@9d6e639. So these tests can't be used in the backport. That's fine, as these tests are there to guarantee expectation in main and aren't pertinent to the security issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco
Remove tests not relevant to the backported security fix.
d1eca1e
Ref python#123426 (comment)
@jaraco jaraco mentioned this pull request Sep 2, 2024
[3.9] gh-123270: Replaced SanitizedNames with a more surgical fix. (GH-123354) #123432
Merged
@jaraco

jaraco commented Sep 2, 2024

Copy link
Copy Markdown
Member Author

@pablogsal In addition to approving/merging this security fix, I'd like your opinion.

In troubleshooting why the two new tests were failing, I learned that on Python 3.10 only, zipfile.Path.name is incorrect for names containing characters specific to the platform's file system (i.e. : and \ on Windows). Probably nobody is going to care about it, but it's conceivable it could lead to a security issue. Trivially, files that are present in the zipfile will appear to be missing on Windows, and potentially someone could craft a zipfile that could cause more serious harm, all because pathlib.Path is used to derive the .name of the path, producing invalid and unexpected results.

I can think of a few options:

  • track the issue as a separate security issue and patch it separately.
  • patch the issue as part of this fix, making the behavior consistent with Python 3.9 and 3.11.
  • (default) disregard the concern for now, leaving out the tests that caught the concern.

How would you like me to proceed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco
Restore the slash-prefixed paths in the malformed_paths test.
d5c243c
@pablogsal

pablogsal commented Sep 2, 2024

Copy link
Copy Markdown
Member
  • track the issue as a separate security issue and patch it separately.

I would prefer to do that. The reason is that it's unclear if that would affect anything else and I would like more eyes on this because 3.10 it's long into security-only so I don't want to risk this. I personally would prefer to keep it consistent with 3.9 and 3.11 if it's related to the security fix but I want to see what others think

@ambv @Yhg1s what are your thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv

ambv commented Sep 4, 2024

Copy link
Copy Markdown
Contributor

Agree this should be patched separately. @jaraco, the security releases will go out on Friday. Would it be possible to get a fix before then?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco

jaraco commented Sep 4, 2024

Copy link
Copy Markdown
Member Author

No problem. I'll get it done today.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco

jaraco commented Sep 4, 2024

Copy link
Copy Markdown
Member Author

I'll revise this PR to be acceptable as-is with the expectation that the additional issue will be addressed to re-enable the tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco
Revert "Remove tests not relevant to the backported security fix."
ee0d35f
This reverts commit d1eca1e.
@jaraco jaraco mentioned this pull request Sep 4, 2024
zipfile.Path.name uses inappropriate Windows semantics #123693
Closed
@jaraco
Skip failing tests, known to fail, referencing tracking bug.
45a7927
@jaraco

jaraco commented Sep 4, 2024

Copy link
Copy Markdown
Member Author

This patch now retains the tests but marks the two new ones as skipped on Windows, allowing the test suite to pass. A follow up GH-123694 promises to fix the emergent issue and restore the tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv
ambv merged commit 0aa1ee2 into python:3.10 Sep 4, 2024
@bedevere-app bedevere-app Bot removed the awaiting core review label Sep 4, 2024
@jaraco
jaraco deleted the backport-17b77bb-3.10 branch September 4, 2024 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jaraco @pablogsal @ambv
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.