[poppler] 2 commits - poppler/Annot.cc qt5/tests
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jul 1 21:45:27 UTC 2019
poppler/Annot.cc | 5 +++--
qt5/tests/check_annotations.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 2 deletions(-)
New commits:
commit ccfaa9dc0f8929d9ec49d8f49ad017cdd06ee5cb
Author: Tobias Deiminger <haxtibal at posteo.de>
Date: Mon Jul 1 23:23:01 2019 +0200
Add unit test for class DefaultAppearance
diff --git a/qt5/tests/check_annotations.cpp b/qt5/tests/check_annotations.cpp
index 20b33f21..00026f05 100644
--- a/qt5/tests/check_annotations.cpp
+++ b/qt5/tests/check_annotations.cpp
@@ -7,6 +7,7 @@
#include <poppler-qt5.h>
+#include "poppler/Annot.h"
#include "goo/GooString.h"
#include "goo/gstrtod.h"
@@ -21,6 +22,7 @@ private slots:
void checkHighlightFromAndToQuads();
void checkUTF16LEAnnot();
void checkNonMarkupAnnotations();
+ void checkDefaultAppearance();
};
/* Is .5f sufficient for 16 bit color channel roundtrip trough save and load on all architectures? */
@@ -172,6 +174,44 @@ void TestAnnotations::checkNonMarkupAnnotations()
QCOMPARE(annots.size(), 17);
}
+void TestAnnotations::checkDefaultAppearance()
+{
+ std::unique_ptr<GooString> roundtripString;
+ {
+ GooString daString{ "/Helv 10 Tf 0.1 0.2 0.3 rg" };
+ const DefaultAppearance da { &daString };
+ QCOMPARE( da.getFontPtSize(), 10. );
+ QVERIFY( da.getFontName().isName() );
+ QCOMPARE( da.getFontName().getName(), "Helv" );
+ const AnnotColor* color = da.getFontColor();
+ QVERIFY( color );
+ QCOMPARE( color->getSpace(), AnnotColor::colorRGB );
+ QCOMPARE( color->getValues()[0], 0.1 );
+ QCOMPARE( color->getValues()[1], 0.2 );
+ QCOMPARE( color->getValues()[2], 0.3 );
+ roundtripString.reset( da.toAppearanceString() );
+ }
+ {
+ /* roundtrip through parse/generate/parse shall preserve values */
+ const DefaultAppearance da { roundtripString.get() };
+ QCOMPARE( da.getFontPtSize(), 10. );
+ QVERIFY( da.getFontName().isName() );
+ QCOMPARE( da.getFontName().getName(), "Helv" );
+ const AnnotColor* color = da.getFontColor();
+ QVERIFY( color );
+ QCOMPARE( color->getSpace(), AnnotColor::colorRGB );
+ QCOMPARE( color->getValues()[0], 0.1 );
+ QCOMPARE( color->getValues()[1], 0.2 );
+ QCOMPARE( color->getValues()[2], 0.3 );
+ }
+ {
+ /* parsing bad DA strings must not cause crash */
+ GooString daString{ "/ % Tf 1 2 rg" };
+ const DefaultAppearance da { &daString };
+ QVERIFY( !da.getFontName().isName() );
+ }
+}
+
QTEST_GUILESS_MAIN(TestAnnotations)
commit 68b74ab18016520f755bf8bc35e9804fe378ad91
Author: Tobias Deiminger <haxtibal at posteo.de>
Date: Mon Jul 1 23:10:48 2019 +0200
Fix bad cast of GooString* to const char* in DefaultAppearance
Casting GooString* to const char* was probably a reminder from a time
where GooString layout had been under poppler control.
Nowadays GooString derives from std::string and we must not rely upon
the memory layout.
The bug leads to DefaultAppearance::getFontName() always returning an
invalid Object. The offending code is reachable via
AnnotFreeText::generateFreeTextAppearance.
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index bbccd820..0bf9864b 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -753,9 +753,10 @@ DefaultAppearance::DefaultAppearance(GooString *da) {
}
if (i >= 2) {
// We are expecting a name, therefore the first letter should be '/'.
- if ((*daToks)[i-2] && ((const char*)((*daToks)[i-2]))[0] == '/') {
+ const GooString* fontToken = (*daToks)[i-2];
+ if (fontToken && fontToken->getLength() > 1 && fontToken->getChar(0) == '/') {
// The +1 is here to skip the leading '/'.
- fontName = Object(objName, ((const char*)(*daToks)[i-2])+1);
+ fontName = Object(objName, fontToken->c_str() + 1);
}
}
// Scan backwards: we are looking for the last set value
More information about the poppler
mailing list