From edc7a41dbbfd71e1fa185e23dc03f022fa137c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Aliste?= Date: Mon, 18 Nov 2013 17:40:07 -0300 Subject: [PATCH] Catalog: sort entries of NameTrees to make sure lookup works Fixes https://bugs.freedesktop.org/show_bug.cgi?id=26049 --- poppler/Catalog.cc | 12 ++++++++++++ poppler/Catalog.h | 1 + 2 files changed, 13 insertions(+) diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc index a06ae5f..744f0b2 100644 --- a/poppler/Catalog.cc +++ b/poppler/Catalog.cc @@ -666,11 +666,23 @@ void NameTree::addEntry(Entry *entry) ++length; } +int NameTree::Entry::cmpEntry(const void *voidEntry, const void *voidOtherEntry) +{ + Entry *entry = *(NameTree::Entry **) voidEntry; + Entry *otherEntry = *(NameTree::Entry **) voidOtherEntry; + + return entry->name.cmp(&otherEntry->name); +} + void NameTree::init(XRef *xrefA, Object *tree) { xref = xrefA; parse(tree); + if (entries && length > 0) { + qsort(entries, length, sizeof(Entry *), Entry::cmpEntry); + } } + void NameTree::parse(Object *tree) { Object names; Object kids, kid; diff --git a/poppler/Catalog.h b/poppler/Catalog.h index 40c783c..c46b66f 100644 --- a/poppler/Catalog.h +++ b/poppler/Catalog.h @@ -80,6 +80,7 @@ private: GooString name; Object value; void free(); + static int cmpEntry(const void *voidEntry, const void *voidOtherEntry); static int cmp(const void *key, const void *entry); }; -- 1.8.4.2