Skip to content

Commit cd52803

Browse files
authored
gh-105979: Fix exception handling in unmarshal_frozen_code (Python/import.c) (#105980)
1 parent 46a3190 commit cd52803

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Lib/test/test_import/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import unittest
2424
from unittest import mock
2525
import _testinternalcapi
26+
import _imp
2627

2728
from test.support import os_helper
2829
from test.support import (
@@ -763,6 +764,13 @@ def test_dll_dependency_import(self):
763764
env=env,
764765
cwd=os.path.dirname(pyexe))
765766

767+
def test_issue105979(self):
768+
# this used to crash
769+
with self.assertRaises(ImportError) as cm:
770+
_imp.get_frozen_object("x", b"6\'\xd5Cu\x12")
771+
self.assertIn("Frozen object named 'x' is invalid",
772+
str(cm.exception))
773+
766774

767775
@skip_if_dont_write_bytecode
768776
class FilePermissionTests(unittest.TestCase):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash in :func:`!_imp.get_frozen_object` due to improper exception handling.

Python/import.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,7 @@ unmarshal_frozen_code(PyInterpreterState *interp, struct frozen_info *info)
20712071
PyObject *co = PyMarshal_ReadObjectFromString(info->data, info->size);
20722072
if (co == NULL) {
20732073
/* Does not contain executable code. */
2074+
PyErr_Clear();
20742075
set_frozen_error(FROZEN_INVALID, info->nameobj);
20752076
return NULL;
20762077
}

0 commit comments

Comments
 (0)