MCPcopy Create free account
hub / github.com/apache/thrift / createParserFuzzer

Function createParserFuzzer

lib/nodejs/test/fuzz/fuzz_common.js:31–58  ·  view source on GitHub ↗

* Creates a parser fuzzer function for a specific protocol * @param {Function} protocolFactory - The Thrift protocol factory function * @param {boolean} [readMessageBegin=false] - Whether to call readMessageBegin before reading the test instance * This is needed for protocols that do not support

(protocolFactory, readMessageBegin = false)

Source from the content-addressed store, hash-verified

29 * @returns {Function} A fuzzer function that can be used with Jazzer.js
30 */
31function createParserFuzzer(protocolFactory, readMessageBegin = false) {
32 return function fuzz(data) {
33 if (data.length < 2) {
34 return;
35 }
36
37 try {
38 // Set up transport with input data
39 const transport = new thrift.TFramedTransport(data);
40 const protocol = protocolFactory(transport);
41 const testInstance = new FuzzTest.FuzzTest();
42 if (readMessageBegin) {
43 protocol.readMessageBegin();
44 }
45 testInstance[Symbol.for("read")](protocol);
46 } catch (e) {
47 if (
48 !(
49 e.name === "InputBufferUnderrunError" ||
50 e.name === "TProtocolException"
51 )
52 ) {
53 // TODO: Are other exceptions expected?
54 // console.log(e);
55 }
56 }
57 };
58}
59
60/**
61 * Creates a roundtrip fuzzer function for a specific protocol

Calls 2

forMethod · 0.80
readMessageBeginMethod · 0.65

Tested by

no test coverage detected