Skip to content

Commit 307c59a

Browse files
[3.11] gh-105979: Fix exception handling in unmarshal_frozen_code (Python/import.c) (GH-105980). (#106100)
* [3.11] gh-105979: Fix exception handling in `unmarshal_frozen_code` (`Python/import.c`) (GH-105980). (cherry picked from commit cd52803) Co-authored-by: chgnrdv <52372310+chgnrdv@users.noreply.github.com>
1 parent 8c79274 commit 307c59a

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
@@ -17,6 +17,7 @@
1717
import time
1818
import unittest
1919
from unittest import mock
20+
import _imp
2021

2122
from test.support import os_helper
2223
from test.support import (
@@ -529,6 +530,13 @@ def test_dll_dependency_import(self):
529530
env=env,
530531
cwd=os.path.dirname(pyexe))
531532

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

533541
@skip_if_dont_write_bytecode
534542
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
@@ -1327,6 +1327,7 @@ unmarshal_frozen_code(struct frozen_info *info)
13271327
PyObject *co = PyMarshal_ReadObjectFromString(info->data, info->size);
13281328
if (co == NULL) {
13291329
/* Does not contain executable code. */
1330+
PyErr_Clear();
13301331
set_frozen_error(FROZEN_INVALID, info->nameobj);
13311332
return NULL;
13321333
}

0 commit comments

Comments
 (0)