Skip to content

Commit

Permalink
Merge pull request #12393 from Snuffleupagus/issue-12392
Browse files Browse the repository at this point in the history
Prevent errors if the `InkList` property, in InkAnnotations, is missing and/or not an Array (issue 12392)
  • Loading branch information
timvandermeij authored Sep 19, 2020
2 parents 26ae7ba + 2497e8e commit c98046e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1974,12 +1974,15 @@ class PolylineAnnotation extends MarkupAnnotation {
super(parameters);

this.data.annotationType = AnnotationType.POLYLINE;
this.data.vertices = [];

// The vertices array is an array of numbers representing the alternating
// horizontal and vertical coordinates, respectively, of each vertex.
// Convert this to an array of objects with x and y coordinates.
const rawVertices = parameters.dict.getArray("Vertices");
this.data.vertices = [];
if (!Array.isArray(rawVertices)) {
return;
}
for (let i = 0, ii = rawVertices.length; i < ii; i += 2) {
this.data.vertices.push({
x: rawVertices[i],
Expand Down Expand Up @@ -2011,20 +2014,23 @@ class InkAnnotation extends MarkupAnnotation {
super(parameters);

this.data.annotationType = AnnotationType.INK;
this.data.inkLists = [];

const rawInkLists = parameters.dict.getArray("InkList");
if (!Array.isArray(rawInkLists)) {
return;
}
const xref = parameters.xref;
const originalInkLists = parameters.dict.getArray("InkList");
this.data.inkLists = [];
for (let i = 0, ii = originalInkLists.length; i < ii; ++i) {
for (let i = 0, ii = rawInkLists.length; i < ii; ++i) {
// The raw ink lists array contains arrays of numbers representing
// the alternating horizontal and vertical coordinates, respectively,
// of each vertex. Convert this to an array of objects with x and y
// coordinates.
this.data.inkLists.push([]);
for (let j = 0, jj = originalInkLists[i].length; j < jj; j += 2) {
for (let j = 0, jj = rawInkLists[i].length; j < jj; j += 2) {
this.data.inkLists[i].push({
x: xref.fetchIfRef(originalInkLists[i][j]),
y: xref.fetchIfRef(originalInkLists[i][j + 1]),
x: xref.fetchIfRef(rawInkLists[i][j]),
y: xref.fetchIfRef(rawInkLists[i][j + 1]),
});
}
}
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue12392.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/5249872/product1.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4235,6 +4235,14 @@
"rounds": 1,
"type": "eq"
},
{ "id": "issue12392",
"file": "pdfs/issue12392.pdf",
"md5": "76c3a34c6520940c45c66c92f7df2de5",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
},
{ "id": "issue4883",
"file": "pdfs/issue4883.pdf",
"md5": "2fac0d9a189ca5fcef8626153d050be8",
Expand Down

0 comments on commit c98046e

Please sign in to comment.