aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-09-20 03:03:58 +0200
committerJay Berkenbilt <ejb@ql.org>2019-09-20 03:25:34 +0200
commit685250d7d6cc285be86e2c9e628449b51e08d489 (patch)
tree5fcdc4568088dbd8d85664008b44b634e4b7dc36
parent48b7de2cc3c48bfb30da0bba60e070eac7c8f6fb (diff)
downloadqpdf-685250d7d6cc285be86e2c9e628449b51e08d489.tar.zst
Correct reversed Rectangle coordinates (fixes #363)
-rw-r--r--ChangeLog4
-rw-r--r--libqpdf/QPDFObjectHandle.cc16
-rw-r--r--qpdf/qtest/qpdf/manual-appearances.pdf4
3 files changed, 18 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 5427224e..e40c10d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2019-09-19 Jay Berkenbilt <ejb@ql.org>
+ * When converting an array to a Rectangle, ensure that llx <= urx
+ and lly <= ury. This prevents flatten-annotations from flipping
+ fields whose coordinates are messed up in the input. Fixes #363.
+
* Warn when duplicated dictionary keys are found during parsing.
The behavior remains as before: later keys override earlier ones.
However, this generates a warning now rather than being silently
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 4ee25bc7..e36a7a2a 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -30,6 +30,7 @@
#include <ctype.h>
#include <limits.h>
#include <cstring>
+#include <algorithm>
class TerminateParsing
{
@@ -717,10 +718,17 @@ QPDFObjectHandle::getArrayAsRectangle()
Rectangle result;
if (isRectangle())
{
- result = Rectangle(getArrayItem(0).getNumericValue(),
- getArrayItem(1).getNumericValue(),
- getArrayItem(2).getNumericValue(),
- getArrayItem(3).getNumericValue());
+ // Rectangle coordinates are always supposed to be llx, lly,
+ // urx, ury, but files have been found in the wild where
+ // llx > urx or lly > ury.
+ double i0 = getArrayItem(0).getNumericValue();
+ double i1 = getArrayItem(1).getNumericValue();
+ double i2 = getArrayItem(2).getNumericValue();
+ double i3 = getArrayItem(3).getNumericValue();
+ result = Rectangle(std::min(i0, i2),
+ std::min(i1, i3),
+ std::max(i0, i2),
+ std::max(i1, i3));
}
return result;
}
diff --git a/qpdf/qtest/qpdf/manual-appearances.pdf b/qpdf/qtest/qpdf/manual-appearances.pdf
index dbce982b..bc53a96b 100644
--- a/qpdf/qtest/qpdf/manual-appearances.pdf
+++ b/qpdf/qtest/qpdf/manual-appearances.pdf
@@ -819,10 +819,10 @@ endobj
/Ff 4096
/P 100 0 R
/Rect [
- 294.149
- 430.251
366.951
528.249
+ 294.149
+ 430.251
]
/Subtype /Widget
/T (Text Box 3)