diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 9e9cfbcaa..0562ff5c1 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -40,6 +40,13 @@ import { XfaLayer } from "./xfa_layer.js"; const DEFAULT_TAB_INDEX = 1000; const GetElementsByNameSet = new WeakSet(); +function getRectDims(rect) { + return { + width: rect[2] - rect[0], + height: rect[3] - rect[1], + }; +} + /** * @typedef {Object} AnnotationElementParameters * @property {Object} data @@ -189,8 +196,7 @@ class AnnotationElement { page = this.page, viewport = this.viewport; const container = document.createElement("section"); - let width = data.rect[2] - data.rect[0]; - let height = data.rect[3] - data.rect[1]; + let { width, height } = getRectDims(data.rect); container.setAttribute("data-annotation-id", data.id); @@ -1842,8 +1848,7 @@ class LineAnnotationElement extends AnnotationElement { // that acts as the trigger for the popup. Only the line itself should // trigger the popup, not the entire container. const data = this.data; - const width = data.rect[2] - data.rect[0]; - const height = data.rect[3] - data.rect[1]; + const { width, height } = getRectDims(data.rect); const svg = this.svgFactory.create(width, height); // PDF coordinates are calculated from a bottom left origin, so transform @@ -1888,8 +1893,7 @@ class SquareAnnotationElement extends AnnotationElement { // trigger for the popup. Only the square itself should trigger the // popup, not the entire container. const data = this.data; - const width = data.rect[2] - data.rect[0]; - const height = data.rect[3] - data.rect[1]; + const { width, height } = getRectDims(data.rect); const svg = this.svgFactory.create(width, height); // The browser draws half of the borders inside the square and half of @@ -1936,8 +1940,7 @@ class CircleAnnotationElement extends AnnotationElement { // trigger for the popup. Only the circle itself should trigger the // popup, not the entire container. const data = this.data; - const width = data.rect[2] - data.rect[0]; - const height = data.rect[3] - data.rect[1]; + const { width, height } = getRectDims(data.rect); const svg = this.svgFactory.create(width, height); // The browser draws half of the borders inside the circle and half of @@ -1987,8 +1990,7 @@ class PolylineAnnotationElement extends AnnotationElement { // trigger for the popup. Only the polyline itself should trigger the // popup, not the entire container. const data = this.data; - const width = data.rect[2] - data.rect[0]; - const height = data.rect[3] - data.rect[1]; + const { width, height } = getRectDims(data.rect); const svg = this.svgFactory.create(width, height); // Convert the vertices array to a single points string that the SVG @@ -2076,8 +2078,7 @@ class InkAnnotationElement extends AnnotationElement { // Create an invisible polyline with the same points that acts as the // trigger for the popup. const data = this.data; - const width = data.rect[2] - data.rect[0]; - const height = data.rect[3] - data.rect[1]; + const { width, height } = getRectDims(data.rect); const svg = this.svgFactory.create(width, height); for (const inkList of data.inkLists) { @@ -2337,6 +2338,10 @@ class AnnotationLayer { if (!data) { continue; } + const { width, height } = getRectDims(data.rect); + if (width <= 0 || height <= 0) { + continue; + } if (data.annotationType === AnnotationType.POPUP) { popupAnnotations.push(data); continue; diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index e9067c31c..02bb8eaee 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -117,6 +117,7 @@ !issue11878.pdf !issue13916.pdf !issue14023.pdf +!issue14438.pdf !bad-PageLabels.pdf !decodeACSuccessive.pdf !issue13003.pdf @@ -500,4 +501,4 @@ !poppler-937-0-fuzzed.pdf !PDFBOX-3148-2-fuzzed.pdf !poppler-90-0-fuzzed.pdf -!issue14415.pdf \ No newline at end of file +!issue14415.pdf diff --git a/test/pdfs/issue14438.pdf b/test/pdfs/issue14438.pdf new file mode 100644 index 000000000..d4b305468 Binary files /dev/null and b/test/pdfs/issue14438.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index f95c0eb3a..3ca1ee2df 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -6196,5 +6196,12 @@ "file": "pdfs/issue14415.pdf", "md5": "fa306a250a3d37fe0e7a4b3bba51c91e", "type": "text" - } + }, + { "id": "issue14438", + "file": "pdfs/issue14438.pdf", + "md5": "c4f5a21bbd6567fe08583fc9d3149a38", + "rounds": 1, + "type": "eq", + "annotations": true + } ]