Visitar URL original
bpo-6839: removed unnecessary file name encoding test from ZipFile.open() by MorganRamsay · Pull Request #14212 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221223192504/https://github.com/python/cpython/pull/14212
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

bpo-6839: removed unnecessary file name encoding test from ZipFile.open() #14212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MorganRamsay
Copy link

@MorganRamsay MorganRamsay commented Jun 18, 2019 •

When attempting to open a ZIP file with ZipFile.open(), a BadZipFile exception is raised. The origin of the exception is an unnecessary file name encoding test.

            if zinfo.flag_bits & 0x800:
                # UTF-8 filename
                fname_str = fname.decode("utf-8")
            else:
                fname_str = fname.decode("cp437")

            if fname_str != zinfo.orig_filename:
                raise BadZipFile(
                    'File name in directory %r and header %r differ.'
                    % (zinfo.orig_filename, fname))

Two clear problems with this test:

  1. The test supports only the UTF-8 and CP437 encodings.
  2. On Windows, the test always fails due to path separator differences.

Two risks with this solution:

  1. This test might be relevant to whomever is using CP437.
  2. This test might be relevant on non-Windows platforms.

This issue has been open and unresolved for nearly 10 years, requiring users to subclass ZipFile when working with ZIP files on Windows platforms. This issue affects every version of Python since at least 2.7.

https://bugs.python.org/issue6839

@the-knights-who-say-ni
Copy link

the-knights-who-say-ni commented Jun 18, 2019

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@MorganRamsay
Copy link
Author

MorganRamsay commented Jun 18, 2019

I signed the CLA. My BPO account reflects that, but the Heroku app isn't sync'd. In any case, this PR removes code; it doesn't add any.

@mangrisano
Copy link
Contributor

mangrisano commented Jun 19, 2019

/cc @serhiy-storchaka @Yhg1s

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jun 23, 2019

  • The test supports only the UTF-8 and CP437 encodings.

Because they are the only official encodings. I do not see a problem here.

  • On Windows, the test always fails due to path separator differences.

Do you say that reading the ZIP file always fails on Windows? Why our tests are passed and we did not have bug reports about such major bug?

@MorganRamsay
Copy link
Author

MorganRamsay commented Jun 23, 2019 •

Why our tests are passed?

Bad tests?

and we did not have bug reports about such major bug?

So, this doesn't count? https://bugs.python.org/issue6839

FYI: Using test data generated from CryEngine's Resource Compiler, this is what the exception looks like:

Traceback (most recent call last):
<snip>
  File "D:\dev\Python3_7_2\Lib\zipfile.py", line 1599, in extract
    return self._extract_member(member, path, pwd)
  File "D:\dev\Python3_7_2\Lib\zipfile.py", line 1669, in _extract_member
    with self.open(member, pwd=pwd) as source, \
  File "D:\dev\Python3_7_2\Lib\zipfile.py", line 1511, in open
    % (zinfo.orig_filename, fname))
zipfile.BadZipFile: File name in directory 'Animations/animals/cow/cow.animevents' and header b'Animations\\animals\\cow\\cow.animevents' differ.

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jun 24, 2019 •

Why our tests are passed?

Bad tests?

There are tests for reading ZIP archives containing files in subdirectories. They are passed on Windows. If you think that some tests are missed, could you please provide them?

and we did not have bug reports about such major bug?

So, this doesn't count? https://bugs.python.org/issue6839

Seems this is just one case of ZIP archives generated by some broken software. That software should be fixed.

Please read the discussion on bpo-6839. Even if we make zipfile more lenient, the check should not be just removed, but an exception can be replaced with a warning.

@MorganRamsay
Copy link
Author

MorganRamsay commented Jun 24, 2019

Even if we make zipfile more lenient, the check should not be just removed, but an exception can be replaced with a warning.

Okay, so do that. At this point, any progress is good progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants