Skip to content

Commit 79f02fe

Browse files
tirkarthincoghlan
authored andcommitted
bpo-39033: Fix NameError in zipimport during hash validation (pythonGH-17588)
Patch by Karthikeyan Singaravelan.
1 parent d587272 commit 79f02fe

5 files changed

Lines changed: 286 additions & 269 deletions

File tree

Lib/test/test_zipimport.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import struct
77
import time
88
import unittest
9+
import unittest.mock
910

1011
from test import support
1112

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

208+
@unittest.mock.patch('_imp.check_hash_based_pycs', 'always')
209+
def test_checked_hash_based_change_pyc(self):
210+
source = b"state = 'old'"
211+
source_hash = importlib.util.source_hash(source)
212+
bytecode = importlib._bootstrap_external._code_to_hash_pyc(
213+
compile(source, "???", "exec"),
214+
source_hash,
215+
False,
216+
)
217+
files = {TESTMOD + ".py": (NOW, "state = 'new'"),
218+
TESTMOD + ".pyc": (NOW - 20, bytecode)}
219+
def check(mod):
220+
self.assertEqual(mod.state, 'new')
221+
self.doTest(None, files, TESTMOD, call=check)
222+
207223
def testEmptyPy(self):
208224
files = {TESTMOD + ".py": (NOW, "")}
209225
self.doTest(None, files, TESTMOD)

Lib/zipimport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def _unmarshal_code(self, pathname, fullpath, fullname, data):
608608
)
609609

610610
try:
611-
_boostrap_external._validate_hash_pyc(
611+
_bootstrap_external._validate_hash_pyc(
612612
data, source_hash, fullname, exc_details)
613613
except ImportError:
614614
return None

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,3 +1901,4 @@ Tim Hopper
19011901
Dan Lidral-Porter
19021902
Ngalim Siregar
19031903
Tim Gates
1904+
Karthikeyan Singaravelan
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :exc:`NameError` in :mod:`zipimport`. Patch by Karthikeyan Singaravelan.

0 commit comments

Comments
 (0)