1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Always prefer abbreviated keys, over full ones, when doing any dictionary lookups (issue 14256)

Note that issue 14256 was specifically about *inline* images, please refer to:
 - https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G7.1852045
 - https://www.pdfa.org/safedocs-unearths-pdf-inline-image-issue/
 - https://pdf-issues.pdfa.org/32000-2-2020/clause08.html#H8.9.7

However, during review of the initial PR in https://github.com/mozilla/pdf.js/pull/14257#issuecomment-964469710, it was suggested that we instead do this *unconditionally for all* dictionary lookups.
In addition to re-ordering the existing call-sites in the `src/core`-code, and adding non-PRODUCTION/TESTING asserts to catch future errors, for consistency a number of existing `if`/`switch`-blocks were re-factored to also check the abbreviated keys first.
This commit is contained in:
Jonas Jenwald 2021-11-09 22:39:21 +01:00
parent 4ee906adf4
commit ea1c348c67
12 changed files with 730 additions and 104 deletions

View file

@ -93,7 +93,7 @@ class PDFImage {
this.image = image;
const dict = image.dict;
const filter = dict.get("Filter");
const filter = dict.get("F", "Filter");
if (isName(filter)) {
switch (filter.name) {
case "JPXDecode":
@ -114,8 +114,8 @@ class PDFImage {
}
// TODO cache rendered images?
let width = dict.get("Width", "W");
let height = dict.get("Height", "H");
let width = dict.get("W", "Width");
let height = dict.get("H", "Height");
if (
Number.isInteger(image.width) &&
@ -139,13 +139,13 @@ class PDFImage {
this.width = width;
this.height = height;
this.interpolate = dict.get("Interpolate", "I");
this.imageMask = dict.get("ImageMask", "IM") || false;
this.interpolate = dict.get("I", "Interpolate");
this.imageMask = dict.get("IM", "ImageMask") || false;
this.matte = dict.get("Matte") || false;
let bitsPerComponent = image.bitsPerComponent;
if (!bitsPerComponent) {
bitsPerComponent = dict.get("BitsPerComponent", "BPC");
bitsPerComponent = dict.get("BPC", "BitsPerComponent");
if (!bitsPerComponent) {
if (this.imageMask) {
bitsPerComponent = 1;
@ -159,7 +159,7 @@ class PDFImage {
this.bpc = bitsPerComponent;
if (!this.imageMask) {
let colorSpace = dict.getRaw("ColorSpace") || dict.getRaw("CS");
let colorSpace = dict.getRaw("CS") || dict.getRaw("ColorSpace");
if (!colorSpace) {
info("JPX images (which do not require color spaces)");
switch (image.numComps) {
@ -174,8 +174,7 @@ class PDFImage {
break;
default:
throw new Error(
`JPX images with ${image.numComps} ` +
"color components not supported."
`JPX images with ${image.numComps} color components not supported.`
);
}
}
@ -189,7 +188,7 @@ class PDFImage {
this.numComps = this.colorSpace.numComps;
}
this.decode = dict.getArray("Decode", "D");
this.decode = dict.getArray("D", "Decode");
this.needsDecode = false;
if (
this.decode &&
@ -226,7 +225,7 @@ class PDFImage {
} else if (mask) {
if (isStream(mask)) {
const maskDict = mask.dict,
imageMask = maskDict.get("ImageMask", "IM");
imageMask = maskDict.get("IM", "ImageMask");
if (!imageMask) {
warn("Ignoring /Mask in image without /ImageMask.");
} else {