Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ config.ini
*.txt
.*
!.gitignore
__pycache__/
25 changes: 15 additions & 10 deletions verify_nzb.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,24 @@ def _parse_yenc_attrs(line: bytes) -> dict[str, str]:
return attrs


_DECODE_TABLE = bytes((i - 42) % 256 for i in range(256))
_ESCAPED_DECODE_TABLE = bytes((i - 106) % 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):
raise ValueError("dangling yEnc escape")
byte = (line[index] - 64) % 256
decoded.append((byte - 42) % 256)
index += 1
if b"=" not in line:
decoded.extend(line.translate(_DECODE_TABLE))
continue

parts = line.split(b"=")
decoded.extend(parts[0].translate(_DECODE_TABLE))
for part in parts[1:]:
if not part:
raise ValueError("dangling yEnc escape")
Comment on lines +131 to +132
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve consecutive yEnc escape markers during decode

The new split(b"=") logic misclassifies consecutive escape markers as a dangling escape: for input like b"==" (or any segment containing "=="), parts includes an empty chunk and if not part: raise ValueError(...) now triggers. In yEnc decoding, = should consume the very next byte (which may itself be =), so this is a behavioral regression from the previous byte-wise parser and can incorrectly flag decodable payloads as corrupt.

Useful? React with πŸ‘Β / πŸ‘Ž.

decoded.append(_ESCAPED_DECODE_TABLE[part[0]])
if len(part) > 1:
decoded.extend(part[1:].translate(_DECODE_TABLE))
return bytes(decoded)


Expand Down