Skip to content

bpo-39033: Fix NameError in zipimport during hash validation #17588

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

Merged
merged 2 commits into from
Dec 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import struct
import time
import unittest
import unittest.mock

from test import support

Expand Down Expand Up @@ -204,6 +205,21 @@ def check(mod):
self.assertEqual(mod.state, 'old')
self.doTest(None, files, TESTMOD, call=check)

@unittest.mock.patch('_imp.check_hash_based_pycs', 'always')
def test_checked_hash_based_change_pyc(self):
source = b"state = 'old'"
source_hash = importlib.util.source_hash(source)
bytecode = importlib._bootstrap_external._code_to_hash_pyc(
compile(source, "???", "exec"),
source_hash,
False,
)
files = {TESTMOD + ".py": (NOW, "state = 'new'"),
TESTMOD + ".pyc": (NOW - 20, bytecode)}
def check(mod):
self.assertEqual(mod.state, 'new')
self.doTest(None, files, TESTMOD, call=check)

def testEmptyPy(self):
files = {TESTMOD + ".py": (NOW, "")}
self.doTest(None, files, TESTMOD)
Expand Down
2 changes: 1 addition & 1 deletion Lib/zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def _unmarshal_code(self, pathname, fullpath, fullname, data):
)

try:
_boostrap_external._validate_hash_pyc(
_bootstrap_external._validate_hash_pyc(
data, source_hash, fullname, exc_details)
except ImportError:
return None
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1901,3 +1901,4 @@ Tim Hopper
Dan Lidral-Porter
Ngalim Siregar
Tim Gates
Karthikeyan Singaravelan
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :exc:`NameError` in :mod:`zipimport`. Patch by Karthikeyan Singaravelan.
Loading