mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Validate even more dictionary properties
This checks primarily Arrays, but also some other properties, that we'll end up sending (sometimes indirectly) to the main-thread.
This commit is contained in:
parent
1b811ac113
commit
52f7ff155d
8 changed files with 125 additions and 64 deletions
|
@ -16,14 +16,19 @@
|
|||
import {
|
||||
assert,
|
||||
FormatError,
|
||||
IDENTITY_MATRIX,
|
||||
info,
|
||||
unreachable,
|
||||
Util,
|
||||
warn,
|
||||
} from "../shared/util.js";
|
||||
import {
|
||||
isBooleanArray,
|
||||
isNumberArray,
|
||||
MissingDataException,
|
||||
} from "./core_utils.js";
|
||||
import { BaseStream } from "./base_stream.js";
|
||||
import { ColorSpace } from "./colorspace.js";
|
||||
import { MissingDataException } from "./core_utils.js";
|
||||
|
||||
const ShadingType = {
|
||||
FUNCTION_BASED: 1,
|
||||
|
@ -106,8 +111,17 @@ class BaseShading {
|
|||
class RadialAxialShading extends BaseShading {
|
||||
constructor(dict, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
|
||||
super();
|
||||
this.coordsArr = dict.getArray("Coords");
|
||||
this.shadingType = dict.get("ShadingType");
|
||||
let coordsLen = 0;
|
||||
if (this.shadingType === ShadingType.AXIAL) {
|
||||
coordsLen = 4;
|
||||
} else if (this.shadingType === ShadingType.RADIAL) {
|
||||
coordsLen = 6;
|
||||
}
|
||||
this.coordsArr = dict.getArray("Coords");
|
||||
if (!isNumberArray(this.coordsArr, coordsLen)) {
|
||||
throw new FormatError("RadialAxialShading: Invalid /Coords array.");
|
||||
}
|
||||
const cs = ColorSpace.parse({
|
||||
cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
|
||||
xref,
|
||||
|
@ -116,25 +130,20 @@ class RadialAxialShading extends BaseShading {
|
|||
localColorSpaceCache,
|
||||
});
|
||||
const bbox = dict.getArray("BBox");
|
||||
this.bbox =
|
||||
Array.isArray(bbox) && bbox.length === 4
|
||||
? Util.normalizeRect(bbox)
|
||||
: null;
|
||||
this.bbox = isNumberArray(bbox, 4) ? Util.normalizeRect(bbox) : null;
|
||||
|
||||
let t0 = 0.0,
|
||||
t1 = 1.0;
|
||||
if (dict.has("Domain")) {
|
||||
const domainArr = dict.getArray("Domain");
|
||||
t0 = domainArr[0];
|
||||
t1 = domainArr[1];
|
||||
const domainArr = dict.getArray("Domain");
|
||||
if (isNumberArray(domainArr, 2)) {
|
||||
[t0, t1] = domainArr;
|
||||
}
|
||||
|
||||
let extendStart = false,
|
||||
extendEnd = false;
|
||||
if (dict.has("Extend")) {
|
||||
const extendArr = dict.getArray("Extend");
|
||||
extendStart = extendArr[0];
|
||||
extendEnd = extendArr[1];
|
||||
const extendArr = dict.getArray("Extend");
|
||||
if (isBooleanArray(extendArr, 2)) {
|
||||
[extendStart, extendEnd] = extendArr;
|
||||
}
|
||||
|
||||
if (
|
||||
|
@ -271,8 +280,7 @@ class RadialAxialShading extends BaseShading {
|
|||
}
|
||||
|
||||
getIR() {
|
||||
const coordsArr = this.coordsArr;
|
||||
const shadingType = this.shadingType;
|
||||
const { coordsArr, shadingType } = this;
|
||||
let type, p0, p1, r0, r1;
|
||||
if (shadingType === ShadingType.AXIAL) {
|
||||
p0 = [coordsArr[0], coordsArr[1]];
|
||||
|
@ -454,10 +462,7 @@ class MeshShading extends BaseShading {
|
|||
const dict = stream.dict;
|
||||
this.shadingType = dict.get("ShadingType");
|
||||
const bbox = dict.getArray("BBox");
|
||||
this.bbox =
|
||||
Array.isArray(bbox) && bbox.length === 4
|
||||
? Util.normalizeRect(bbox)
|
||||
: null;
|
||||
this.bbox = isNumberArray(bbox, 4) ? Util.normalizeRect(bbox) : null;
|
||||
const cs = ColorSpace.parse({
|
||||
cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
|
||||
xref,
|
||||
|
@ -983,17 +988,32 @@ class DummyShading extends BaseShading {
|
|||
}
|
||||
|
||||
function getTilingPatternIR(operatorList, dict, color) {
|
||||
const matrix = dict.getArray("Matrix");
|
||||
const bbox = Util.normalizeRect(dict.getArray("BBox"));
|
||||
const xstep = dict.get("XStep");
|
||||
const ystep = dict.get("YStep");
|
||||
const paintType = dict.get("PaintType");
|
||||
const tilingType = dict.get("TilingType");
|
||||
|
||||
let matrix = dict.getArray("Matrix");
|
||||
if (!isNumberArray(matrix, 6)) {
|
||||
matrix = IDENTITY_MATRIX;
|
||||
}
|
||||
let bbox = dict.getArray("BBox");
|
||||
bbox = isNumberArray(bbox, 4) ? Util.normalizeRect(bbox) : null;
|
||||
// Ensure that the pattern has a non-zero width and height, to prevent errors
|
||||
// in `pattern_helper.js` (fixes issue8330.pdf).
|
||||
if (bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
|
||||
throw new FormatError(`Invalid getTilingPatternIR /BBox array: [${bbox}].`);
|
||||
if (!bbox || bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
|
||||
throw new FormatError(`Invalid getTilingPatternIR /BBox array.`);
|
||||
}
|
||||
const xstep = dict.get("XStep");
|
||||
if (typeof xstep !== "number") {
|
||||
throw new FormatError(`Invalid getTilingPatternIR /XStep value.`);
|
||||
}
|
||||
const ystep = dict.get("YStep");
|
||||
if (typeof ystep !== "number") {
|
||||
throw new FormatError(`Invalid getTilingPatternIR /YStep value.`);
|
||||
}
|
||||
const paintType = dict.get("PaintType");
|
||||
if (!Number.isInteger(paintType)) {
|
||||
throw new FormatError(`Invalid getTilingPatternIR /PaintType value.`);
|
||||
}
|
||||
const tilingType = dict.get("TilingType");
|
||||
if (!Number.isInteger(tilingType)) {
|
||||
throw new FormatError(`Invalid getTilingPatternIR /TilingType value.`);
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue