From 15b3806937343fb742cdea34eafcab8336e8043d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 31 Dec 2018 12:14:33 +0100 Subject: [PATCH 1/2] Actually validate the input in `AnnotationBorderStyle.setStyle` --- src/core/annotation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index cd2dd298e..becd119e6 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -492,11 +492,11 @@ class AnnotationBorderStyle { * * @public * @memberof AnnotationBorderStyle - * @param {Object} style - The style object + * @param {Name} style - The annotation style. * @see {@link shared/util.js} */ setStyle(style) { - if (!style) { + if (!isName(style)) { return; } switch (style.name) { From 76a9580aeb5219df5a5d23557cdeba580ccb2618 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 31 Dec 2018 12:21:28 +0100 Subject: [PATCH 2/2] Ensure that `AnnotationBorderStyle.setWidth` is able to handle the input being a `Name`, to correctly deal with corrupt PDF documents (issue 10385) --- src/core/annotation.js | 5 +++++ test/unit/annotation_spec.js | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/core/annotation.js b/src/core/annotation.js index becd119e6..352aafac0 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -482,6 +482,11 @@ class AnnotationBorderStyle { * @param {integer} width - The width */ setWidth(width) { + // Some corrupt PDF generators may provide the width as a `Name`, + // rather than as a number (fixes issue 10385). + if (isName(width)) { + width = parseFloat(width.name); + } if (Number.isInteger(width)) { this.width = width; } diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 7c83ce53a..0f131a3e4 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -236,6 +236,14 @@ describe('annotation', function() { expect(borderStyle.width).toEqual(1); }); + it('should set/get a valid width, when the input is a `Name` (issue 10385)', + function() { + const borderStyle = new AnnotationBorderStyle(); + borderStyle.setWidth(Name.get('0')); + + expect(borderStyle.width).toEqual(0); + }); + it('should set and get a valid style', function() { const borderStyle = new AnnotationBorderStyle(); borderStyle.setStyle(Name.get('D'));