From 63dd687d73a7b05cdee74aa0cb82c3bb55554579 Mon Sep 17 00:00:00 2001 From: Egbert Bouman Date: Fri, 13 Dec 2024 15:43:29 +0100 Subject: [PATCH] Fix is_bencoded --- src/tribler/core/tunnel/community.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tribler/core/tunnel/community.py b/src/tribler/core/tunnel/community.py index 06ad145a46..5f03ef6ddd 100644 --- a/src/tribler/core/tunnel/community.py +++ b/src/tribler/core/tunnel/community.py @@ -51,7 +51,13 @@ def is_bencoded(x: bytes) -> bool: """ Returns True is x appears to be valid bencoded byte string. """ - return bdecode(x) is not None + if not isinstance(x, bytes): + raise ValueError('Value should be of bytes type. Got: %s' % type(x).__name__) + try: + decoded = bdecode(x) + except RuntimeError: + decoded = None + return decoded is not None class TriblerTunnelSettings(HiddenTunnelSettings):