[poppler] 3 commits - utils/pdfinfo.cc
Albert Astals Cid
aacid at kemper.freedesktop.org
Sat Sep 2 09:55:52 UTC 2017
utils/pdfinfo.cc | 48 +++++++++++++++++++++++++++++-------------------
1 file changed, 29 insertions(+), 19 deletions(-)
New commits:
commit c5487b653b1c37882af32a25296611e64d7ba867
Author: Albert Astals Cid <aacid at kde.org>
Date: Sat Sep 2 11:55:17 2017 +0200
pdfinfo: -dests don't crash in broken documents
That have pages that don't have ref
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index a6f64764..d5e86b3c 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -403,25 +403,27 @@ static void printDestinations(PDFDoc *doc, UnicodeMap *uMap) {
printf("Page Destination Name\n");
for (int i = firstPage; i <= lastPage; i++) {
Ref *ref = doc->getCatalog()->getPageRef(i);
- auto pageDests = map.find(*ref);
- if (pageDests != map.end()) {
- for (auto& it: pageDests->second) {
- it.first->getCString()[4] = 0;
- printf("%4d ", i);
- printLinkDest(it.second);
- printf(" \"");
- Unicode *u;
- char buf[8];
- int n, len;
- len = TextStringToUCS4(it.first, &u);
- for (int i = 0; i < len; i++) {
- n = uMap->mapUnicode(u[i], buf, sizeof(buf));
- fwrite(buf, 1, n, stdout);
+ if (ref) {
+ auto pageDests = map.find(*ref);
+ if (pageDests != map.end()) {
+ for (auto& it: pageDests->second) {
+ it.first->getCString()[4] = 0;
+ printf("%4d ", i);
+ printLinkDest(it.second);
+ printf(" \"");
+ Unicode *u;
+ char buf[8];
+ int n, len;
+ len = TextStringToUCS4(it.first, &u);
+ for (int i = 0; i < len; i++) {
+ n = uMap->mapUnicode(u[i], buf, sizeof(buf));
+ fwrite(buf, 1, n, stdout);
+ }
+ gfree(u);
+ printf("\"\n");
+ delete it.first;
+ delete it.second;
}
- gfree(u);
- printf("\"\n");
- delete it.first;
- delete it.second;
}
}
}
commit 10660b359dc960f4b0f3728243c64eec79c39851
Author: Albert Astals Cid <aacid at kde.org>
Date: Sat Sep 2 11:50:00 2017 +0200
pdfinfo: Fix memory leaks when using -dests
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index 07733128..a6f64764 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -378,10 +378,13 @@ static void printDestinations(PDFDoc *doc, UnicodeMap *uMap) {
int numDests = doc->getCatalog()->numDestNameTree();
for (int i = 0; i < numDests; i++) {
- GooString *name = doc->getCatalog()->getDestNameTreeName(i);
+ GooString *name = new GooString(doc->getCatalog()->getDestNameTreeName(i));
LinkDest *dest = doc->getCatalog()->getDestNameTreeDest(i);
if (dest && dest->isPageRef()) {
map[dest->getPageRef()].insert(std::make_pair(name, dest));
+ } else {
+ delete name;
+ delete dest;
}
}
@@ -391,6 +394,9 @@ static void printDestinations(PDFDoc *doc, UnicodeMap *uMap) {
LinkDest *dest = doc->getCatalog()->getDestsDest(i);
if (dest && dest->isPageRef()) {
map[dest->getPageRef()].insert(std::make_pair(name, dest));
+ } else {
+ delete name;
+ delete dest;
}
}
@@ -414,6 +420,8 @@ static void printDestinations(PDFDoc *doc, UnicodeMap *uMap) {
}
gfree(u);
printf("\"\n");
+ delete it.first;
+ delete it.second;
}
}
}
commit ea6174def73f7478ae76843bb88ef85c5a6150f9
Author: Albert Astals Cid <aacid at kde.org>
Date: Sat Sep 2 11:31:51 2017 +0200
pdfinfo: Fix crash if getDest* returns nullptr
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index f9fde5a3..07733128 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -380,7 +380,7 @@ static void printDestinations(PDFDoc *doc, UnicodeMap *uMap) {
for (int i = 0; i < numDests; i++) {
GooString *name = doc->getCatalog()->getDestNameTreeName(i);
LinkDest *dest = doc->getCatalog()->getDestNameTreeDest(i);
- if (dest->isPageRef()) {
+ if (dest && dest->isPageRef()) {
map[dest->getPageRef()].insert(std::make_pair(name, dest));
}
}
@@ -389,7 +389,7 @@ static void printDestinations(PDFDoc *doc, UnicodeMap *uMap) {
for (int i = 0; i < numDests; i++) {
GooString *name = new GooString(doc->getCatalog()->getDestsName(i));
LinkDest *dest = doc->getCatalog()->getDestsDest(i);
- if (dest->isPageRef()) {
+ if (dest && dest->isPageRef()) {
map[dest->getPageRef()].insert(std::make_pair(name, dest));
}
}
More information about the poppler
mailing list