Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that AnnotationBorderStyle.setWidth is able to handle the input being a Name, to correctly deal with corrupt PDF documents (issue 10385) #10397

Merged
merged 2 commits into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -492,11 +497,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) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down