mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-13 23:29:02 +00:00
bencode: fix nontermination on empty or malformed input
read(1) returns b'' on EOF, which wasn't checked for in a couple cases, which could cause empty/truncated input to enter one of the `while True` loops without hope of exit. programming is hard.
This commit is contained in:
@@ -58,11 +58,15 @@ class TestBencode(unittest.TestCase):
|
||||
(b'ie', bencode.MalformedBencodeException,
|
||||
r'Unable to parse int'),
|
||||
(b'i64', bencode.MalformedBencodeException,
|
||||
r'Unexpected end while reading an integer'),
|
||||
r'EOF, expecting more integer'),
|
||||
(b'', bencode.MalformedBencodeException,
|
||||
r'EOF, expecting kind'),
|
||||
(b'i6-4', bencode.MalformedBencodeException,
|
||||
r'Unexpected input while reading an integer'),
|
||||
(b'4#string', bencode.MalformedBencodeException,
|
||||
r'Unexpected input while reading string length'),
|
||||
(b'4', bencode.MalformedBencodeException,
|
||||
r'EOF, expecting more string len'),
|
||||
(b'$:string', bencode.MalformedBencodeException,
|
||||
r'Unexpected data type'),
|
||||
(b'd5:world7:numbersli1ei2eee', bencode.MalformedBencodeException,
|
||||
|
||||
Reference in New Issue
Block a user