Use a RefSet
, rather than a plain Object, for tracking already processed nodes in PartialEvaluator.hasBlendModes
This commit is contained in:
parent
f20aeb9343
commit
b3480842b3
@ -44,6 +44,7 @@ import {
|
|||||||
isStream,
|
isStream,
|
||||||
Name,
|
Name,
|
||||||
Ref,
|
Ref,
|
||||||
|
RefSet,
|
||||||
} from "./primitives.js";
|
} from "./primitives.js";
|
||||||
import {
|
import {
|
||||||
ErrorFont,
|
ErrorFont,
|
||||||
@ -237,9 +238,9 @@ class PartialEvaluator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var processed = Object.create(null);
|
const processed = new RefSet();
|
||||||
if (resources.objId) {
|
if (resources.objId) {
|
||||||
processed[resources.objId] = true;
|
processed.put(resources.objId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodes = [resources],
|
var nodes = [resources],
|
||||||
@ -252,7 +253,7 @@ class PartialEvaluator {
|
|||||||
for (const key of graphicStates.getKeys()) {
|
for (const key of graphicStates.getKeys()) {
|
||||||
let graphicState = graphicStates.getRaw(key);
|
let graphicState = graphicStates.getRaw(key);
|
||||||
if (graphicState instanceof Ref) {
|
if (graphicState instanceof Ref) {
|
||||||
if (processed[graphicState.toString()]) {
|
if (processed.has(graphicState)) {
|
||||||
continue; // The ExtGState has already been processed.
|
continue; // The ExtGState has already been processed.
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -262,7 +263,7 @@ class PartialEvaluator {
|
|||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
// Avoid parsing a corrupt ExtGState more than once.
|
// Avoid parsing a corrupt ExtGState more than once.
|
||||||
processed[graphicState.toString()] = true;
|
processed.put(graphicState);
|
||||||
|
|
||||||
info(`hasBlendModes - ignoring ExtGState: "${ex}".`);
|
info(`hasBlendModes - ignoring ExtGState: "${ex}".`);
|
||||||
continue;
|
continue;
|
||||||
@ -272,7 +273,7 @@ class PartialEvaluator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (graphicState.objId) {
|
if (graphicState.objId) {
|
||||||
processed[graphicState.objId] = true;
|
processed.put(graphicState.objId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bm = graphicState.get("BM");
|
const bm = graphicState.get("BM");
|
||||||
@ -299,7 +300,7 @@ class PartialEvaluator {
|
|||||||
for (const key of xObjects.getKeys()) {
|
for (const key of xObjects.getKeys()) {
|
||||||
var xObject = xObjects.getRaw(key);
|
var xObject = xObjects.getRaw(key);
|
||||||
if (xObject instanceof Ref) {
|
if (xObject instanceof Ref) {
|
||||||
if (processed[xObject.toString()]) {
|
if (processed.has(xObject)) {
|
||||||
// The XObject has already been processed, and by avoiding a
|
// The XObject has already been processed, and by avoiding a
|
||||||
// redundant `xref.fetch` we can *significantly* reduce the load
|
// redundant `xref.fetch` we can *significantly* reduce the load
|
||||||
// time for badly generated PDF files (fixes issue6961.pdf).
|
// time for badly generated PDF files (fixes issue6961.pdf).
|
||||||
@ -312,7 +313,7 @@ class PartialEvaluator {
|
|||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
// Avoid parsing a corrupt XObject more than once.
|
// Avoid parsing a corrupt XObject more than once.
|
||||||
processed[xObject.toString()] = true;
|
processed.put(xObject);
|
||||||
|
|
||||||
info(`hasBlendModes - ignoring XObject: "${ex}".`);
|
info(`hasBlendModes - ignoring XObject: "${ex}".`);
|
||||||
continue;
|
continue;
|
||||||
@ -322,20 +323,20 @@ class PartialEvaluator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (xObject.dict.objId) {
|
if (xObject.dict.objId) {
|
||||||
processed[xObject.dict.objId] = true;
|
processed.put(xObject.dict.objId);
|
||||||
}
|
}
|
||||||
var xResources = xObject.dict.get("Resources");
|
var xResources = xObject.dict.get("Resources");
|
||||||
if (!(xResources instanceof Dict)) {
|
if (!(xResources instanceof Dict)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Checking objId to detect an infinite loop.
|
// Checking objId to detect an infinite loop.
|
||||||
if (xResources.objId && processed[xResources.objId]) {
|
if (xResources.objId && processed.has(xResources.objId)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.push(xResources);
|
nodes.push(xResources);
|
||||||
if (xResources.objId) {
|
if (xResources.objId) {
|
||||||
processed[xResources.objId] = true;
|
processed.put(xResources.objId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user