From d9fa36210b121ebd24bde4048aef72712af0ea58 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 19 Sep 2026 07:33:47 -0400 Subject: [PATCH] check if BEconded biffer is empty --- libi2pd_client/Torrents.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libi2pd_client/Torrents.cpp b/libi2pd_client/Torrents.cpp index a6752e73..b055f8e8 100644 --- a/libi2pd_client/Torrents.cpp +++ b/libi2pd_client/Torrents.cpp @@ -49,7 +49,7 @@ namespace torrents static std::pair ExtractInteger (std::string_view buf) { - if (buf[0] == 'i') + if (!buf.empty () && buf[0] == 'i') { auto pos = buf.find ('e'); if (pos != std::string_view::npos) @@ -66,7 +66,7 @@ namespace torrents static size_t ParseBEncoded (std::string_view buf); // recursive static size_t ParseDictionary (std::string_view buf, std::function handler = nullptr) { - if (buf[0] != 'd') return 0; + if (buf.empty () || buf[0] != 'd') return 0; buf = buf.substr (1); size_t len = 1; while (!buf.empty () && buf[0] != 'e') @@ -91,7 +91,7 @@ namespace torrents static size_t ParseList (std::string_view buf, std::function handler = nullptr) { - if (buf[0] != 'l') return 0 ; + if (buf.empty () || buf[0] != 'l') return 0; buf = buf.substr (1); size_t len = 1; while (!buf.empty () && buf[0] != 'e')