Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions test/fuzz/ccitt_stream.fuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* Fuzzer for CCITT fax stream decoding (Group 3 and Group 4).
* Used for fax-encoded images in PDFs.
*/

const MAX_INPUT_SIZE = 128 * 1024; // 128KB limit

let CCITTFaxDecoder = null;

async function init() {
if (CCITTFaxDecoder) return;
const ccittModule = await import("../../build/lib-legacy/core/ccitt.js");
CCITTFaxDecoder = ccittModule.CCITTFaxDecoder;
}

/**
* @param { Buffer } data
*/
module.exports.fuzz = async function (data) {
await init();

if (data.length < 4 || data.length > MAX_INPUT_SIZE) {
return;
}

// Use first 4 bytes to derive decoder parameters
const params = {
K: (data[0] % 3) - 1, // -1, 0, or 1
EndOfLine: !!(data[1] & 0x01),
EncodedByteAlign: !!(data[1] & 0x02),
Columns: ((data[2] << 8) | data[3]) % 4096 + 1,
Rows: 0,
EndOfBlock: !!(data[1] & 0x04),
BlackIs1: !!(data[1] & 0x08),
};

try {
const source = {
next: (function() {
let pos = 4;
return function() {
if (pos >= data.length) {
return -1;
}
return data[pos++];
};
})()
};

const decoder = new CCITTFaxDecoder(source, params);

// Try to decode some data
let bytesRead = 0;
const maxBytes = 1024 * 1024; // 1MB output limit
let byte;
while ((byte = decoder.readNextChar()) !== -1 && bytesRead < maxBytes) {
bytesRead++;
}
} catch (e) {
// Expected exceptions for malformed CCITT data
if (e.message && (
e.message.includes("out of memory") ||
e.message.includes("Maximum call stack") ||
e.message.includes("allocation failed")
)) {
throw e;
}
}
};
78 changes: 78 additions & 0 deletions test/fuzz/cff_parser.fuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* Fuzzer for CFF (Compact Font Format) parsing.
* CFF fonts are complex with charstring bytecode interpretation.
*/

const MAX_INPUT_SIZE = 256 * 1024; // 256KB limit

let CFFParser = null;

async function init() {
if (CFFParser) return;
const cffModule = await import("../../build/lib-legacy/core/cff_parser.js");
CFFParser = cffModule.CFFParser;
}

/**
* @param { Buffer } data
*/
module.exports.fuzz = async function (data) {
await init();

if (data.length < 4 || data.length > MAX_INPUT_SIZE) {
return;
}

try {
const bytes = new Uint8Array(data);
const parser = new CFFParser(
{
getBytes: () => bytes,
pos: 0,
length: bytes.length,
},
{}, // properties
true // isCIDFont - try both modes
);

const cff = parser.parse();

// Try to access font data
if (cff) {
// Access charstrings if available
if (cff.charStrings) {
const count = Math.min(cff.charStrings.count || 0, 10);
for (let i = 0; i < count; i++) {
try {
cff.charStrings.get(i);
} catch (e) {
// Individual charstring errors expected
}
}
}
}
} catch (e) {
// Expected exceptions for malformed CFF data
if (e.message && (
e.message.includes("out of memory") ||
e.message.includes("Maximum call stack") ||
e.message.includes("allocation failed")
)) {
throw e;
}
}
};
68 changes: 68 additions & 0 deletions test/fuzz/cmap_parser.fuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* Fuzzer for CMap (Character Map) parsing.
* CMaps define character code to glyph mappings.
*/

const MAX_INPUT_SIZE = 128 * 1024; // 128KB limit

let CMapFactory = null;

async function init() {
if (CMapFactory) return;
const cmapModule = await import("../../build/lib-legacy/core/cmap.js");
CMapFactory = cmapModule.CMapFactory;
}

/**
* @param { Buffer } data
*/
module.exports.fuzz = async function (data) {
await init();

if (data.length === 0 || data.length > MAX_INPUT_SIZE) {
return;
}

try {
// Create a minimal fetch function that returns our data
const fetchBuiltInCMap = async () => ({
cMapData: new Uint8Array(data),
compressionType: 0,
});

const cmap = await CMapFactory.create({
encoding: { name: "Identity-H" },
fetchBuiltInCMap,
useCMap: null,
});

// Try to use the cmap
if (cmap) {
cmap.lookup(0x0041);
cmap.lookup(0x3000);
}
} catch (e) {
// Expected exceptions for malformed CMap data
if (e.message && (
e.message.includes("out of memory") ||
e.message.includes("Maximum call stack") ||
e.message.includes("allocation failed")
)) {
throw e;
}
}
};
80 changes: 80 additions & 0 deletions test/fuzz/colorspace.fuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* Fuzzer for Colorspace parsing including ICC profiles.
*/

const MAX_INPUT_SIZE = 128 * 1024; // 128KB limit

let ColorSpace = null;
let Name = null;
let Dict = null;

async function init() {
if (ColorSpace) return;
const colorspaceModule = await import("../../build/lib-legacy/core/colorspace.js");
const primitivesModule = await import("../../build/lib-legacy/core/primitives.js");
ColorSpace = colorspaceModule.ColorSpace;
Name = primitivesModule.Name;
Dict = primitivesModule.Dict;
}

/**
* @param { Buffer } data
*/
module.exports.fuzz = async function (data) {
await init();

if (data.length < 4 || data.length > MAX_INPUT_SIZE) {
return;
}

try {
// Create a mock XRef and resources
const xref = {
fetch: () => null,
fetchIfRef: (obj) => obj,
};
const resources = new Dict(xref);

// Construct colorspace name from first byte
const csTypes = [
"DeviceGray", "DeviceRGB", "DeviceCMYK",
"CalGray", "CalRGB", "Lab",
"ICCBased", "Indexed", "Pattern", "Separation"
];
const csType = csTypes[data[0] % csTypes.length];
const csName = Name.get(csType);

ColorSpace.parse({
cs: csName,
xref,
resources,
pdfFunctionFactory: {
create: () => ({ parse: () => null }),
},
localColorSpaceCache: new Map(),
});
} catch (e) {
// Expected exceptions for malformed colorspace data
if (e.message && (
e.message.includes("out of memory") ||
e.message.includes("Maximum call stack") ||
e.message.includes("allocation failed")
)) {
throw e;
}
}
};
Binary file not shown.
Binary file added test/fuzz/corpus/ccitt_stream/minimal_g3.ccitt
Binary file not shown.
Binary file added test/fuzz/corpus/cff_parser/minimal.cff
Binary file not shown.
Empty file.
14 changes: 14 additions & 0 deletions test/fuzz/corpus/cmap_parser/identity.cmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
<< /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> def
/CMapName /Identity-H def
/CMapType 1 def
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
Binary file added test/fuzz/corpus/colorspace/calrgb.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/colorspace/cmykjpeg.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/colorspace/colorspace_atan.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/colorspace/colorspace_cos.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/colorspace/colorspace_sin.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/crypto/sample1.bin
Binary file not shown.
Binary file added test/fuzz/corpus/crypto/sample2.bin
Binary file not shown.
Binary file added test/fuzz/corpus/flate_stream/empty.z
Binary file not shown.
Binary file added test/fuzz/corpus/flate_stream/hello.z
Binary file not shown.
Binary file added test/fuzz/corpus/flate_stream/raw.deflate
Binary file not shown.
29 changes: 29 additions & 0 deletions test/fuzz/corpus/formcalc_parser/complex.fc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Complex FormCalc script
var total = 0
var count = 0
var avg = 0

func Calculate(a, b, c)
var sum = a + b + c
return sum / 3
endfunc

for i = 1 upto 10 step 1 do
total = total + i
count = count + 1
endfor

if (count > 0) then
avg = total / count
if (avg > 5) then
avg = Round(avg, 2)
endif
endif

foreach item in (1, 2, 3, 4, 5) do
total = total + item
endfor

while (count < 20) do
count = count + 1
endwhile
7 changes: 7 additions & 0 deletions test/fuzz/corpus/formcalc_parser/functions.fc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
func Add(a, b)
return a + b
endfunc

var result = Add(10, 20)
var text = Concat("Hello ", "World")
var len = Len(text)
5 changes: 5 additions & 0 deletions test/fuzz/corpus/formcalc_parser/simple.fc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var x = 1 + 2
var y = x * 3
if (y > 5) then
y = y - 1
endif
Binary file not shown.
2 changes: 2 additions & 0 deletions test/fuzz/corpus/jbig2_image/minimal.jbig2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
�JB2

Binary file added test/fuzz/corpus/jpeg_image/jfif_header.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fuzz/corpus/jpeg_image/minimal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fuzz/corpus/jpx_image/jp2k-resetprob.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/jpx_image/minimal.jp2
Binary file not shown.
Binary file added test/fuzz/corpus/lzw_stream/minimal.lzw
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/annotation-as.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/annotation-stamp.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/annotation-tx.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/annotation-tx2.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/annotation-tx3.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/bug1019475_2.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/bug1072164.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/bug1538111.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/bug1723568.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/bug1901253.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/cid_cff.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/complex_ttf_font.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue13433.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue14256.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue17069.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue17332.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue17679.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue19695.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue19835.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue1985.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue19971.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue2856.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue3351.3.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue3584.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue4061.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue5470.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue5564_reduced.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue5686.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue6286.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue6737.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue6894.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue7014.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue8697.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue8707.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue9458.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/issue9915_reduced.pdf
Binary file not shown.
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/minimal.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/mixedfonts.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/mmtype1.pdf
Binary file not shown.
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/rc_annotation.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/simpletype3font.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/standard_fonts.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/text_clip_cff_cid.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1716047.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1716380.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1716809.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1716816.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1716980.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1717668_1.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1717668_2.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1717668_3.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1717668_4.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1717681.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1717805.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718037.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718053.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718521_1.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718521_2.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718521_3.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718670_1.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718725.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718735.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718740.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1718741.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1720888.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1721600.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1722029.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1722030_1.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1722038.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1729877.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1735738.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1739502.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_bug1998843.pdf
Binary file not shown.
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue13213.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue13500.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue13611.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue13679.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue13855.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue13994.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue14071.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue14144.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue14150.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xfa_issue14315.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/pdf_parser/xobject-image.pdf
Binary file not shown.
Binary file added test/fuzz/corpus/ps_parser/complex.ps
Binary file not shown.
Binary file added test/fuzz/corpus/ps_parser/conditional.ps
Binary file not shown.
Binary file added test/fuzz/corpus/ps_parser/conditionals.ps
Binary file not shown.
Binary file added test/fuzz/corpus/ps_parser/math_ops.ps
Binary file not shown.
Binary file added test/fuzz/corpus/ps_parser/simple.ps
Binary file not shown.
Binary file added test/fuzz/corpus/ps_parser/stack_ops.ps
Binary file not shown.
Binary file added test/fuzz/corpus/ps_parser/trig.ps
Binary file not shown.
11 changes: 11 additions & 0 deletions test/fuzz/corpus/type1_parser/minimal.pfa
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%!PS-AdobeFont-1.0: TestFont 001.000
%%CreationDate: 1/1/2024
11 dict begin
/FontType 1 def
/FontName /TestFont def
/FontMatrix [0.001 0 0 0.001 0 0] def
/FontBBox {0 0 1000 1000} def
/Encoding StandardEncoding def
/UniqueID 1000000 def
/PaintType 0 def
currentdict end
Loading