2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-03 19:00:51 +00:00

Correct reversed Rectangle coordinates (fixes #363)

This commit is contained in:
Jay Berkenbilt 2019-09-19 21:03:58 -04:00
parent 48b7de2cc3
commit 685250d7d6
3 changed files with 18 additions and 6 deletions

View File

@ -1,5 +1,9 @@
2019-09-19 Jay Berkenbilt <ejb@ql.org> 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. * Warn when duplicated dictionary keys are found during parsing.
The behavior remains as before: later keys override earlier ones. The behavior remains as before: later keys override earlier ones.
However, this generates a warning now rather than being silently However, this generates a warning now rather than being silently

View File

@ -30,6 +30,7 @@
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
#include <cstring> #include <cstring>
#include <algorithm>
class TerminateParsing class TerminateParsing
{ {
@ -717,10 +718,17 @@ QPDFObjectHandle::getArrayAsRectangle()
Rectangle result; Rectangle result;
if (isRectangle()) if (isRectangle())
{ {
result = Rectangle(getArrayItem(0).getNumericValue(), // Rectangle coordinates are always supposed to be llx, lly,
getArrayItem(1).getNumericValue(), // urx, ury, but files have been found in the wild where
getArrayItem(2).getNumericValue(), // llx > urx or lly > ury.
getArrayItem(3).getNumericValue()); 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; return result;
} }

View File

@ -819,10 +819,10 @@ endobj
/Ff 4096 /Ff 4096
/P 100 0 R /P 100 0 R
/Rect [ /Rect [
294.149
430.251
366.951 366.951
528.249 528.249
294.149
430.251
] ]
/Subtype /Widget /Subtype /Widget
/T (Text Box 3) /T (Text Box 3)