Merge pull request #9327 from Snuffleupagus/JpegStream-DeviceGray-length

Avoid truncating JPEG images with DeviceGray ColourSpaces when using the `src/core/jpg.js` built-in decoder
This commit is contained in:
Tim van der Meij 2017-12-29 22:31:35 +01:00 committed by GitHub
commit ad0dc7e89a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

View File

@ -546,14 +546,21 @@ var PDFImage = (function PDFImageClosure() {
}
return imgData;
}
if (this.image instanceof JpegStream && !this.smask && !this.mask &&
(this.colorSpace.name === 'DeviceGray' ||
this.colorSpace.name === 'DeviceRGB' ||
this.colorSpace.name === 'DeviceCMYK')) {
imgData.kind = ImageKind.RGB_24BPP;
imgData.data = this.getImageBytes(originalHeight * rowBytes,
drawWidth, drawHeight, true);
return imgData;
if (this.image instanceof JpegStream && !this.smask && !this.mask) {
let imageLength = originalHeight * rowBytes;
switch (this.colorSpace.name) {
case 'DeviceGray':
// Avoid truncating the image, since `JpegImage.getData`
// will expand the image data when `forceRGB === true`.
imageLength *= 3;
/* falls through */
case 'DeviceRGB':
case 'DeviceCMYK':
imgData.kind = ImageKind.RGB_24BPP;
imgData.data = this.getImageBytes(imageLength,
drawWidth, drawHeight, /* forceRGB = */ true);
return imgData;
}
}
}

View File

@ -1318,7 +1318,8 @@
"link": true,
"firstPage": 2,
"lastPage": 2,
"type": "eq"
"type": "eq",
"nativeImageDecoderSupport": "none"
},
{ "id": "issue6071",
"file": "pdfs/issue6071.pdf",