gh-105979: Fix exception handling in unmarshal_frozen_code (Python/import.c) (#105980)

This commit is contained in:
chgnrdv 2023-06-23 00:30:19 +03:00 committed by GitHub
parent 46a3190fcf
commit cd5280367a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View file

@ -23,6 +23,7 @@
import unittest
from unittest import mock
import _testinternalcapi
import _imp
from test.support import os_helper
from test.support import (
@ -763,6 +764,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):

View file

@ -0,0 +1 @@
Fix crash in :func:`!_imp.get_frozen_object` due to improper exception handling.

View file

@ -2071,6 +2071,7 @@ unmarshal_frozen_code(PyInterpreterState *interp, 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;
}