Skip to content
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
8 changes: 8 additions & 0 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import time
import unittest
from unittest import mock
import _imp

from test.support import os_helper
from test.support import (
Expand Down Expand Up @@ -529,6 +530,13 @@ def test_dll_dependency_import(self):
env=env,
cwd=os.path.dirname(pyexe))

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


@skip_if_dont_write_bytecode
class FilePermissionTests(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash in :func:`!_imp.get_frozen_object` due to improper exception handling.
1 change: 1 addition & 0 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,7 @@ unmarshal_frozen_code(struct frozen_info *info)
PyObject *co = PyMarshal_ReadObjectFromString(info->data, info->size);
if (co == NULL) {
/* Does not contain executable code. */
PyErr_Clear();
set_frozen_error(FROZEN_INVALID, info->nameobj);
return NULL;
}
Expand Down