From 9d00bd01ce7fe4e4b0854801cbb0468502f5ff85 Mon Sep 17 00:00:00 2001 From: bashonly Date: Wed, 11 Jun 2025 02:32:42 -0500 Subject: [PATCH] [devalue] guard against Python negative indexing Authored by: bashonly --- yt_dlp/utils/web/devalue.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/yt_dlp/utils/web/devalue.py b/yt_dlp/utils/web/devalue.py index 570a0388e..dbde0b941 100644 --- a/yt_dlp/utils/web/devalue.py +++ b/yt_dlp/utils/web/devalue.py @@ -39,6 +39,8 @@ def parse_iter(parsed: typing.Any, /, *, revivers: dict[str, collections.abc.Cal -5: -math.inf, -6: -0.0, } + lowest_valid_index = min(resolved.keys()) + if isinstance(parsed, int): if parsed == -2: raise ValueError('invalid input') @@ -66,6 +68,10 @@ def parse_iter(parsed: typing.Any, /, *, revivers: dict[str, collections.abc.Cal target[index] = resolved[source] continue + if source < lowest_valid_index: + yield IndexError(f'invalid index: {source!r}') + continue + value = parsed[source] if isinstance(value, list): if value and isinstance(value[0], str):