Skip to content

Commit a72d188

Browse files
Merge pull request #14439 from Snuffleupagus/issue-14438
Ignore Annotations with empty /Rect-entries in the display-layer (issue 14438)
2 parents 78f160b + 08d88a0 commit a72d188

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

src/display/annotation_layer.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ import { XfaLayer } from "./xfa_layer.js";
4040
const DEFAULT_TAB_INDEX = 1000;
4141
const GetElementsByNameSet = new WeakSet();
4242

43+
function getRectDims(rect) {
44+
return {
45+
width: rect[2] - rect[0],
46+
height: rect[3] - rect[1],
47+
};
48+
}
49+
4350
/**
4451
* @typedef {Object} AnnotationElementParameters
4552
* @property {Object} data
@@ -189,8 +196,7 @@ class AnnotationElement {
189196
page = this.page,
190197
viewport = this.viewport;
191198
const container = document.createElement("section");
192-
let width = data.rect[2] - data.rect[0];
193-
let height = data.rect[3] - data.rect[1];
199+
let { width, height } = getRectDims(data.rect);
194200

195201
container.setAttribute("data-annotation-id", data.id);
196202

@@ -1842,8 +1848,7 @@ class LineAnnotationElement extends AnnotationElement {
18421848
// that acts as the trigger for the popup. Only the line itself should
18431849
// trigger the popup, not the entire container.
18441850
const data = this.data;
1845-
const width = data.rect[2] - data.rect[0];
1846-
const height = data.rect[3] - data.rect[1];
1851+
const { width, height } = getRectDims(data.rect);
18471852
const svg = this.svgFactory.create(width, height);
18481853

18491854
// PDF coordinates are calculated from a bottom left origin, so transform
@@ -1888,8 +1893,7 @@ class SquareAnnotationElement extends AnnotationElement {
18881893
// trigger for the popup. Only the square itself should trigger the
18891894
// popup, not the entire container.
18901895
const data = this.data;
1891-
const width = data.rect[2] - data.rect[0];
1892-
const height = data.rect[3] - data.rect[1];
1896+
const { width, height } = getRectDims(data.rect);
18931897
const svg = this.svgFactory.create(width, height);
18941898

18951899
// The browser draws half of the borders inside the square and half of
@@ -1936,8 +1940,7 @@ class CircleAnnotationElement extends AnnotationElement {
19361940
// trigger for the popup. Only the circle itself should trigger the
19371941
// popup, not the entire container.
19381942
const data = this.data;
1939-
const width = data.rect[2] - data.rect[0];
1940-
const height = data.rect[3] - data.rect[1];
1943+
const { width, height } = getRectDims(data.rect);
19411944
const svg = this.svgFactory.create(width, height);
19421945

19431946
// The browser draws half of the borders inside the circle and half of
@@ -1987,8 +1990,7 @@ class PolylineAnnotationElement extends AnnotationElement {
19871990
// trigger for the popup. Only the polyline itself should trigger the
19881991
// popup, not the entire container.
19891992
const data = this.data;
1990-
const width = data.rect[2] - data.rect[0];
1991-
const height = data.rect[3] - data.rect[1];
1993+
const { width, height } = getRectDims(data.rect);
19921994
const svg = this.svgFactory.create(width, height);
19931995

19941996
// Convert the vertices array to a single points string that the SVG
@@ -2076,8 +2078,7 @@ class InkAnnotationElement extends AnnotationElement {
20762078
// Create an invisible polyline with the same points that acts as the
20772079
// trigger for the popup.
20782080
const data = this.data;
2079-
const width = data.rect[2] - data.rect[0];
2080-
const height = data.rect[3] - data.rect[1];
2081+
const { width, height } = getRectDims(data.rect);
20812082
const svg = this.svgFactory.create(width, height);
20822083

20832084
for (const inkList of data.inkLists) {
@@ -2337,6 +2338,10 @@ class AnnotationLayer {
23372338
if (!data) {
23382339
continue;
23392340
}
2341+
const { width, height } = getRectDims(data.rect);
2342+
if (width <= 0 || height <= 0) {
2343+
continue;
2344+
}
23402345
if (data.annotationType === AnnotationType.POPUP) {
23412346
popupAnnotations.push(data);
23422347
continue;

test/pdfs/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
!issue11878.pdf
118118
!issue13916.pdf
119119
!issue14023.pdf
120+
!issue14438.pdf
120121
!bad-PageLabels.pdf
121122
!decodeACSuccessive.pdf
122123
!issue13003.pdf
@@ -500,4 +501,4 @@
500501
!poppler-937-0-fuzzed.pdf
501502
!PDFBOX-3148-2-fuzzed.pdf
502503
!poppler-90-0-fuzzed.pdf
503-
!issue14415.pdf
504+
!issue14415.pdf

test/pdfs/issue14438.pdf

128 KB
Binary file not shown.

test/test_manifest.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -6196,5 +6196,12 @@
61966196
"file": "pdfs/issue14415.pdf",
61976197
"md5": "fa306a250a3d37fe0e7a4b3bba51c91e",
61986198
"type": "text"
6199-
}
6199+
},
6200+
{ "id": "issue14438",
6201+
"file": "pdfs/issue14438.pdf",
6202+
"md5": "c4f5a21bbd6567fe08583fc9d3149a38",
6203+
"rounds": 1,
6204+
"type": "eq",
6205+
"annotations": true
6206+
}
62006207
]

0 commit comments

Comments
 (0)