Add non-PRODUCTION/TESTING overflow assert
s to various string helper-functions (issue 6759)
This commit is contained in:
parent
d644b66c72
commit
273d8cb746
@ -3788,6 +3788,9 @@ class PartialEvaluator {
|
|||||||
firstChar,
|
firstChar,
|
||||||
lastChar,
|
lastChar,
|
||||||
toUnicode,
|
toUnicode,
|
||||||
|
xHeight: 0,
|
||||||
|
capHeight: 0,
|
||||||
|
italicAngle: 0,
|
||||||
isType3Font,
|
isType3Font,
|
||||||
};
|
};
|
||||||
const widths = dict.get("Widths");
|
const widths = dict.get("Widths");
|
||||||
@ -3919,10 +3922,10 @@ class PartialEvaluator {
|
|||||||
bbox: descriptor.getArray("FontBBox") || dict.getArray("FontBBox"),
|
bbox: descriptor.getArray("FontBBox") || dict.getArray("FontBBox"),
|
||||||
ascent: descriptor.get("Ascent"),
|
ascent: descriptor.get("Ascent"),
|
||||||
descent: descriptor.get("Descent"),
|
descent: descriptor.get("Descent"),
|
||||||
xHeight: descriptor.get("XHeight"),
|
xHeight: descriptor.get("XHeight") || 0,
|
||||||
capHeight: descriptor.get("CapHeight"),
|
capHeight: descriptor.get("CapHeight") || 0,
|
||||||
flags: descriptor.get("Flags"),
|
flags: descriptor.get("Flags"),
|
||||||
italicAngle: descriptor.get("ItalicAngle"),
|
italicAngle: descriptor.get("ItalicAngle") || 0,
|
||||||
isType3Font,
|
isType3Font,
|
||||||
cssFontInfo,
|
cssFontInfo,
|
||||||
scaleFactors: glyphScaleFactors,
|
scaleFactors: glyphScaleFactors,
|
||||||
|
@ -257,10 +257,28 @@ function int32(b0, b1, b2, b3) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function string16(value) {
|
function string16(value) {
|
||||||
|
if (
|
||||||
|
typeof PDFJSDev === "undefined" ||
|
||||||
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||||
|
) {
|
||||||
|
assert(
|
||||||
|
typeof value === "number" && Math.abs(value) < 2 ** 16,
|
||||||
|
`string16: Unexpected input "${value}".`
|
||||||
|
);
|
||||||
|
}
|
||||||
return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
|
return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
function safeString16(value) {
|
function safeString16(value) {
|
||||||
|
if (
|
||||||
|
typeof PDFJSDev === "undefined" ||
|
||||||
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||||
|
) {
|
||||||
|
assert(
|
||||||
|
typeof value === "number" && !Number.isNaN(value),
|
||||||
|
`safeString16: Unexpected input "${value}".`
|
||||||
|
);
|
||||||
|
}
|
||||||
// clamp value to the 16-bit int range
|
// clamp value to the 16-bit int range
|
||||||
if (value > 0x7fff) {
|
if (value > 0x7fff) {
|
||||||
value = 0x7fff;
|
value = 0x7fff;
|
||||||
@ -751,7 +769,7 @@ function createPostTable(properties) {
|
|||||||
string32(angle) + // italicAngle
|
string32(angle) + // italicAngle
|
||||||
"\x00\x00" + // underlinePosition
|
"\x00\x00" + // underlinePosition
|
||||||
"\x00\x00" + // underlineThickness
|
"\x00\x00" + // underlineThickness
|
||||||
string32(properties.fixedPitch) + // isFixedPitch
|
string32(properties.fixedPitch ? 1 : 0) + // isFixedPitch
|
||||||
"\x00\x00\x00\x00" + // minMemType42
|
"\x00\x00\x00\x00" + // minMemType42
|
||||||
"\x00\x00\x00\x00" + // maxMemType42
|
"\x00\x00\x00\x00" + // maxMemType42
|
||||||
"\x00\x00\x00\x00" + // minMemType1
|
"\x00\x00\x00\x00" + // minMemType1
|
||||||
|
@ -588,6 +588,15 @@ function arraysToBytes(arr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function string32(value) {
|
function string32(value) {
|
||||||
|
if (
|
||||||
|
typeof PDFJSDev === "undefined" ||
|
||||||
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||||
|
) {
|
||||||
|
assert(
|
||||||
|
typeof value === "number" && Math.abs(value) < 2 ** 32,
|
||||||
|
`string32: Unexpected input "${value}".`
|
||||||
|
);
|
||||||
|
}
|
||||||
return String.fromCharCode(
|
return String.fromCharCode(
|
||||||
(value >> 24) & 0xff,
|
(value >> 24) & 0xff,
|
||||||
(value >> 16) & 0xff,
|
(value >> 16) & 0xff,
|
||||||
|
@ -23,6 +23,9 @@ describe("font_fpgm", function () {
|
|||||||
defaultEncoding: [],
|
defaultEncoding: [],
|
||||||
cMap,
|
cMap,
|
||||||
toUnicode: new ToUnicodeMap([]),
|
toUnicode: new ToUnicodeMap([]),
|
||||||
|
xHeight: 0,
|
||||||
|
capHeight: 0,
|
||||||
|
italicAngle: 0,
|
||||||
});
|
});
|
||||||
const output = await ttx(font.data);
|
const output = await ttx(font.data);
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ describe("font_post", function () {
|
|||||||
differences: [],
|
differences: [],
|
||||||
defaultEncoding: [],
|
defaultEncoding: [],
|
||||||
toUnicode: new ToUnicodeMap([]),
|
toUnicode: new ToUnicodeMap([]),
|
||||||
|
xHeight: 0,
|
||||||
|
capHeight: 0,
|
||||||
|
italicAngle: 0,
|
||||||
});
|
});
|
||||||
const output = await ttx(font.data);
|
const output = await ttx(font.data);
|
||||||
|
|
||||||
@ -41,6 +44,9 @@ describe("font_post", function () {
|
|||||||
defaultEncoding: [],
|
defaultEncoding: [],
|
||||||
cMap,
|
cMap,
|
||||||
toUnicode: new ToUnicodeMap([]),
|
toUnicode: new ToUnicodeMap([]),
|
||||||
|
xHeight: 0,
|
||||||
|
capHeight: 0,
|
||||||
|
italicAngle: 0,
|
||||||
});
|
});
|
||||||
const output = await ttx(font.data);
|
const output = await ttx(font.data);
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@ describe("font_post", function () {
|
|||||||
defaultEncoding: [],
|
defaultEncoding: [],
|
||||||
cMap,
|
cMap,
|
||||||
toUnicode: new ToUnicodeMap([]),
|
toUnicode: new ToUnicodeMap([]),
|
||||||
|
xHeight: 0,
|
||||||
|
capHeight: 0,
|
||||||
|
italicAngle: 0,
|
||||||
});
|
});
|
||||||
const output = await ttx(font.data);
|
const output = await ttx(font.data);
|
||||||
|
|
||||||
@ -45,6 +48,9 @@ describe("font_post", function () {
|
|||||||
differences: [],
|
differences: [],
|
||||||
defaultEncoding: [],
|
defaultEncoding: [],
|
||||||
toUnicode: new ToUnicodeMap([]),
|
toUnicode: new ToUnicodeMap([]),
|
||||||
|
xHeight: 0,
|
||||||
|
capHeight: 0,
|
||||||
|
italicAngle: 0,
|
||||||
});
|
});
|
||||||
const output = await ttx(font.data);
|
const output = await ttx(font.data);
|
||||||
|
|
||||||
@ -59,6 +65,9 @@ describe("font_post", function () {
|
|||||||
differences: [],
|
differences: [],
|
||||||
defaultEncoding: [],
|
defaultEncoding: [],
|
||||||
toUnicode: new ToUnicodeMap([]),
|
toUnicode: new ToUnicodeMap([]),
|
||||||
|
xHeight: 0,
|
||||||
|
capHeight: 0,
|
||||||
|
italicAngle: 0,
|
||||||
});
|
});
|
||||||
const output = await ttx(font.data);
|
const output = await ttx(font.data);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user