summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2024-04-22 10:53:15 +0200
committerAlbert Astals Cid <aacid@kde.org>2024-04-22 09:26:48 +0000
commitfd98a72b6a72bb6e395ef70ae2527477496db6f5 (patch)
treea00a6101b8c9c32f414173be0376ba67c3a09c38
parent103fc977d30fa6b3df8d3a018e970230e9661933 (diff)
Fix crash in TextStringToUtf8
utf16ToUtf8 expects a null ended string
-rw-r--r--poppler/UTF.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/poppler/UTF.cc b/poppler/UTF.cc
index 74c5a113..af17a8b1 100644
--- a/poppler/UTF.cc
+++ b/poppler/UTF.cc
@@ -16,7 +16,7 @@
// Copyright (C) 2008 Koji Otani <sho@bbr.jp>
// Copyright (C) 2012, 2017, 2021, 2023 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2012 Hib Eris <hib@hiberis.nl>
-// Copyright (C) 2016, 2018-2022 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2016, 2018-2022, 2024 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2016 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
// Copyright (C) 2018, 2020 Nelson Benítez León <nbenitezl@gmail.com>
@@ -561,11 +561,12 @@ std::string TextStringToUtf8(const std::string &textStr)
if (hasUnicodeByteOrderMark(textStr)) {
uint16_t *utf16;
len = len / 2 - 1;
- utf16 = new uint16_t[len];
+ utf16 = new uint16_t[len + 1];
for (i = 0; i < len; i++) {
utf16[i] = (s[2 + i * 2] & 0xff) << 8 | (s[3 + i * 2] & 0xff);
}
- utf8 = utf16ToUtf8(utf16, &len);
+ utf16[i] = 0;
+ utf8 = utf16ToUtf8(utf16);
delete[] utf16;
} else {
utf8 = (char *)gmalloc(len + 1);