From add28462a02bdd02bff3c36d1b7b796941a785c3 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 14 May 2021 13:18:52 +0300 Subject: [PATCH] Fix Slice underflow. --- td/telegram/MessageEntity.cpp | 2 +- test/message_entities.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 630e75332..9ea1be0d0 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -628,7 +628,7 @@ static vector match_urls(Slice str) { } path_end_ptr = next_ptr; } - while (bad_path_end_chars.find(path_end_ptr[-1]) < bad_path_end_chars.size()) { + while (path_end_ptr > url_end_ptr + 1 && bad_path_end_chars.find(path_end_ptr[-1]) < bad_path_end_chars.size()) { path_end_ptr--; } if (url_end_ptr[0] == '/' || path_end_ptr > url_end_ptr + 1) { diff --git a/test/message_entities.cpp b/test/message_entities.cpp index 18d3a3f4c..e88139513 100644 --- a/test/message_entities.cpp +++ b/test/message_entities.cpp @@ -582,6 +582,7 @@ TEST(MessageEntities, url) { check_url("https://t…", {}); check_url("👉http://ab.com/cdefgh-1IJ", {"http://ab.com/cdefgh-1IJ"}); check_url("...👉http://ab.com/cdefgh-1IJ", {}); // TODO + check_url(".?", {}); } static void check_fix_formatted_text(td::string str, td::vector entities,