From b1b191a6e7dd167f01ed9c4c239c10a0a89c4cae Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sat, 22 Jan 2022 17:46:20 +0100 Subject: [PATCH] Avoid crashes --- .../telegrambots/meta/api/objects/MessageEntity.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/MessageEntity.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/MessageEntity.java index fde140d7..362f7376 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/MessageEntity.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/MessageEntity.java @@ -79,8 +79,12 @@ public class MessageEntity implements BotApiObject { public void computeText(String message) { if (message != null) { byte[] bytes = message.getBytes(StandardCharsets.UTF_16LE); - text = new String(Arrays.copyOfRange(bytes, offset, offset + length), - StandardCharsets.UTF_16LE); + if (bytes.length >= offset && offset >= 0 && length >= 0) { + text = new String(Arrays.copyOfRange(bytes, offset, offset + length), + StandardCharsets.UTF_16LE); + } else { + text = ""; + } } } }