diff options
3 files changed, 1388 insertions, 0 deletions
diff --git a/meta-oe/recipes-support/poppler/poppler/CVE-2024-6239-0001.patch b/meta-oe/recipes-support/poppler/poppler/CVE-2024-6239-0001.patch new file mode 100644 index 0000000000..9994ce785b --- /dev/null +++ b/meta-oe/recipes-support/poppler/poppler/CVE-2024-6239-0001.patch | |||
@@ -0,0 +1,1275 @@ | |||
1 | From fc1c711cb5f769546c6b31cc688bf0ee7f0c1dbc Mon Sep 17 00:00:00 2001 | ||
2 | From: Sune Vuorela <sune@vuorela.dk> | ||
3 | Date: Thu, 1 Feb 2024 19:11:03 +0000 | ||
4 | Subject: [PATCH] More unicode vectors; fewer raw pointers | ||
5 | |||
6 | CVE: CVE-2024-6239 | ||
7 | Upstream-Status: Backport [https://gitlab.freedesktop.org/poppler/poppler/-/commit/fc1c711cb5f769546c6b31cc688bf0ee7f0c1dbc] | ||
8 | |||
9 | Signed-off-by: Yogita Urade <yogita.urade@windriver.com> | ||
10 | --- | ||
11 | cpp/poppler-toc.cpp | 5 +- | ||
12 | glib/poppler-document.cc | 3 +- | ||
13 | poppler/CharCodeToUnicode.cc | 113 +++++++++------------------ | ||
14 | poppler/CharCodeToUnicode.h | 12 ++- | ||
15 | poppler/DateInfo.cc | 10 +-- | ||
16 | poppler/JSInfo.cc | 9 +-- | ||
17 | poppler/Outline.cc | 12 +-- | ||
18 | poppler/Outline.h | 7 +- | ||
19 | poppler/TextOutputDev.cc | 8 +- | ||
20 | poppler/UTF.cc | 78 ++++++++---------- | ||
21 | poppler/UTF.h | 11 ++- | ||
22 | qt5/src/poppler-outline.cc | 2 +- | ||
23 | qt5/src/poppler-private.cc | 13 ++- | ||
24 | qt5/src/poppler-private.h | 1 + | ||
25 | qt5/tests/check_internal_outline.cpp | 6 +- | ||
26 | qt5/tests/check_utf_conversion.cpp | 24 +++--- | ||
27 | qt6/src/poppler-outline.cc | 2 +- | ||
28 | qt6/src/poppler-private.cc | 5 ++ | ||
29 | qt6/src/poppler-private.h | 1 + | ||
30 | qt6/tests/check_internal_outline.cpp | 6 +- | ||
31 | qt6/tests/check_utf_conversion.cpp | 24 +++--- | ||
32 | utils/HtmlFonts.cc | 4 +- | ||
33 | utils/HtmlFonts.h | 2 +- | ||
34 | utils/HtmlOutputDev.cc | 38 ++++----- | ||
35 | utils/HtmlOutputDev.h | 2 +- | ||
36 | utils/pdfinfo.cc | 8 +- | ||
37 | utils/pdfsig.cc | 8 +- | ||
38 | utils/pdftohtml.cc | 25 +++--- | ||
39 | 28 files changed, 183 insertions(+), 256 deletions(-) | ||
40 | |||
41 | diff --git a/cpp/poppler-toc.cpp b/cpp/poppler-toc.cpp | ||
42 | index c79abde..ed3a983 100644 | ||
43 | --- a/cpp/poppler-toc.cpp | ||
44 | +++ b/cpp/poppler-toc.cpp | ||
45 | @@ -61,9 +61,8 @@ toc_item_private::~toc_item_private() | ||
46 | |||
47 | void toc_item_private::load(const OutlineItem *item) | ||
48 | { | ||
49 | - const Unicode *title_unicode = item->getTitle(); | ||
50 | - const int title_length = item->getTitleLength(); | ||
51 | - title = detail::unicode_to_ustring(title_unicode, title_length); | ||
52 | + const std::vector<Unicode> &title_unicode = item->getTitle(); | ||
53 | + title = detail::unicode_to_ustring(title_unicode.data(), title_unicode.size()); | ||
54 | is_open = item->isOpen(); | ||
55 | } | ||
56 | |||
57 | diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc | ||
58 | index 7505a6f..fdfefdc 100644 | ||
59 | --- a/glib/poppler-document.cc | ||
60 | +++ b/glib/poppler-document.cc | ||
61 | @@ -2772,7 +2772,8 @@ PopplerAction *poppler_index_iter_get_action(PopplerIndexIter *iter) | ||
62 | item = (*iter->items)[iter->index]; | ||
63 | link_action = item->getAction(); | ||
64 | |||
65 | - title = unicode_to_char(item->getTitle(), item->getTitleLength()); | ||
66 | + const std::vector<Unicode> &itemTitle = item->getTitle(); | ||
67 | + title = unicode_to_char(itemTitle.data(), itemTitle.size()); | ||
68 | |||
69 | action = _poppler_action_new(iter->document, link_action, title); | ||
70 | g_free(title); | ||
71 | diff --git a/poppler/CharCodeToUnicode.cc b/poppler/CharCodeToUnicode.cc | ||
72 | index cd00937..d9ef019 100644 | ||
73 | --- a/poppler/CharCodeToUnicode.cc | ||
74 | +++ b/poppler/CharCodeToUnicode.cc | ||
75 | @@ -38,6 +38,7 @@ | ||
76 | |||
77 | #include <cstdio> | ||
78 | #include <cstring> | ||
79 | +#include <functional> | ||
80 | #include "goo/glibc.h" | ||
81 | #include "goo/gmem.h" | ||
82 | #include "goo/gfile.h" | ||
83 | @@ -51,13 +52,6 @@ | ||
84 | |||
85 | //------------------------------------------------------------------------ | ||
86 | |||
87 | -struct CharCodeToUnicodeString | ||
88 | -{ | ||
89 | - CharCode c; | ||
90 | - Unicode *u; | ||
91 | - int len; | ||
92 | -}; | ||
93 | - | ||
94 | //------------------------------------------------------------------------ | ||
95 | |||
96 | static int getCharFromString(void *data) | ||
97 | @@ -162,7 +156,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseCIDToUnicode(const char *fileName, co | ||
98 | } | ||
99 | fclose(f); | ||
100 | |||
101 | - ctu = new CharCodeToUnicode(collection->toStr(), mapA, mapLenA, true, nullptr, 0, 0); | ||
102 | + ctu = new CharCodeToUnicode(collection->toStr(), mapA, mapLenA, true, {}); | ||
103 | gfree(mapA); | ||
104 | return ctu; | ||
105 | } | ||
106 | @@ -171,8 +165,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(const GooString *fil | ||
107 | { | ||
108 | FILE *f; | ||
109 | Unicode *mapA; | ||
110 | - CharCodeToUnicodeString *sMapA; | ||
111 | - CharCode size, oldSize, len, sMapSizeA, sMapLenA; | ||
112 | + CharCode size, oldSize, len; | ||
113 | char buf[256]; | ||
114 | char *tok; | ||
115 | Unicode u0; | ||
116 | @@ -192,8 +185,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(const GooString *fil | ||
117 | mapA = (Unicode *)gmallocn(size, sizeof(Unicode)); | ||
118 | memset(mapA, 0, size * sizeof(Unicode)); | ||
119 | len = 0; | ||
120 | - sMapA = nullptr; | ||
121 | - sMapSizeA = sMapLenA = 0; | ||
122 | + std::vector<CharCodeToUnicodeString> sMapA; | ||
123 | |||
124 | line = 0; | ||
125 | while (getLine(buf, sizeof(buf), f)) { | ||
126 | @@ -230,17 +222,12 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(const GooString *fil | ||
127 | mapA[u0] = uBuf[0]; | ||
128 | } else { | ||
129 | mapA[u0] = 0; | ||
130 | - if (sMapLenA == sMapSizeA) { | ||
131 | - sMapSizeA += 16; | ||
132 | - sMapA = (CharCodeToUnicodeString *)greallocn(sMapA, sMapSizeA, sizeof(CharCodeToUnicodeString)); | ||
133 | - } | ||
134 | - sMapA[sMapLenA].c = u0; | ||
135 | - sMapA[sMapLenA].u = (Unicode *)gmallocn(n, sizeof(Unicode)); | ||
136 | + std::vector<Unicode> u; | ||
137 | + u.reserve(n); | ||
138 | for (i = 0; i < n; ++i) { | ||
139 | - sMapA[sMapLenA].u[i] = uBuf[i]; | ||
140 | + u.push_back(uBuf[i]); | ||
141 | } | ||
142 | - sMapA[sMapLenA].len = n; | ||
143 | - ++sMapLenA; | ||
144 | + sMapA.push_back({ u0, std::move(u) }); | ||
145 | } | ||
146 | if (u0 >= len) { | ||
147 | len = u0 + 1; | ||
148 | @@ -248,7 +235,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(const GooString *fil | ||
149 | } | ||
150 | fclose(f); | ||
151 | |||
152 | - ctu = new CharCodeToUnicode(fileName->toStr(), mapA, len, true, sMapA, sMapLenA, sMapSizeA); | ||
153 | + ctu = new CharCodeToUnicode(fileName->toStr(), mapA, len, true, std::move(sMapA)); | ||
154 | gfree(mapA); | ||
155 | gfree(uBuf); | ||
156 | return ctu; | ||
157 | @@ -256,7 +243,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(const GooString *fil | ||
158 | |||
159 | CharCodeToUnicode *CharCodeToUnicode::make8BitToUnicode(Unicode *toUnicode) | ||
160 | { | ||
161 | - return new CharCodeToUnicode({}, toUnicode, 256, true, nullptr, 0, 0); | ||
162 | + return new CharCodeToUnicode({}, toUnicode, 256, true, {}); | ||
163 | } | ||
164 | |||
165 | CharCodeToUnicode *CharCodeToUnicode::parseCMap(const GooString *buf, int nBits) | ||
166 | @@ -512,25 +499,18 @@ void CharCodeToUnicode::addMapping(CharCode code, char *uStr, int n, int offset) | ||
167 | map[code] = 0xfffd; | ||
168 | } | ||
169 | } else { | ||
170 | - if (sMapLen >= sMapSize) { | ||
171 | - sMapSize = sMapSize + 16; | ||
172 | - sMap = (CharCodeToUnicodeString *)greallocn(sMap, sMapSize, sizeof(CharCodeToUnicodeString)); | ||
173 | - } | ||
174 | map[code] = 0; | ||
175 | - sMap[sMapLen].c = code; | ||
176 | int utf16Len = n / 4; | ||
177 | - Unicode *utf16 = (Unicode *)gmallocn(utf16Len, sizeof(Unicode)); | ||
178 | + std::vector<Unicode> utf16(utf16Len); | ||
179 | + utf16.resize(utf16Len); | ||
180 | for (j = 0; j < utf16Len; ++j) { | ||
181 | if (!parseHex(uStr + j * 4, 4, &utf16[j])) { | ||
182 | - gfree(utf16); | ||
183 | error(errSyntaxWarning, -1, "Illegal entry in ToUnicode CMap"); | ||
184 | return; | ||
185 | } | ||
186 | } | ||
187 | utf16[utf16Len - 1] += offset; | ||
188 | - sMap[sMapLen].len = UTF16toUCS4(utf16, utf16Len, &sMap[sMapLen].u); | ||
189 | - gfree(utf16); | ||
190 | - ++sMapLen; | ||
191 | + sMap.push_back({ code, UTF16toUCS4(utf16.data(), utf16.size()) }); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | @@ -561,8 +541,6 @@ CharCodeToUnicode::CharCodeToUnicode() | ||
196 | { | ||
197 | map = nullptr; | ||
198 | mapLen = 0; | ||
199 | - sMap = nullptr; | ||
200 | - sMapLen = sMapSize = 0; | ||
201 | refCnt = 1; | ||
202 | isIdentity = false; | ||
203 | } | ||
204 | @@ -576,13 +554,11 @@ CharCodeToUnicode::CharCodeToUnicode(const std::optional<std::string> &tagA) : t | ||
205 | for (i = 0; i < mapLen; ++i) { | ||
206 | map[i] = 0; | ||
207 | } | ||
208 | - sMap = nullptr; | ||
209 | - sMapLen = sMapSize = 0; | ||
210 | refCnt = 1; | ||
211 | isIdentity = false; | ||
212 | } | ||
213 | |||
214 | -CharCodeToUnicode::CharCodeToUnicode(const std::optional<std::string> &tagA, Unicode *mapA, CharCode mapLenA, bool copyMap, CharCodeToUnicodeString *sMapA, int sMapLenA, int sMapSizeA) : tag(tagA) | ||
215 | +CharCodeToUnicode::CharCodeToUnicode(const std::optional<std::string> &tagA, Unicode *mapA, CharCode mapLenA, bool copyMap, std::vector<CharCodeToUnicodeString> &&sMapA) : tag(tagA) | ||
216 | { | ||
217 | mapLen = mapLenA; | ||
218 | if (copyMap) { | ||
219 | @@ -591,9 +567,7 @@ CharCodeToUnicode::CharCodeToUnicode(const std::optional<std::string> &tagA, Uni | ||
220 | } else { | ||
221 | map = mapA; | ||
222 | } | ||
223 | - sMap = sMapA; | ||
224 | - sMapLen = sMapLenA; | ||
225 | - sMapSize = sMapSizeA; | ||
226 | + sMap = std::move(sMapA); | ||
227 | refCnt = 1; | ||
228 | isIdentity = false; | ||
229 | } | ||
230 | @@ -601,12 +575,6 @@ CharCodeToUnicode::CharCodeToUnicode(const std::optional<std::string> &tagA, Uni | ||
231 | CharCodeToUnicode::~CharCodeToUnicode() | ||
232 | { | ||
233 | gfree(map); | ||
234 | - if (sMap) { | ||
235 | - for (int i = 0; i < sMapLen; ++i) { | ||
236 | - gfree(sMap[i].u); | ||
237 | - } | ||
238 | - gfree(sMap); | ||
239 | - } | ||
240 | } | ||
241 | |||
242 | void CharCodeToUnicode::incRefCnt() | ||
243 | @@ -628,7 +596,8 @@ bool CharCodeToUnicode::match(const GooString *tagA) | ||
244 | |||
245 | void CharCodeToUnicode::setMapping(CharCode c, Unicode *u, int len) | ||
246 | { | ||
247 | - int i, j; | ||
248 | + size_t i; | ||
249 | + int j; | ||
250 | |||
251 | if (!map || isIdentity) { | ||
252 | return; | ||
253 | @@ -636,28 +605,26 @@ void CharCodeToUnicode::setMapping(CharCode c, Unicode *u, int len) | ||
254 | if (len == 1) { | ||
255 | map[c] = u[0]; | ||
256 | } else { | ||
257 | - for (i = 0; i < sMapLen; ++i) { | ||
258 | + std::optional<std::reference_wrapper<CharCodeToUnicodeString>> element; | ||
259 | + for (i = 0; i < sMap.size(); ++i) { | ||
260 | if (sMap[i].c == c) { | ||
261 | - gfree(sMap[i].u); | ||
262 | + sMap[i].u.clear(); | ||
263 | + element = std::ref(sMap[i]); | ||
264 | break; | ||
265 | } | ||
266 | } | ||
267 | - if (i == sMapLen) { | ||
268 | - if (sMapLen == sMapSize) { | ||
269 | - sMapSize += 8; | ||
270 | - sMap = (CharCodeToUnicodeString *)greallocn(sMap, sMapSize, sizeof(CharCodeToUnicodeString)); | ||
271 | - } | ||
272 | - ++sMapLen; | ||
273 | + if (!element) { | ||
274 | + sMap.emplace_back(CharCodeToUnicodeString { c, {} }); | ||
275 | + element = std::ref(sMap.back()); | ||
276 | } | ||
277 | map[c] = 0; | ||
278 | - sMap[i].c = c; | ||
279 | - sMap[i].len = len; | ||
280 | - sMap[i].u = (Unicode *)gmallocn(len, sizeof(Unicode)); | ||
281 | + element->get().c = c; | ||
282 | + element->get().u.reserve(len); | ||
283 | for (j = 0; j < len; ++j) { | ||
284 | if (UnicodeIsValid(u[j])) { | ||
285 | - sMap[i].u[j] = u[j]; | ||
286 | + element->get().u.push_back(u[j]); | ||
287 | } else { | ||
288 | - sMap[i].u[j] = 0xfffd; | ||
289 | + element->get().u.push_back(0xfffd); | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | @@ -665,8 +632,6 @@ void CharCodeToUnicode::setMapping(CharCode c, Unicode *u, int len) | ||
294 | |||
295 | int CharCodeToUnicode::mapToUnicode(CharCode c, Unicode const **u) const | ||
296 | { | ||
297 | - int i; | ||
298 | - | ||
299 | if (isIdentity) { | ||
300 | map[0] = (Unicode)c; | ||
301 | *u = map; | ||
302 | @@ -679,10 +644,10 @@ int CharCodeToUnicode::mapToUnicode(CharCode c, Unicode const **u) const | ||
303 | *u = &map[c]; | ||
304 | return 1; | ||
305 | } | ||
306 | - for (i = sMapLen - 1; i >= 0; --i) { // in reverse so CMap takes precedence | ||
307 | - if (sMap[i].c == c) { | ||
308 | - *u = sMap[i].u; | ||
309 | - return sMap[i].len; | ||
310 | + for (auto i = sMap.size(); i > 0; --i) { // in reverse so CMap takes precedence | ||
311 | + if (sMap[i - 1].c == c) { | ||
312 | + *u = sMap[i - 1].u.data(); | ||
313 | + return sMap[i - 1].u.size(); | ||
314 | } | ||
315 | } | ||
316 | return 0; | ||
317 | @@ -704,24 +669,24 @@ int CharCodeToUnicode::mapToCharCode(const Unicode *u, CharCode *c, int usize) c | ||
318 | } | ||
319 | *c = 'x'; | ||
320 | } else { | ||
321 | - int i, j; | ||
322 | + size_t j; | ||
323 | // for each entry in the sMap | ||
324 | - for (i = 0; i < sMapLen; i++) { | ||
325 | + for (const auto &element : sMap) { | ||
326 | // if the entry's unicode length isn't the same are usize, the strings | ||
327 | // are obviously different | ||
328 | - if (sMap[i].len != usize) { | ||
329 | + if (element.u.size() != size_t(usize)) { | ||
330 | continue; | ||
331 | } | ||
332 | // compare the string char by char | ||
333 | - for (j = 0; j < sMap[i].len; j++) { | ||
334 | - if (sMap[i].u[j] != u[j]) { | ||
335 | + for (j = 0; j < element.u.size(); j++) { | ||
336 | + if (element.u[j] != u[j]) { | ||
337 | break; | ||
338 | } | ||
339 | } | ||
340 | |||
341 | // we have the same strings | ||
342 | - if (j == sMap[i].len) { | ||
343 | - *c = sMap[i].c; | ||
344 | + if (j == element.u.size()) { | ||
345 | + *c = element.c; | ||
346 | return 1; | ||
347 | } | ||
348 | } | ||
349 | diff --git a/poppler/CharCodeToUnicode.h b/poppler/CharCodeToUnicode.h | ||
350 | index 596d44d..9aa2571 100644 | ||
351 | --- a/poppler/CharCodeToUnicode.h | ||
352 | +++ b/poppler/CharCodeToUnicode.h | ||
353 | @@ -33,11 +33,11 @@ | ||
354 | |||
355 | #include <atomic> | ||
356 | #include <optional> | ||
357 | +#include <vector> | ||
358 | |||
359 | #include "poppler-config.h" | ||
360 | #include "CharTypes.h" | ||
361 | |||
362 | -struct CharCodeToUnicodeString; | ||
363 | class GooString; | ||
364 | |||
365 | //------------------------------------------------------------------------ | ||
366 | @@ -100,18 +100,22 @@ public: | ||
367 | CharCode getLength() const { return mapLen; } | ||
368 | |||
369 | private: | ||
370 | + struct CharCodeToUnicodeString | ||
371 | + { | ||
372 | + CharCode c; | ||
373 | + std::vector<Unicode> u; | ||
374 | + }; | ||
375 | bool parseCMap1(int (*getCharFunc)(void *), void *data, int nBits); | ||
376 | void addMapping(CharCode code, char *uStr, int n, int offset); | ||
377 | void addMappingInt(CharCode code, Unicode u); | ||
378 | CharCodeToUnicode(); | ||
379 | explicit CharCodeToUnicode(const std::optional<std::string> &tagA); | ||
380 | - CharCodeToUnicode(const std::optional<std::string> &tagA, Unicode *mapA, CharCode mapLenA, bool copyMap, CharCodeToUnicodeString *sMapA, int sMapLenA, int sMapSizeA); | ||
381 | + CharCodeToUnicode(const std::optional<std::string> &tagA, Unicode *mapA, CharCode mapLenA, bool copyMap, std::vector<CharCodeToUnicodeString> &&sMapA); | ||
382 | |||
383 | const std::optional<std::string> tag; | ||
384 | Unicode *map; | ||
385 | CharCode mapLen; | ||
386 | - CharCodeToUnicodeString *sMap; | ||
387 | - int sMapLen, sMapSize; | ||
388 | + std::vector<CharCodeToUnicodeString> sMap; | ||
389 | std::atomic_int refCnt; | ||
390 | bool isIdentity; | ||
391 | }; | ||
392 | diff --git a/poppler/DateInfo.cc b/poppler/DateInfo.cc | ||
393 | index cdba4ab..28474de 100644 | ||
394 | --- a/poppler/DateInfo.cc | ||
395 | +++ b/poppler/DateInfo.cc | ||
396 | @@ -36,16 +36,14 @@ | ||
397 | /* See PDF Reference 1.3, Section 3.8.2 for PDF Date representation */ | ||
398 | bool parseDateString(const GooString *date, int *year, int *month, int *day, int *hour, int *minute, int *second, char *tz, int *tzHour, int *tzMinute) | ||
399 | { | ||
400 | - Unicode *u; | ||
401 | - int len = TextStringToUCS4(date->toStr(), &u); | ||
402 | + std::vector<Unicode> u = TextStringToUCS4(date->toStr()); | ||
403 | GooString s; | ||
404 | - for (int i = 0; i < len; i++) { | ||
405 | + for (auto &c : u) { | ||
406 | // Ignore any non ASCII characters | ||
407 | - if (u[i] < 128) { | ||
408 | - s.append(u[i]); | ||
409 | + if (c < 128) { | ||
410 | + s.append(c); | ||
411 | } | ||
412 | } | ||
413 | - gfree(u); | ||
414 | const char *dateString = s.c_str(); | ||
415 | |||
416 | if (strlen(dateString) < 2) { | ||
417 | diff --git a/poppler/JSInfo.cc b/poppler/JSInfo.cc | ||
418 | index 29fa707..eaef33e 100644 | ||
419 | --- a/poppler/JSInfo.cc | ||
420 | +++ b/poppler/JSInfo.cc | ||
421 | @@ -38,20 +38,17 @@ JSInfo::~JSInfo() { } | ||
422 | |||
423 | void JSInfo::printJS(const GooString *js) | ||
424 | { | ||
425 | - Unicode *u = nullptr; | ||
426 | char buf[8]; | ||
427 | - int i, n, len; | ||
428 | |||
429 | if (!js || !js->c_str()) { | ||
430 | return; | ||
431 | } | ||
432 | |||
433 | - len = TextStringToUCS4(js->toStr(), &u); | ||
434 | - for (i = 0; i < len; i++) { | ||
435 | - n = uniMap->mapUnicode(u[i], buf, sizeof(buf)); | ||
436 | + std::vector<Unicode> u = TextStringToUCS4(js->toStr()); | ||
437 | + for (auto &c : u) { | ||
438 | + int n = uniMap->mapUnicode(c, buf, sizeof(buf)); | ||
439 | fwrite(buf, 1, n, file); | ||
440 | } | ||
441 | - gfree(u); | ||
442 | } | ||
443 | |||
444 | void JSInfo::scanLinkAction(LinkAction *link, const char *action) | ||
445 | diff --git a/poppler/Outline.cc b/poppler/Outline.cc | ||
446 | index 4c68be9..086c104 100644 | ||
447 | --- a/poppler/Outline.cc | ||
448 | +++ b/poppler/Outline.cc | ||
449 | @@ -407,15 +407,12 @@ OutlineItem::OutlineItem(const Dict *dict, Ref refA, OutlineItem *parentA, XRef | ||
450 | parent = parentA; | ||
451 | xref = xrefA; | ||
452 | doc = docA; | ||
453 | - title = nullptr; | ||
454 | kids = nullptr; | ||
455 | |||
456 | obj1 = dict->lookup("Title"); | ||
457 | if (obj1.isString()) { | ||
458 | const GooString *s = obj1.getString(); | ||
459 | - titleLen = TextStringToUCS4(s->toStr(), &title); | ||
460 | - } else { | ||
461 | - titleLen = 0; | ||
462 | + title = TextStringToUCS4(s->toStr()); | ||
463 | } | ||
464 | |||
465 | obj1 = dict->lookup("Dest"); | ||
466 | @@ -446,9 +443,6 @@ OutlineItem::~OutlineItem() | ||
467 | delete kids; | ||
468 | kids = nullptr; | ||
469 | } | ||
470 | - if (title) { | ||
471 | - gfree(title); | ||
472 | - } | ||
473 | } | ||
474 | |||
475 | std::vector<OutlineItem *> *OutlineItem::readItemList(OutlineItem *parent, const Object *firstItemRef, XRef *xrefA, PDFDoc *docA) | ||
476 | @@ -494,11 +488,9 @@ void OutlineItem::open() | ||
477 | |||
478 | void OutlineItem::setTitle(const std::string &titleA) | ||
479 | { | ||
480 | - gfree(title); | ||
481 | - | ||
482 | Object dict = xref->fetch(ref); | ||
483 | GooString *g = new GooString(titleA); | ||
484 | - titleLen = TextStringToUCS4(g->toStr(), &title); | ||
485 | + title = TextStringToUCS4(g->toStr()); | ||
486 | dict.dictSet("Title", Object(g)); | ||
487 | xref->setModifiedObject(&dict, ref); | ||
488 | } | ||
489 | diff --git a/poppler/Outline.h b/poppler/Outline.h | ||
490 | index a301604..af431f6 100644 | ||
491 | --- a/poppler/Outline.h | ||
492 | +++ b/poppler/Outline.h | ||
493 | @@ -27,6 +27,7 @@ | ||
494 | #define OUTLINE_H | ||
495 | |||
496 | #include <memory> | ||
497 | +#include <vector> | ||
498 | #include "Object.h" | ||
499 | #include "CharTypes.h" | ||
500 | #include "poppler_private_export.h" | ||
501 | @@ -91,9 +92,8 @@ public: | ||
502 | OutlineItem(const OutlineItem &) = delete; | ||
503 | OutlineItem &operator=(const OutlineItem &) = delete; | ||
504 | static std::vector<OutlineItem *> *readItemList(OutlineItem *parent, const Object *firstItemRef, XRef *xrefA, PDFDoc *docA); | ||
505 | - const Unicode *getTitle() const { return title; } | ||
506 | + const std::vector<Unicode> &getTitle() const { return title; } | ||
507 | void setTitle(const std::string &titleA); | ||
508 | - int getTitleLength() const { return titleLen; } | ||
509 | bool setPageDest(int i); | ||
510 | // OutlineItem keeps the ownership of the action | ||
511 | const LinkAction *getAction() const { return action.get(); } | ||
512 | @@ -112,8 +112,7 @@ private: | ||
513 | OutlineItem *parent; | ||
514 | PDFDoc *doc; | ||
515 | XRef *xref; | ||
516 | - Unicode *title; | ||
517 | - int titleLen; | ||
518 | + std::vector<Unicode> title; | ||
519 | std::unique_ptr<LinkAction> action; | ||
520 | bool startsOpen; | ||
521 | std::vector<OutlineItem *> *kids; // nullptr if this item is closed or has no kids | ||
522 | diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc | ||
523 | index 06fc307..ee11fcb 100644 | ||
524 | --- a/poppler/TextOutputDev.cc | ||
525 | +++ b/poppler/TextOutputDev.cc | ||
526 | @@ -5668,15 +5668,11 @@ void ActualText::end(const GfxState *state) | ||
527 | // extents of all the glyphs inside the span | ||
528 | |||
529 | if (actualTextNBytes) { | ||
530 | - Unicode *uni = nullptr; | ||
531 | - int length; | ||
532 | - | ||
533 | // now that we have the position info for all of the text inside | ||
534 | // the marked content span, we feed the "ActualText" back through | ||
535 | // text->addChar() | ||
536 | - length = TextStringToUCS4(actualText->toStr(), &uni); | ||
537 | - text->addChar(state, actualTextX0, actualTextY0, actualTextX1 - actualTextX0, actualTextY1 - actualTextY0, 0, actualTextNBytes, uni, length); | ||
538 | - gfree(uni); | ||
539 | + std::vector<Unicode> uni = TextStringToUCS4(actualText->toStr()); | ||
540 | + text->addChar(state, actualTextX0, actualTextY0, actualTextX1 - actualTextX0, actualTextY1 - actualTextY0, 0, actualTextNBytes, uni.data(), uni.size()); | ||
541 | } | ||
542 | |||
543 | delete actualText; | ||
544 | diff --git a/poppler/UTF.cc b/poppler/UTF.cc | ||
545 | index 9b1bf95..eb542eb 100644 | ||
546 | --- a/poppler/UTF.cc | ||
547 | +++ b/poppler/UTF.cc | ||
548 | @@ -42,65 +42,52 @@ bool UnicodeIsValid(Unicode ucs4) | ||
549 | return (ucs4 < 0x110000) && ((ucs4 & 0xfffff800) != 0xd800) && (ucs4 < 0xfdd0 || ucs4 > 0xfdef) && ((ucs4 & 0xfffe) != 0xfffe); | ||
550 | } | ||
551 | |||
552 | -int UTF16toUCS4(const Unicode *utf16, int utf16Len, Unicode **ucs4_out) | ||
553 | +std::vector<Unicode> UTF16toUCS4(const Unicode *utf16, int utf16Len) | ||
554 | { | ||
555 | - int i, n, len; | ||
556 | - Unicode *u; | ||
557 | - | ||
558 | // count characters | ||
559 | - len = 0; | ||
560 | - for (i = 0; i < utf16Len; i++) { | ||
561 | + int len = 0; | ||
562 | + for (int i = 0; i < utf16Len; i++) { | ||
563 | if (utf16[i] >= 0xd800 && utf16[i] < 0xdc00 && i + 1 < utf16Len && utf16[i + 1] >= 0xdc00 && utf16[i + 1] < 0xe000) { | ||
564 | i++; /* surrogate pair */ | ||
565 | } | ||
566 | len++; | ||
567 | } | ||
568 | - if (ucs4_out == nullptr) { | ||
569 | - return len; | ||
570 | - } | ||
571 | - | ||
572 | - u = (Unicode *)gmallocn(len, sizeof(Unicode)); | ||
573 | - n = 0; | ||
574 | + std::vector<Unicode> u; | ||
575 | + u.reserve(len); | ||
576 | // convert string | ||
577 | - for (i = 0; i < utf16Len; i++) { | ||
578 | + for (int i = 0; i < utf16Len; i++) { | ||
579 | if (utf16[i] >= 0xd800 && utf16[i] < 0xdc00) { /* surrogate pair */ | ||
580 | if (i + 1 < utf16Len && utf16[i + 1] >= 0xdc00 && utf16[i + 1] < 0xe000) { | ||
581 | /* next code is a low surrogate */ | ||
582 | - u[n] = (((utf16[i] & 0x3ff) << 10) | (utf16[i + 1] & 0x3ff)) + 0x10000; | ||
583 | + u.push_back((((utf16[i] & 0x3ff) << 10) | (utf16[i + 1] & 0x3ff)) + 0x10000); | ||
584 | ++i; | ||
585 | } else { | ||
586 | /* missing low surrogate | ||
587 | replace it with REPLACEMENT CHARACTER (U+FFFD) */ | ||
588 | - u[n] = 0xfffd; | ||
589 | + u.push_back(0xfffd); | ||
590 | } | ||
591 | } else if (utf16[i] >= 0xdc00 && utf16[i] < 0xe000) { | ||
592 | /* invalid low surrogate | ||
593 | replace it with REPLACEMENT CHARACTER (U+FFFD) */ | ||
594 | - u[n] = 0xfffd; | ||
595 | + u.push_back(0xfffd); | ||
596 | } else { | ||
597 | - u[n] = utf16[i]; | ||
598 | + u.push_back(utf16[i]); | ||
599 | } | ||
600 | - if (!UnicodeIsValid(u[n])) { | ||
601 | - u[n] = 0xfffd; | ||
602 | + if (!UnicodeIsValid(u.back())) { | ||
603 | + u.back() = 0xfffd; | ||
604 | } | ||
605 | - n++; | ||
606 | } | ||
607 | - *ucs4_out = u; | ||
608 | - return len; | ||
609 | + return u; | ||
610 | } | ||
611 | |||
612 | -int TextStringToUCS4(const std::string &textStr, Unicode **ucs4) | ||
613 | +std::vector<Unicode> TextStringToUCS4(const std::string &textStr) | ||
614 | { | ||
615 | - int i, len; | ||
616 | - const char *s; | ||
617 | - Unicode *u; | ||
618 | bool isUnicode, isUnicodeLE; | ||
619 | |||
620 | - len = textStr.size(); | ||
621 | - s = textStr.c_str(); | ||
622 | + int len = textStr.size(); | ||
623 | + const std::string &s = textStr; | ||
624 | if (len == 0) { | ||
625 | - *ucs4 = nullptr; | ||
626 | - return 0; | ||
627 | + return {}; | ||
628 | } | ||
629 | |||
630 | if (GooString::hasUnicodeMarker(textStr)) { | ||
631 | @@ -115,30 +102,30 @@ int TextStringToUCS4(const std::string &textStr, Unicode **ucs4) | ||
632 | } | ||
633 | |||
634 | if (isUnicode || isUnicodeLE) { | ||
635 | - Unicode *utf16; | ||
636 | len = len / 2 - 1; | ||
637 | if (len > 0) { | ||
638 | - utf16 = new Unicode[len]; | ||
639 | - for (i = 0; i < len; i++) { | ||
640 | + std::vector<Unicode> utf16; | ||
641 | + utf16.reserve(len); | ||
642 | + for (int i = 0; i < len; i++) { | ||
643 | if (isUnicode) { | ||
644 | - utf16[i] = (s[2 + i * 2] & 0xff) << 8 | (s[3 + i * 2] & 0xff); | ||
645 | + utf16.push_back((s[2 + i * 2] & 0xff) << 8 | (s[3 + i * 2] & 0xff)); | ||
646 | } else { // UnicodeLE | ||
647 | - utf16[i] = (s[3 + i * 2] & 0xff) << 8 | (s[2 + i * 2] & 0xff); | ||
648 | + utf16.push_back((s[3 + i * 2] & 0xff) << 8 | (s[2 + i * 2] & 0xff)); | ||
649 | } | ||
650 | } | ||
651 | - len = UTF16toUCS4(utf16, len, &u); | ||
652 | - delete[] utf16; | ||
653 | + return UTF16toUCS4(utf16.data(), utf16.size()); | ||
654 | + | ||
655 | } else { | ||
656 | - u = nullptr; | ||
657 | + return {}; | ||
658 | } | ||
659 | } else { | ||
660 | - u = (Unicode *)gmallocn(len, sizeof(Unicode)); | ||
661 | - for (i = 0; i < len; i++) { | ||
662 | - u[i] = pdfDocEncoding[s[i] & 0xff]; | ||
663 | + std::vector<Unicode> u; | ||
664 | + u.reserve(len); | ||
665 | + for (int i = 0; i < len; i++) { | ||
666 | + u.push_back(pdfDocEncoding[s[i] & 0xff]); | ||
667 | } | ||
668 | + return u; | ||
669 | } | ||
670 | - *ucs4 = u; | ||
671 | - return len; | ||
672 | } | ||
673 | |||
674 | bool UnicodeIsWhitespace(Unicode ucs4) | ||
675 | @@ -549,7 +536,10 @@ void unicodeToAscii7(const Unicode *in, int len, Unicode **ucs4_out, int *out_le | ||
676 | } | ||
677 | } | ||
678 | |||
679 | - *out_len = TextStringToUCS4(str, ucs4_out); | ||
680 | + std::vector<Unicode> ucs4 = TextStringToUCS4(str); | ||
681 | + *out_len = ucs4.size(); | ||
682 | + *ucs4_out = (Unicode *)gmallocn(ucs4.size(), sizeof(Unicode)); | ||
683 | + memcpy(*ucs4_out, ucs4.data(), ucs4.size() * sizeof(Unicode)); | ||
684 | |||
685 | if (indices) { | ||
686 | idx[k] = in_idx[len]; | ||
687 | diff --git a/poppler/UTF.h b/poppler/UTF.h | ||
688 | index 626c686..bfc5f65 100644 | ||
689 | --- a/poppler/UTF.h | ||
690 | +++ b/poppler/UTF.h | ||
691 | @@ -19,6 +19,7 @@ | ||
692 | #include <cstdint> | ||
693 | #include <climits> | ||
694 | #include <memory> | ||
695 | +#include <vector> | ||
696 | |||
697 | #include "goo/GooString.h" | ||
698 | #include "CharTypes.h" | ||
699 | @@ -27,16 +28,14 @@ | ||
700 | // Convert a UTF-16 string to a UCS-4 | ||
701 | // utf16 - utf16 bytes | ||
702 | // utf16_len - number of UTF-16 characters | ||
703 | -// ucs4_out - if not NULL, allocates and returns UCS-4 string. Free with gfree. | ||
704 | // returns number of UCS-4 characters | ||
705 | -int UTF16toUCS4(const Unicode *utf16, int utf16Len, Unicode **ucs4_out); | ||
706 | +std::vector<Unicode> UTF16toUCS4(const Unicode *utf16, int utf16Len); | ||
707 | |||
708 | // Convert a PDF Text String to UCS-4 | ||
709 | // s - PDF text string | ||
710 | -// ucs4 - if the number of UCS-4 characters is > 0, allocates and | ||
711 | -// returns UCS-4 string. Free with gfree. | ||
712 | -// returns number of UCS-4 characters | ||
713 | -int POPPLER_PRIVATE_EXPORT TextStringToUCS4(const std::string &textStr, Unicode **ucs4); | ||
714 | +// returns UCS-4 characters | ||
715 | +// Convert a PDF text string to UCS-4 | ||
716 | +std::vector<Unicode> POPPLER_PRIVATE_EXPORT TextStringToUCS4(const std::string &textStr); | ||
717 | |||
718 | // check if UCS-4 character is valid | ||
719 | bool UnicodeIsValid(Unicode ucs4); | ||
720 | diff --git a/qt5/src/poppler-outline.cc b/qt5/src/poppler-outline.cc | ||
721 | index 5ff7e37..2f6ef2d 100644 | ||
722 | --- a/qt5/src/poppler-outline.cc | ||
723 | +++ b/qt5/src/poppler-outline.cc | ||
724 | @@ -78,7 +78,7 @@ QString OutlineItem::name() const | ||
725 | |||
726 | if (name.isEmpty()) { | ||
727 | if (const ::OutlineItem *data = m_data->data) { | ||
728 | - name = unicodeToQString(data->getTitle(), data->getTitleLength()); | ||
729 | + name = unicodeToQString(data->getTitle()); | ||
730 | } | ||
731 | } | ||
732 | |||
733 | diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc | ||
734 | index 228d8e8..54df79f 100644 | ||
735 | --- a/qt5/src/poppler-private.cc | ||
736 | +++ b/qt5/src/poppler-private.cc | ||
737 | @@ -94,6 +94,11 @@ QString unicodeToQString(const Unicode *u, int len) | ||
738 | return QString::fromUtf8(convertedStr.c_str(), convertedStr.getLength()); | ||
739 | } | ||
740 | |||
741 | +QString unicodeToQString(const std::vector<Unicode> &u) | ||
742 | +{ | ||
743 | + return unicodeToQString(u.data(), u.size()); | ||
744 | +} | ||
745 | + | ||
746 | QString UnicodeParsedString(const GooString *s1) | ||
747 | { | ||
748 | return (s1) ? UnicodeParsedString(s1->toStr()) : QString(); | ||
749 | @@ -266,13 +271,7 @@ void DocumentData::addTocChildren(QDomDocument *docSyn, QDomNode *parent, const | ||
750 | // iterate over every object in 'items' | ||
751 | |||
752 | // 1. create element using outlineItem's title as tagName | ||
753 | - QString name; | ||
754 | - const Unicode *uniChar = outlineItem->getTitle(); | ||
755 | - int titleLength = outlineItem->getTitleLength(); | ||
756 | - name = unicodeToQString(uniChar, titleLength); | ||
757 | - if (name.isEmpty()) { | ||
758 | - continue; | ||
759 | - } | ||
760 | + QString name = unicodeToQString(outlineItem->getTitle()); | ||
761 | |||
762 | QDomElement item = docSyn->createElement(name); | ||
763 | parent->appendChild(item); | ||
764 | diff --git a/qt5/src/poppler-private.h b/qt5/src/poppler-private.h | ||
765 | index 39dfb6b..bba5bd7 100644 | ||
766 | --- a/qt5/src/poppler-private.h | ||
767 | +++ b/qt5/src/poppler-private.h | ||
768 | @@ -73,6 +73,7 @@ namespace Poppler { | ||
769 | |||
770 | /* borrowed from kpdf */ | ||
771 | POPPLER_QT5_EXPORT QString unicodeToQString(const Unicode *u, int len); | ||
772 | +POPPLER_QT5_EXPORT QString unicodeToQString(const std::vector<Unicode> &u); | ||
773 | |||
774 | POPPLER_QT5_EXPORT QString UnicodeParsedString(const GooString *s1); | ||
775 | |||
776 | diff --git a/qt5/tests/check_internal_outline.cpp b/qt5/tests/check_internal_outline.cpp | ||
777 | index c12b604..5db6bf4 100644 | ||
778 | --- a/qt5/tests/check_internal_outline.cpp | ||
779 | +++ b/qt5/tests/check_internal_outline.cpp | ||
780 | @@ -56,10 +56,10 @@ void TestInternalOutline::testCreateOutline() | ||
781 | |||
782 | static std::string getTitle(const OutlineItem *item) | ||
783 | { | ||
784 | - const Unicode *u = item->getTitle(); | ||
785 | + std::vector<Unicode> u = item->getTitle(); | ||
786 | std::string s; | ||
787 | - for (int i = 0; i < item->getTitleLength(); i++) { | ||
788 | - s.append(1, (char)u[i]); | ||
789 | + for (auto &c : u) { | ||
790 | + s.append(1, (char)(c)); | ||
791 | } | ||
792 | return s; | ||
793 | } | ||
794 | diff --git a/qt5/tests/check_utf_conversion.cpp b/qt5/tests/check_utf_conversion.cpp | ||
795 | index 73c684e..b00f080 100644 | ||
796 | --- a/qt5/tests/check_utf_conversion.cpp | ||
797 | +++ b/qt5/tests/check_utf_conversion.cpp | ||
798 | @@ -133,16 +133,13 @@ void TestUTFConversion::testUnicodeToAscii7() | ||
799 | // malloc() always returns 8-byte aligned memory addresses. | ||
800 | GooString *goo = Poppler::QStringToUnicodeGooString(QString::fromUtf8("®©©©©©©©©©©©©©©©©©©©©")); // clazy:exclude=qstring-allocations | ||
801 | |||
802 | - Unicode *in; | ||
803 | - const int in_len = TextStringToUCS4(goo->toStr(), &in); | ||
804 | + const std::vector<Unicode> in = TextStringToUCS4(goo->toStr()); | ||
805 | |||
806 | delete goo; | ||
807 | |||
808 | int in_norm_len; | ||
809 | int *in_norm_idx; | ||
810 | - Unicode *in_norm = unicodeNormalizeNFKC(in, in_len, &in_norm_len, &in_norm_idx, true); | ||
811 | - | ||
812 | - free(in); | ||
813 | + Unicode *in_norm = unicodeNormalizeNFKC(in.data(), in.size(), &in_norm_len, &in_norm_idx, true); | ||
814 | |||
815 | Unicode *out; | ||
816 | int out_len; | ||
817 | @@ -174,25 +171,24 @@ void TestUTFConversion::testUnicodeLittleEndian() | ||
818 | // Let's assert both GooString's are different | ||
819 | QVERIFY(GooUTF16LE != GooUTF16BE); | ||
820 | |||
821 | - Unicode *UCS4fromLE, *UCS4fromBE; | ||
822 | - const int len1 = TextStringToUCS4(GooUTF16LE, &UCS4fromLE); | ||
823 | - const int len2 = TextStringToUCS4(GooUTF16BE, &UCS4fromBE); | ||
824 | + const std::vector<Unicode> UCS4fromLE = TextStringToUCS4(GooUTF16LE); | ||
825 | + const std::vector<Unicode> UCS4fromBE = TextStringToUCS4(GooUTF16BE); | ||
826 | |||
827 | // len is 4 because TextStringToUCS4() removes the two leading Byte Order Mark (BOM) code points | ||
828 | - QCOMPARE(len1, len2); | ||
829 | - QCOMPARE(len1, 4); | ||
830 | + QCOMPARE(UCS4fromLE.size(), UCS4fromBE.size()); | ||
831 | + QCOMPARE(UCS4fromLE.size(), 4); | ||
832 | |||
833 | // Check that now after conversion, UCS4fromLE and UCS4fromBE are now the same | ||
834 | - for (int i = 0; i < len1; i++) { | ||
835 | + for (size_t i = 0; i < UCS4fromLE.size(); i++) { | ||
836 | QCOMPARE(UCS4fromLE[i], UCS4fromBE[i]); | ||
837 | } | ||
838 | |||
839 | const QString expected = QString::fromUtf8("HI!☑"); // clazy:exclude=qstring-allocations | ||
840 | |||
841 | // Do some final verifications, checking the strings to be "HI!" | ||
842 | - QVERIFY(*UCS4fromLE == *UCS4fromBE); | ||
843 | - QVERIFY(compare(UCS4fromLE, expected.utf16(), len1)); | ||
844 | - QVERIFY(compare(UCS4fromBE, expected.utf16(), len1)); | ||
845 | + QVERIFY(UCS4fromLE == UCS4fromBE); | ||
846 | + QVERIFY(compare(UCS4fromLE.data(), expected.utf16(), UCS4fromLE.size())); | ||
847 | + QVERIFY(compare(UCS4fromBE.data(), expected.utf16(), UCS4fromLE.size())); | ||
848 | } | ||
849 | |||
850 | QTEST_GUILESS_MAIN(TestUTFConversion) | ||
851 | diff --git a/qt6/src/poppler-outline.cc b/qt6/src/poppler-outline.cc | ||
852 | index f5ba2a9..2bc0d30 100644 | ||
853 | --- a/qt6/src/poppler-outline.cc | ||
854 | +++ b/qt6/src/poppler-outline.cc | ||
855 | @@ -78,7 +78,7 @@ QString OutlineItem::name() const | ||
856 | |||
857 | if (name.isEmpty()) { | ||
858 | if (const ::OutlineItem *data = m_data->data) { | ||
859 | - name = unicodeToQString(data->getTitle(), data->getTitleLength()); | ||
860 | + name = unicodeToQString(data->getTitle()); | ||
861 | } | ||
862 | } | ||
863 | |||
864 | diff --git a/qt6/src/poppler-private.cc b/qt6/src/poppler-private.cc | ||
865 | index 91d1725..2cb2396 100644 | ||
866 | --- a/qt6/src/poppler-private.cc | ||
867 | +++ b/qt6/src/poppler-private.cc | ||
868 | @@ -94,6 +94,11 @@ QString unicodeToQString(const Unicode *u, int len) | ||
869 | return QString::fromUtf8(convertedStr.c_str(), convertedStr.getLength()); | ||
870 | } | ||
871 | |||
872 | +QString unicodeToQString(const std::vector<Unicode> &u) | ||
873 | +{ | ||
874 | + return unicodeToQString(u.data(), u.size()); | ||
875 | +} | ||
876 | + | ||
877 | QString UnicodeParsedString(const GooString *s1) | ||
878 | { | ||
879 | return (s1) ? UnicodeParsedString(s1->toStr()) : QString(); | ||
880 | diff --git a/qt6/src/poppler-private.h b/qt6/src/poppler-private.h | ||
881 | index d1f7335..a3117a6 100644 | ||
882 | --- a/qt6/src/poppler-private.h | ||
883 | +++ b/qt6/src/poppler-private.h | ||
884 | @@ -72,6 +72,7 @@ namespace Poppler { | ||
885 | |||
886 | /* borrowed from kpdf */ | ||
887 | POPPLER_QT6_EXPORT QString unicodeToQString(const Unicode *u, int len); | ||
888 | +POPPLER_QT6_EXPORT QString unicodeToQString(const std::vector<Unicode> &u); | ||
889 | |||
890 | POPPLER_QT6_EXPORT QString UnicodeParsedString(const GooString *s1); | ||
891 | |||
892 | diff --git a/qt6/tests/check_internal_outline.cpp b/qt6/tests/check_internal_outline.cpp | ||
893 | index c12b604..d23e773 100644 | ||
894 | --- a/qt6/tests/check_internal_outline.cpp | ||
895 | +++ b/qt6/tests/check_internal_outline.cpp | ||
896 | @@ -56,10 +56,10 @@ void TestInternalOutline::testCreateOutline() | ||
897 | |||
898 | static std::string getTitle(const OutlineItem *item) | ||
899 | { | ||
900 | - const Unicode *u = item->getTitle(); | ||
901 | + const std::vector<Unicode> &u = item->getTitle(); | ||
902 | std::string s; | ||
903 | - for (int i = 0; i < item->getTitleLength(); i++) { | ||
904 | - s.append(1, (char)u[i]); | ||
905 | + for (const auto &c : u) { | ||
906 | + s.append(1, (char)(c)); | ||
907 | } | ||
908 | return s; | ||
909 | } | ||
910 | diff --git a/qt6/tests/check_utf_conversion.cpp b/qt6/tests/check_utf_conversion.cpp | ||
911 | index 2cac758..e7f35ea 100644 | ||
912 | --- a/qt6/tests/check_utf_conversion.cpp | ||
913 | +++ b/qt6/tests/check_utf_conversion.cpp | ||
914 | @@ -131,16 +131,13 @@ void TestUTFConversion::testUnicodeToAscii7() | ||
915 | // malloc() always returns 8-byte aligned memory addresses. | ||
916 | GooString *goo = Poppler::QStringToUnicodeGooString(QString::fromUtf8("®©©©©©©©©©©©©©©©©©©©©")); // clazy:exclude=qstring-allocations | ||
917 | |||
918 | - Unicode *in; | ||
919 | - const int in_len = TextStringToUCS4(goo->toStr(), &in); | ||
920 | + const std::vector<Unicode> in = TextStringToUCS4(goo->toStr()); | ||
921 | |||
922 | delete goo; | ||
923 | |||
924 | int in_norm_len; | ||
925 | int *in_norm_idx; | ||
926 | - Unicode *in_norm = unicodeNormalizeNFKC(in, in_len, &in_norm_len, &in_norm_idx, true); | ||
927 | - | ||
928 | - free(in); | ||
929 | + Unicode *in_norm = unicodeNormalizeNFKC(in.data(), in.size(), &in_norm_len, &in_norm_idx, true); | ||
930 | |||
931 | Unicode *out; | ||
932 | int out_len; | ||
933 | @@ -172,25 +169,24 @@ void TestUTFConversion::testUnicodeLittleEndian() | ||
934 | // Let's assert both GooString's are different | ||
935 | QVERIFY(GooUTF16LE != GooUTF16BE); | ||
936 | |||
937 | - Unicode *UCS4fromLE, *UCS4fromBE; | ||
938 | - const int len1 = TextStringToUCS4(GooUTF16LE, &UCS4fromLE); | ||
939 | - const int len2 = TextStringToUCS4(GooUTF16BE, &UCS4fromBE); | ||
940 | + const std::vector<Unicode> UCS4fromLE = TextStringToUCS4(GooUTF16LE); | ||
941 | + const std::vector<Unicode> UCS4fromBE = TextStringToUCS4(GooUTF16BE); | ||
942 | |||
943 | // len is 4 because TextStringToUCS4() removes the two leading Byte Order Mark (BOM) code points | ||
944 | - QCOMPARE(len1, len2); | ||
945 | - QCOMPARE(len1, 4); | ||
946 | + QCOMPARE(UCS4fromLE.size(), UCS4fromBE.size()); | ||
947 | + QCOMPARE(UCS4fromLE.size(), 4); | ||
948 | |||
949 | // Check that now after conversion, UCS4fromLE and UCS4fromBE are now the same | ||
950 | - for (int i = 0; i < len1; i++) { | ||
951 | + for (size_t i = 0; i < UCS4fromLE.size(); i++) { | ||
952 | QCOMPARE(UCS4fromLE[i], UCS4fromBE[i]); | ||
953 | } | ||
954 | |||
955 | const QString expected = QStringLiteral("HI!☑"); | ||
956 | |||
957 | // Do some final verifications, checking the strings to be "HI!" | ||
958 | - QVERIFY(*UCS4fromLE == *UCS4fromBE); | ||
959 | - QVERIFY(compare(UCS4fromLE, expected.utf16(), len1)); | ||
960 | - QVERIFY(compare(UCS4fromBE, expected.utf16(), len1)); | ||
961 | + QVERIFY(UCS4fromLE == UCS4fromBE); | ||
962 | + QVERIFY(compare(UCS4fromLE.data(), expected.utf16(), UCS4fromLE.size())); | ||
963 | + QVERIFY(compare(UCS4fromBE.data(), expected.utf16(), UCS4fromBE.size())); | ||
964 | } | ||
965 | |||
966 | QTEST_GUILESS_MAIN(TestUTFConversion) | ||
967 | diff --git a/utils/HtmlFonts.cc b/utils/HtmlFonts.cc | ||
968 | index ca7d4a4..9f25621 100644 | ||
969 | --- a/utils/HtmlFonts.cc | ||
970 | +++ b/utils/HtmlFonts.cc | ||
971 | @@ -230,9 +230,9 @@ GooString *HtmlFont::getFullName() | ||
972 | } | ||
973 | |||
974 | // this method if plain wrong todo | ||
975 | -GooString *HtmlFont::HtmlFilter(const Unicode *u, int uLen) | ||
976 | +std::unique_ptr<GooString> HtmlFont::HtmlFilter(const Unicode *u, int uLen) | ||
977 | { | ||
978 | - GooString *tmp = new GooString(); | ||
979 | + auto tmp = std::make_unique<GooString>(); | ||
980 | const UnicodeMap *uMap; | ||
981 | char buf[8]; | ||
982 | int n; | ||
983 | diff --git a/utils/HtmlFonts.h b/utils/HtmlFonts.h | ||
984 | index ca4ae54..74cdca0 100644 | ||
985 | --- a/utils/HtmlFonts.h | ||
986 | +++ b/utils/HtmlFonts.h | ||
987 | @@ -104,7 +104,7 @@ public: | ||
988 | } | ||
989 | const double *getRotMat() const { return rotSkewMat; } | ||
990 | GooString *getFontName(); | ||
991 | - static GooString *HtmlFilter(const Unicode *u, int uLen); // char* s); | ||
992 | + static std::unique_ptr<GooString> HtmlFilter(const Unicode *u, int uLen); // char* s); | ||
993 | bool isEqual(const HtmlFont &x) const; | ||
994 | bool isEqualIgnoreBold(const HtmlFont &x) const; | ||
995 | void print() const { printf("font: %s (%s) %d %s%s\n", FontName->c_str(), familyName.c_str(), size, bold ? "bold " : "", italic ? "italic " : ""); }; | ||
996 | diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc | ||
997 | index 2611e06..b45a5ff 100644 | ||
998 | --- a/utils/HtmlOutputDev.cc | ||
999 | +++ b/utils/HtmlOutputDev.cc | ||
1000 | @@ -124,11 +124,11 @@ static bool debug = false; | ||
1001 | |||
1002 | #if 0 | ||
1003 | static GooString* Dirname(GooString* str){ | ||
1004 | - | ||
1005 | + | ||
1006 | char *p=str->c_str(); | ||
1007 | int len=str->getLength(); | ||
1008 | for (int i=len-1;i>=0;i--) | ||
1009 | - if (*(p+i)==SLASH) | ||
1010 | + if (*(p+i)==SLASH) | ||
1011 | return new GooString(p,i+1); | ||
1012 | return new GooString(); | ||
1013 | } | ||
1014 | @@ -219,14 +219,13 @@ HtmlString::HtmlString(GfxState *state, double fontSize, HtmlFontAccu *_fonts) : | ||
1015 | len = size = 0; | ||
1016 | yxNext = nullptr; | ||
1017 | xyNext = nullptr; | ||
1018 | - htext = new GooString(); | ||
1019 | + htext = std::make_unique<GooString>(); | ||
1020 | dir = textDirUnknown; | ||
1021 | } | ||
1022 | |||
1023 | HtmlString::~HtmlString() | ||
1024 | { | ||
1025 | gfree(text); | ||
1026 | - delete htext; | ||
1027 | gfree(xRight); | ||
1028 | } | ||
1029 | |||
1030 | @@ -345,7 +344,6 @@ void HtmlPage::beginString(GfxState *state, const GooString *s) | ||
1031 | void HtmlPage::conv() | ||
1032 | { | ||
1033 | for (HtmlString *tmp = yxStrings; tmp; tmp = tmp->yxNext) { | ||
1034 | - delete tmp->htext; | ||
1035 | tmp->htext = HtmlFont::HtmlFilter(tmp->text, tmp->len); | ||
1036 | |||
1037 | size_t linkIndex = 0; | ||
1038 | @@ -641,7 +639,7 @@ void HtmlPage::coalesce() | ||
1039 | bool finish_a = switch_links && hlink1 != nullptr; | ||
1040 | bool finish_italic = hfont1->isItalic() && (!hfont2->isItalic() || finish_a); | ||
1041 | bool finish_bold = hfont1->isBold() && (!hfont2->isBold() || finish_a || finish_italic); | ||
1042 | - CloseTags(str1->htext, finish_a, finish_italic, finish_bold); | ||
1043 | + CloseTags(str1->htext.get(), finish_a, finish_italic, finish_bold); | ||
1044 | if (switch_links && hlink2 != nullptr) { | ||
1045 | GooString *ls = hlink2->getLinkStart(); | ||
1046 | str1->htext->append(ls); | ||
1047 | @@ -654,7 +652,7 @@ void HtmlPage::coalesce() | ||
1048 | str1->htext->append("<b>", 3); | ||
1049 | } | ||
1050 | |||
1051 | - str1->htext->append(str2->htext); | ||
1052 | + str1->htext->append(str2->htext.get()); | ||
1053 | // str1 now contains href for link of str2 (if it is defined) | ||
1054 | str1->link = str2->link; | ||
1055 | hfont1 = hfont2; | ||
1056 | @@ -671,7 +669,7 @@ void HtmlPage::coalesce() | ||
1057 | bool finish_a = str1->getLink() != nullptr; | ||
1058 | bool finish_bold = hfont1->isBold(); | ||
1059 | bool finish_italic = hfont1->isItalic(); | ||
1060 | - CloseTags(str1->htext, finish_a, finish_italic, finish_bold); | ||
1061 | + CloseTags(str1->htext.get(), finish_a, finish_italic, finish_bold); | ||
1062 | |||
1063 | str1->xMin = curX; | ||
1064 | str1->yMin = curY; | ||
1065 | @@ -698,14 +696,14 @@ void HtmlPage::coalesce() | ||
1066 | bool finish_bold = hfont1->isBold(); | ||
1067 | bool finish_italic = hfont1->isItalic(); | ||
1068 | bool finish_a = str1->getLink() != nullptr; | ||
1069 | - CloseTags(str1->htext, finish_a, finish_italic, finish_bold); | ||
1070 | + CloseTags(str1->htext.get(), finish_a, finish_italic, finish_bold); | ||
1071 | |||
1072 | #if 0 //~ for debugging | ||
1073 | for (str1 = yxStrings; str1; str1 = str1->yxNext) { | ||
1074 | printf("x=%3d..%3d y=%3d..%3d size=%2d ", | ||
1075 | (int)str1->xMin, (int)str1->xMax, (int)str1->yMin, (int)str1->yMax, | ||
1076 | (int)(str1->yMax - str1->yMin)); | ||
1077 | - printf("'%s'\n", str1->htext->c_str()); | ||
1078 | + printf("'%s'\n", str1->htext->c_str()); | ||
1079 | } | ||
1080 | printf("\n------------------------------------------------------------\n\n"); | ||
1081 | #endif | ||
1082 | @@ -1225,10 +1223,10 @@ void HtmlOutputDev::startPage(int pageNumA, GfxState *state, XRef *xref) | ||
1083 | exit(1); | ||
1084 | } | ||
1085 | delete fname; | ||
1086 | - // if(state->getRotation()!=0) | ||
1087 | + // if(state->getRotation()!=0) | ||
1088 | // fprintf(tin,"ROTATE=%d rotate %d neg %d neg translate\n",state->getRotation(),state->getX1(),-state->getY1()); | ||
1089 | - // else | ||
1090 | - fprintf(tin,"ROTATE=%d neg %d neg translate\n",state->getX1(),state->getY1()); | ||
1091 | + // else | ||
1092 | + fprintf(tin,"ROTATE=%d neg %d neg translate\n",state->getX1(),state->getY1()); | ||
1093 | } | ||
1094 | } | ||
1095 | #endif | ||
1096 | @@ -1723,10 +1721,11 @@ bool HtmlOutputDev::newHtmlOutlineLevel(FILE *output, const std::vector<OutlineI | ||
1097 | fputs("<ul>\n", output); | ||
1098 | |||
1099 | for (OutlineItem *item : *outlines) { | ||
1100 | - GooString *titleStr = HtmlFont::HtmlFilter(item->getTitle(), item->getTitleLength()); | ||
1101 | + const auto &title = item->getTitle(); | ||
1102 | + std::unique_ptr<GooString> titleStr = HtmlFont::HtmlFilter(title.data(), title.size()); | ||
1103 | |||
1104 | GooString *linkName = nullptr; | ||
1105 | - ; | ||
1106 | + | ||
1107 | const int itemPage = getOutlinePageNum(item); | ||
1108 | if (itemPage > 0) { | ||
1109 | /* complex simple | ||
1110 | @@ -1753,12 +1752,13 @@ bool HtmlOutputDev::newHtmlOutlineLevel(FILE *output, const std::vector<OutlineI | ||
1111 | if (linkName) { | ||
1112 | fprintf(output, "<a href=\"%s\">", linkName->c_str()); | ||
1113 | } | ||
1114 | - fputs(titleStr->c_str(), output); | ||
1115 | + if (titleStr) { | ||
1116 | + fputs(titleStr->c_str(), output); | ||
1117 | + } | ||
1118 | if (linkName) { | ||
1119 | fputs("</a>", output); | ||
1120 | delete linkName; | ||
1121 | } | ||
1122 | - delete titleStr; | ||
1123 | atLeastOne = true; | ||
1124 | |||
1125 | item->open(); | ||
1126 | @@ -1778,14 +1778,14 @@ void HtmlOutputDev::newXmlOutlineLevel(FILE *output, const std::vector<OutlineIt | ||
1127 | fputs("<outline>\n", output); | ||
1128 | |||
1129 | for (OutlineItem *item : *outlines) { | ||
1130 | - GooString *titleStr = HtmlFont::HtmlFilter(item->getTitle(), item->getTitleLength()); | ||
1131 | + const std::vector<Unicode> &title = item->getTitle(); | ||
1132 | + auto titleStr = HtmlFont::HtmlFilter(title.data(), title.size()); | ||
1133 | const int itemPage = getOutlinePageNum(item); | ||
1134 | if (itemPage > 0) { | ||
1135 | fprintf(output, "<item page=\"%d\">%s</item>\n", itemPage, titleStr->c_str()); | ||
1136 | } else { | ||
1137 | fprintf(output, "<item>%s</item>\n", titleStr->c_str()); | ||
1138 | } | ||
1139 | - delete titleStr; | ||
1140 | |||
1141 | item->open(); | ||
1142 | if (item->hasKids() && item->getKids()) { | ||
1143 | diff --git a/utils/HtmlOutputDev.h b/utils/HtmlOutputDev.h | ||
1144 | index c7b08d1..e490eff 100644 | ||
1145 | --- a/utils/HtmlOutputDev.h | ||
1146 | +++ b/utils/HtmlOutputDev.h | ||
1147 | @@ -95,7 +95,7 @@ private: | ||
1148 | HtmlString *yxNext; // next string in y-major order | ||
1149 | HtmlString *xyNext; // next string in x-major order | ||
1150 | int fontpos; | ||
1151 | - GooString *htext; | ||
1152 | + std::unique_ptr<GooString> htext; | ||
1153 | int len; // length of text and xRight | ||
1154 | int size; // size of text and xRight arrays | ||
1155 | UnicodeTextDirection dir; // direction (left to right/right to left) | ||
1156 | diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc | ||
1157 | index 1f4ca79..2057d22 100644 | ||
1158 | --- a/utils/pdfinfo.cc | ||
1159 | +++ b/utils/pdfinfo.cc | ||
1160 | @@ -114,14 +114,12 @@ static const ArgDesc argDesc[] = { { "-f", argInt, &firstPage, 0, "first page to | ||
1161 | |||
1162 | static void printTextString(const GooString *s, const UnicodeMap *uMap) | ||
1163 | { | ||
1164 | - Unicode *u; | ||
1165 | char buf[8]; | ||
1166 | - int len = TextStringToUCS4(s->toStr(), &u); | ||
1167 | - for (int i = 0; i < len; i++) { | ||
1168 | - int n = uMap->mapUnicode(u[i], buf, sizeof(buf)); | ||
1169 | + std::vector<Unicode> u = TextStringToUCS4(s->toStr()); | ||
1170 | + for (const auto &c : u) { | ||
1171 | + int n = uMap->mapUnicode(c, buf, sizeof(buf)); | ||
1172 | fwrite(buf, 1, n, stdout); | ||
1173 | } | ||
1174 | - gfree(u); | ||
1175 | } | ||
1176 | |||
1177 | static void printUCS4String(const Unicode *u, int len, const UnicodeMap *uMap) | ||
1178 | diff --git a/utils/pdfsig.cc b/utils/pdfsig.cc | ||
1179 | index 490795f..e15a360 100644 | ||
1180 | --- a/utils/pdfsig.cc | ||
1181 | +++ b/utils/pdfsig.cc | ||
1182 | @@ -224,16 +224,14 @@ static std::string TextStringToUTF8(const std::string &str) | ||
1183 | { | ||
1184 | const UnicodeMap *utf8Map = globalParams->getUtf8Map(); | ||
1185 | |||
1186 | - Unicode *u; | ||
1187 | - const int len = TextStringToUCS4(str, &u); | ||
1188 | + std::vector<Unicode> u = TextStringToUCS4(str); | ||
1189 | |||
1190 | std::string convertedStr; | ||
1191 | - for (int i = 0; i < len; ++i) { | ||
1192 | + for (auto &c : u) { | ||
1193 | char buf[8]; | ||
1194 | - const int n = utf8Map->mapUnicode(u[i], buf, sizeof(buf)); | ||
1195 | + const int n = utf8Map->mapUnicode(c, buf, sizeof(buf)); | ||
1196 | convertedStr.append(buf, n); | ||
1197 | } | ||
1198 | - gfree(u); | ||
1199 | |||
1200 | return convertedStr; | ||
1201 | } | ||
1202 | diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc | ||
1203 | index 97b141a..d7c0889 100644 | ||
1204 | --- a/utils/pdftohtml.cc | ||
1205 | +++ b/utils/pdftohtml.cc | ||
1206 | @@ -99,7 +99,7 @@ static char ownerPassword[33] = ""; | ||
1207 | static char userPassword[33] = ""; | ||
1208 | static bool printVersion = false; | ||
1209 | |||
1210 | -static GooString *getInfoString(Dict *infoDict, const char *key); | ||
1211 | +static std::unique_ptr<GooString> getInfoString(Dict *infoDict, const char *key); | ||
1212 | static GooString *getInfoDate(Dict *infoDict, const char *key); | ||
1213 | |||
1214 | static char textEncName[128] = ""; | ||
1215 | @@ -158,8 +158,11 @@ int main(int argc, char *argv[]) | ||
1216 | { | ||
1217 | std::unique_ptr<PDFDoc> doc; | ||
1218 | GooString *fileName = nullptr; | ||
1219 | - GooString *docTitle = nullptr; | ||
1220 | - GooString *author = nullptr, *keywords = nullptr, *subject = nullptr, *date = nullptr; | ||
1221 | + std::unique_ptr<GooString> docTitle; | ||
1222 | + std::unique_ptr<GooString> author; | ||
1223 | + std::unique_ptr<GooString> keywords; | ||
1224 | + std::unique_ptr<GooString> subject; | ||
1225 | + GooString *date = nullptr; | ||
1226 | GooString *htmlFileName = nullptr; | ||
1227 | HtmlOutputDev *htmlOut = nullptr; | ||
1228 | SplashOutputDev *splashOut = nullptr; | ||
1229 | @@ -317,7 +320,7 @@ int main(int argc, char *argv[]) | ||
1230 | } | ||
1231 | } | ||
1232 | if (!docTitle) { | ||
1233 | - docTitle = new GooString(htmlFileName); | ||
1234 | + docTitle = std::make_unique<GooString>(htmlFileName); | ||
1235 | } | ||
1236 | |||
1237 | if (!singleHtml) { | ||
1238 | @@ -330,16 +333,6 @@ int main(int argc, char *argv[]) | ||
1239 | // write text file | ||
1240 | htmlOut = new HtmlOutputDev(doc->getCatalog(), htmlFileName->c_str(), docTitle->c_str(), author ? author->c_str() : nullptr, keywords ? keywords->c_str() : nullptr, subject ? subject->c_str() : nullptr, date ? date->c_str() : nullptr, | ||
1241 | rawOrder, firstPage, doOutline); | ||
1242 | - delete docTitle; | ||
1243 | - if (author) { | ||
1244 | - delete author; | ||
1245 | - } | ||
1246 | - if (keywords) { | ||
1247 | - delete keywords; | ||
1248 | - } | ||
1249 | - if (subject) { | ||
1250 | - delete subject; | ||
1251 | - } | ||
1252 | if (date) { | ||
1253 | delete date; | ||
1254 | } | ||
1255 | @@ -397,7 +390,7 @@ error: | ||
1256 | return exit_status; | ||
1257 | } | ||
1258 | |||
1259 | -static GooString *getInfoString(Dict *infoDict, const char *key) | ||
1260 | +static std::unique_ptr<GooString> getInfoString(Dict *infoDict, const char *key) | ||
1261 | { | ||
1262 | Object obj; | ||
1263 | // Raw value as read from PDF (may be in pdfDocEncoding or UCS2) | ||
1264 | @@ -406,7 +399,7 @@ static GooString *getInfoString(Dict *infoDict, const char *key) | ||
1265 | Unicode *unicodeString; | ||
1266 | int unicodeLength; | ||
1267 | // Value HTML escaped and converted to desired encoding | ||
1268 | - GooString *encodedString = nullptr; | ||
1269 | + std::unique_ptr<GooString> encodedString; | ||
1270 | // Is rawString UCS2 (as opposed to pdfDocEncoding) | ||
1271 | bool isUnicode; | ||
1272 | |||
1273 | -- | ||
1274 | 2.40.0 | ||
1275 | |||
diff --git a/meta-oe/recipes-support/poppler/poppler/CVE-2024-6239-0002.patch b/meta-oe/recipes-support/poppler/poppler/CVE-2024-6239-0002.patch new file mode 100644 index 0000000000..cb9ef4237c --- /dev/null +++ b/meta-oe/recipes-support/poppler/poppler/CVE-2024-6239-0002.patch | |||
@@ -0,0 +1,111 @@ | |||
1 | From 0554731052d1a97745cb179ab0d45620589dd9c4 Mon Sep 17 00:00:00 2001 | ||
2 | From: Albert Astals Cid <aacid@kde.org> | ||
3 | Date: Fri, 17 Jun 2024 00:54:55 +0200 | ||
4 | Subject: [PATCH] pdfinfo: Fix crash in broken documents when using -dests | ||
5 | |||
6 | CVE: CVE-2024-6239 | ||
7 | Upstream-Status: Backport [https://gitlab.freedesktop.org/poppler/poppler/-/commit/0554731052d1a97745cb179ab0d45620589dd9c4] | ||
8 | |||
9 | Signed-off-by: Yogita Urade <yogita.urade@windriver.com> | ||
10 | --- | ||
11 | utils/pdfinfo.cc | 35 +++++++++++++++-------------------- | ||
12 | 1 file changed, 15 insertions(+), 20 deletions(-) | ||
13 | |||
14 | diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc | ||
15 | index 2057d22..5f96b41 100644 | ||
16 | --- a/utils/pdfinfo.cc | ||
17 | +++ b/utils/pdfinfo.cc | ||
18 | @@ -15,7 +15,7 @@ | ||
19 | // under GPL version 2 or later | ||
20 | // | ||
21 | // Copyright (C) 2006 Dom Lachowicz <cinamod@hotmail.com> | ||
22 | -// Copyright (C) 2007-2010, 2012, 2016-2022 Albert Astals Cid <aacid@kde.org> | ||
23 | +// Copyright (C) 2007-2010, 2012, 2016-2022, 2024 Albert Astals Cid <aacid@kde.org> | ||
24 | // Copyright (C) 2010 Hib Eris <hib@hiberis.nl> | ||
25 | // Copyright (C) 2011 Vittal Aithal <vittal.aithal@cognidox.com> | ||
26 | // Copyright (C) 2012, 2013, 2016-2018, 2021 Adrian Johnson <ajohnson@redneon.com> | ||
27 | @@ -112,16 +112,21 @@ static const ArgDesc argDesc[] = { { "-f", argInt, &firstPage, 0, "first page to | ||
28 | { "-?", argFlag, &printHelp, 0, "print usage information" }, | ||
29 | {} }; | ||
30 | |||
31 | -static void printTextString(const GooString *s, const UnicodeMap *uMap) | ||
32 | +static void printStdTextString(const std::string &s, const UnicodeMap *uMap) | ||
33 | { | ||
34 | char buf[8]; | ||
35 | - std::vector<Unicode> u = TextStringToUCS4(s->toStr()); | ||
36 | + const std::vector<Unicode> u = TextStringToUCS4(s); | ||
37 | for (const auto &c : u) { | ||
38 | int n = uMap->mapUnicode(c, buf, sizeof(buf)); | ||
39 | fwrite(buf, 1, n, stdout); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | +static void printTextString(const GooString *s, const UnicodeMap *uMap) | ||
44 | +{ | ||
45 | + printStdTextString(s->toStr(), uMap); | ||
46 | +} | ||
47 | + | ||
48 | static void printUCS4String(const Unicode *u, int len, const UnicodeMap *uMap) | ||
49 | { | ||
50 | char buf[8]; | ||
51 | @@ -293,11 +298,6 @@ static void printStruct(const StructElement *element, unsigned indent) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | -struct GooStringCompare | ||
56 | -{ | ||
57 | - bool operator()(GooString *lhs, GooString *rhs) const { return lhs->cmp(const_cast<GooString *>(rhs)) < 0; } | ||
58 | -}; | ||
59 | - | ||
60 | static void printLinkDest(const std::unique_ptr<LinkDest> &dest) | ||
61 | { | ||
62 | GooString s; | ||
63 | @@ -368,29 +368,25 @@ static void printLinkDest(const std::unique_ptr<LinkDest> &dest) | ||
64 | |||
65 | static void printDestinations(PDFDoc *doc, const UnicodeMap *uMap) | ||
66 | { | ||
67 | - std::map<Ref, std::map<GooString *, std::unique_ptr<LinkDest>, GooStringCompare>> map; | ||
68 | + std::map<Ref, std::map<std::string, std::unique_ptr<LinkDest>>> map; | ||
69 | |||
70 | int numDests = doc->getCatalog()->numDestNameTree(); | ||
71 | for (int i = 0; i < numDests; i++) { | ||
72 | - GooString *name = new GooString(doc->getCatalog()->getDestNameTreeName(i)); | ||
73 | + const GooString *name = doc->getCatalog()->getDestNameTreeName(i); | ||
74 | std::unique_ptr<LinkDest> dest = doc->getCatalog()->getDestNameTreeDest(i); | ||
75 | - if (dest && dest->isPageRef()) { | ||
76 | + if (name && dest && dest->isPageRef()) { | ||
77 | Ref pageRef = dest->getPageRef(); | ||
78 | - map[pageRef].insert(std::make_pair(name, std::move(dest))); | ||
79 | - } else { | ||
80 | - delete name; | ||
81 | + map[pageRef].insert(std::make_pair(name->toStr(), std::move(dest))); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | numDests = doc->getCatalog()->numDests(); | ||
86 | for (int i = 0; i < numDests; i++) { | ||
87 | - GooString *name = new GooString(doc->getCatalog()->getDestsName(i)); | ||
88 | + const char *name = doc->getCatalog()->getDestsName(i); | ||
89 | std::unique_ptr<LinkDest> dest = doc->getCatalog()->getDestsDest(i); | ||
90 | - if (dest && dest->isPageRef()) { | ||
91 | + if (name && dest && dest->isPageRef()) { | ||
92 | Ref pageRef = dest->getPageRef(); | ||
93 | map[pageRef].insert(std::make_pair(name, std::move(dest))); | ||
94 | - } else { | ||
95 | - delete name; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | @@ -404,9 +400,8 @@ static void printDestinations(PDFDoc *doc, const UnicodeMap *uMap) | ||
100 | printf("%4d ", i); | ||
101 | printLinkDest(it.second); | ||
102 | printf(" \""); | ||
103 | - printTextString(it.first, uMap); | ||
104 | + printStdTextString(it.first, uMap); | ||
105 | printf("\"\n"); | ||
106 | - delete it.first; | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | -- | ||
111 | 2.40.0 | ||
diff --git a/meta-oe/recipes-support/poppler/poppler_23.04.0.bb b/meta-oe/recipes-support/poppler/poppler_23.04.0.bb index f4411e1163..e57760d853 100644 --- a/meta-oe/recipes-support/poppler/poppler_23.04.0.bb +++ b/meta-oe/recipes-support/poppler/poppler_23.04.0.bb | |||
@@ -9,6 +9,8 @@ SRC_URI = "http://poppler.freedesktop.org/${BP}.tar.xz \ | |||
9 | file://0001-cmake-Do-not-use-isystem.patch \ | 9 | file://0001-cmake-Do-not-use-isystem.patch \ |
10 | file://jpeg-stdio.patch \ | 10 | file://jpeg-stdio.patch \ |
11 | file://CVE-2023-34872.patch \ | 11 | file://CVE-2023-34872.patch \ |
12 | file://CVE-2024-6239-0001.patch \ | ||
13 | file://CVE-2024-6239-0002.patch \ | ||
12 | " | 14 | " |
13 | SRC_URI[sha256sum] = "b6d893dc7dcd4138b9e9df59a13c59695e50e80dc5c2cacee0674670693951a1" | 15 | SRC_URI[sha256sum] = "b6d893dc7dcd4138b9e9df59a13c59695e50e80dc5c2cacee0674670693951a1" |
14 | 16 | ||