do not call into python api if an exception is set (#24022)
This commit is contained in:
parent
6de708fd46
commit
d73aca769f
|
@ -1,9 +1,11 @@
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
import _ast
|
import _ast
|
||||||
|
import tempfile
|
||||||
import types
|
import types
|
||||||
from test import support
|
from test import support, script_helper
|
||||||
|
|
||||||
class TestSpecifics(unittest.TestCase):
|
class TestSpecifics(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -492,6 +494,16 @@ if 1:
|
||||||
self.assertInvalidSingle('f()\nxy # blah\nblah()')
|
self.assertInvalidSingle('f()\nxy # blah\nblah()')
|
||||||
self.assertInvalidSingle('x = 5 # comment\nx = 6\n')
|
self.assertInvalidSingle('x = 5 # comment\nx = 6\n')
|
||||||
|
|
||||||
|
def test_particularly_evil_undecodable(self):
|
||||||
|
# Issue 24022
|
||||||
|
src = b'0000\x00\n00000000000\n\x00\n\x9e\n'
|
||||||
|
with tempfile.TemporaryDirectory() as tmpd:
|
||||||
|
fn = os.path.join(tmpd, "bad.py")
|
||||||
|
with open(fn, "wb") as fp:
|
||||||
|
fp.write(src)
|
||||||
|
res = script_helper.run_python_until_end(fn)[0]
|
||||||
|
self.assertIn(b"Non-UTF-8", res.err)
|
||||||
|
|
||||||
@support.cpython_only
|
@support.cpython_only
|
||||||
def test_compiler_recursion_limit(self):
|
def test_compiler_recursion_limit(self):
|
||||||
# Expected limit is sys.getrecursionlimit() * the scaling factor
|
# Expected limit is sys.getrecursionlimit() * the scaling factor
|
||||||
|
|
|
@ -10,6 +10,8 @@ Release date: tba
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #24022: Fix tokenizer crash when processing undecodable source code.
|
||||||
|
|
||||||
- Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
|
- Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
|
||||||
while it is holding a lock to a buffered I/O object, and the main thread
|
while it is holding a lock to a buffered I/O object, and the main thread
|
||||||
tries to use the same I/O object (typically stdout or stderr). A fatal
|
tries to use the same I/O object (typically stdout or stderr). A fatal
|
||||||
|
|
|
@ -1301,6 +1301,8 @@ verify_identifier(struct tok_state *tok)
|
||||||
{
|
{
|
||||||
PyObject *s;
|
PyObject *s;
|
||||||
int result;
|
int result;
|
||||||
|
if (tok->decoding_erred)
|
||||||
|
return 0;
|
||||||
s = PyUnicode_DecodeUTF8(tok->start, tok->cur - tok->start, NULL);
|
s = PyUnicode_DecodeUTF8(tok->start, tok->cur - tok->start, NULL);
|
||||||
if (s == NULL || PyUnicode_READY(s) == -1) {
|
if (s == NULL || PyUnicode_READY(s) == -1) {
|
||||||
if (PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) {
|
if (PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) {
|
||||||
|
@ -1469,11 +1471,8 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
|
||||||
c = tok_nextc(tok);
|
c = tok_nextc(tok);
|
||||||
}
|
}
|
||||||
tok_backup(tok, c);
|
tok_backup(tok, c);
|
||||||
if (nonascii &&
|
if (nonascii && !verify_identifier(tok))
|
||||||
!verify_identifier(tok)) {
|
|
||||||
tok->done = E_IDENTIFIER;
|
|
||||||
return ERRORTOKEN;
|
return ERRORTOKEN;
|
||||||
}
|
|
||||||
*p_start = tok->start;
|
*p_start = tok->start;
|
||||||
*p_end = tok->cur;
|
*p_end = tok->cur;
|
||||||
return NAME;
|
return NAME;
|
||||||
|
|
Loading…
Reference in New Issue