mirror of
https://github.com/python/cpython.git
synced 2025-08-10 11:58:39 +00:00
[3.12] gh-105979: Fix exception handling in unmarshal_frozen_code
(Python/import.c
) (GH-105980) (#106055)
gh-105979: Fix exception handling in `unmarshal_frozen_code` (`Python/import.c`) (GH-105980)
(cherry picked from commit cd5280367a
)
Co-authored-by: chgnrdv <52372310+chgnrdv@users.noreply.github.com>
This commit is contained in:
parent
e9366df3ec
commit
b786fe8a09
3 changed files with 10 additions and 0 deletions
|
@ -23,6 +23,7 @@ import types
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
import _testinternalcapi
|
import _testinternalcapi
|
||||||
|
import _imp
|
||||||
|
|
||||||
from test.support import os_helper
|
from test.support import os_helper
|
||||||
from test.support import (
|
from test.support import (
|
||||||
|
@ -763,6 +764,13 @@ class ImportTests(unittest.TestCase):
|
||||||
env=env,
|
env=env,
|
||||||
cwd=os.path.dirname(pyexe))
|
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
|
@skip_if_dont_write_bytecode
|
||||||
class FilePermissionTests(unittest.TestCase):
|
class FilePermissionTests(unittest.TestCase):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix crash in :func:`!_imp.get_frozen_object` due to improper exception handling.
|
|
@ -2053,6 +2053,7 @@ unmarshal_frozen_code(PyInterpreterState *interp, struct frozen_info *info)
|
||||||
PyObject *co = PyMarshal_ReadObjectFromString(info->data, info->size);
|
PyObject *co = PyMarshal_ReadObjectFromString(info->data, info->size);
|
||||||
if (co == NULL) {
|
if (co == NULL) {
|
||||||
/* Does not contain executable code. */
|
/* Does not contain executable code. */
|
||||||
|
PyErr_Clear();
|
||||||
set_frozen_error(FROZEN_INVALID, info->nameobj);
|
set_frozen_error(FROZEN_INVALID, info->nameobj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue