]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105979: Fix exception handling in `unmarshal_frozen_code` (`Python/import.c`)...
authorchgnrdv <52372310+chgnrdv@users.noreply.github.com>
Thu, 22 Jun 2023 21:30:19 +0000 (00:30 +0300)
committerGitHub <noreply@github.com>
Thu, 22 Jun 2023 21:30:19 +0000 (21:30 +0000)
Lib/test/test_import/__init__.py
Misc/NEWS.d/next/Core and Builtins/2023-06-22-19-16-24.gh-issue-105979.TDP2CU.rst [new file with mode: 0644]
Python/import.c

index f2726da203efbda408bd9283d4dfd9e51e824bdc..e0e2354ae2f19f26f0874cea1a6ed0a5827f6e6b 100644 (file)
@@ -23,6 +23,7 @@ import types
 import unittest
 from unittest import mock
 import _testinternalcapi
+import _imp
 
 from test.support import os_helper
 from test.support import (
@@ -763,6 +764,13 @@ class ImportTests(unittest.TestCase):
                                     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):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-06-22-19-16-24.gh-issue-105979.TDP2CU.rst b/Misc/NEWS.d/next/Core and Builtins/2023-06-22-19-16-24.gh-issue-105979.TDP2CU.rst
new file mode 100644 (file)
index 0000000..be6962a
--- /dev/null
@@ -0,0 +1 @@
+Fix crash in :func:`!_imp.get_frozen_object` due to improper exception handling.
index 969902afea1cd6b353f6fbc8c63fc09e39254215..9b1ad87b84f6499c4fa2efd06177c571c33d7468 100644 (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;
     }