From 1329cb6b9063d7d94eb36691480fc5e62917dd65 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 12 Jun 2026 00:20:45 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[yEnc=20parsing]=20Replace?= =?UTF-8?q?=20manual=20byte=20iteration=20with=20bytes.translate=20and=20b?= =?UTF-8?q?ytes.find?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: xbmc4lyfe <273732874+xbmc4lyfe@users.noreply.github.com> --- verify_nzb.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/verify_nzb.py b/verify_nzb.py index 953dccd..9f62c18 100644 --- a/verify_nzb.py +++ b/verify_nzb.py @@ -115,19 +115,28 @@ def _parse_yenc_attrs(line: bytes) -> dict[str, str]: return attrs +_YENC_TABLE = bytes((i - 42) % 256 for i in range(256)) + + def _decode_yenc_lines(lines: Iterable[bytes]) -> bytes: decoded = bytearray() for line in lines: - index = 0 - while index < len(line): - byte = line[index] - if byte == 61: - index += 1 - if index >= len(line): + if b"=" not in line: + decoded.extend(line.translate(_YENC_TABLE)) + else: + index = 0 + length = len(line) + while index < length: + escape_pos = line.find(b"=", index) + if escape_pos == -1: + decoded.extend(line[index:].translate(_YENC_TABLE)) + break + if escape_pos > index: + decoded.extend(line[index:escape_pos].translate(_YENC_TABLE)) + if escape_pos + 1 >= length: raise ValueError("dangling yEnc escape") - byte = (line[index] - 64) % 256 - decoded.append((byte - 42) % 256) - index += 1 + decoded.append((line[escape_pos + 1] - 106) % 256) + index = escape_pos + 2 return bytes(decoded)