diff options
| author | shadchin <[email protected]> | 2026-06-24 07:09:14 +0300 |
|---|---|---|
| committer | shadchin <[email protected]> | 2026-06-24 07:31:09 +0300 |
| commit | 280914cd46f4411a2e01150bf9d9c53dff19fa66 (patch) | |
| tree | 841d7b8330cb51e86f2ea6e915e4904563321aca /contrib/tools/python3/Lib/tomllib/_parser.py | |
| parent | 1100ced6faf1d14f48cb041f885882d3b37491a2 (diff) | |
Update Python 3 to 3.13.14
commit_hash:9913a0288f56b5ddd0f99e5b2ff1569d491cbe5d
Diffstat (limited to 'contrib/tools/python3/Lib/tomllib/_parser.py')
| -rw-r--r-- | contrib/tools/python3/Lib/tomllib/_parser.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/contrib/tools/python3/Lib/tomllib/_parser.py b/contrib/tools/python3/Lib/tomllib/_parser.py index 9c80a6a547d..a1f7ffd6d24 100644 --- a/contrib/tools/python3/Lib/tomllib/_parser.py +++ b/contrib/tools/python3/Lib/tomllib/_parser.py @@ -6,8 +6,9 @@ from __future__ import annotations from collections.abc import Iterable import string +import sys from types import MappingProxyType -from typing import Any, BinaryIO, NamedTuple +from typing import Any, BinaryIO, NamedTuple, Final from ._re import ( RE_DATETIME, @@ -19,6 +20,13 @@ from ._re import ( ) from ._types import Key, ParseFloat, Pos +# Pathologically excessive number of parts in a key runs into quadratic +# behavior (e.g. in Flags.is_). +# Even if keys aren't currently parsed using recursion, they name a +# recursive structure, so it makes sense to limit it using getrecursionlimit() +# and RecursionError. +MAX_KEY_PARTS: Final = sys.getrecursionlimit() + ASCII_CTRL = frozenset(chr(i) for i in range(32)) | frozenset(chr(127)) # Neither of these sets include quotation mark or backslash. They are @@ -385,6 +393,10 @@ def parse_key(src: str, pos: Pos) -> tuple[Pos, Key]: pos = skip_chars(src, pos, TOML_WS) pos, key_part = parse_key_part(src, pos) key += (key_part,) + if len(key) > MAX_KEY_PARTS: + raise RecursionError( + f"TOML key has more than the allowed {MAX_KEY_PARTS} parts" + ) pos = skip_chars(src, pos, TOML_WS) |
