Skip to content
Permalink
Browse files

bpo-39033: Fix NameError in zipimport during hash validation (GH-17588)

Patch by Karthikeyan Singaravelan.
  • Loading branch information
tirkarthi authored and ncoghlan committed Dec 15, 2019
1 parent d587272 commit 79f02fee1a542c440fd906fd54154c73fc0f8235
@@ -6,6 +6,7 @@
import struct
import time
import unittest
import unittest.mock

from test import support

@@ -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)
@@ -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
@@ -1901,3 +1901,4 @@ Tim Hopper
Dan Lidral-Porter
Ngalim Siregar
Tim Gates
Karthikeyan Singaravelan
@@ -0,0 +1 @@
Fix :exc:`NameError` in :mod:`zipimport`. Patch by Karthikeyan Singaravelan.

0 comments on commit 79f02fe

Please sign in to comment.
You can’t perform that action at this time.