-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from msgpack/jsfuzz
Introduce Fuzzing with jsFuzz and fix issues found by fuzzing
- Loading branch information
Showing
8 changed files
with
83 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz | ||
|
||
name: Fuzz | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
fuzzing: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: "16" | ||
|
||
- run: npm ci | ||
- run: npm run test:fuzz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ isolate-*.log | |
|
||
# flamebearer | ||
flamegraph.html | ||
|
||
# jsfuzz | ||
corpus/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
export class DecodeError extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
|
||
// fix the prototype chain in a cross-platform way | ||
const proto: typeof DecodeError.prototype = Object.create(DecodeError.prototype); | ||
Object.setPrototypeOf(this, proto); | ||
|
||
Object.defineProperty(this, "name", { | ||
configurable: true, | ||
enumerable: false, | ||
value: DecodeError.name, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable */ | ||
const assert = require("assert"); | ||
const { Decoder, encode, DecodeError } = require("../dist/index.js"); | ||
|
||
/** | ||
* @param {Buffer} bytes | ||
* @returns {void} | ||
*/ | ||
module.exports.fuzz = function fuzz(bytes) { | ||
const decoder = new Decoder(); | ||
try { | ||
decoder.decode(bytes); | ||
} catch (e) { | ||
if (e instanceof DecodeError) { | ||
// ok | ||
} else if (e instanceof RangeError) { | ||
// ok | ||
} else { | ||
throw e; | ||
} | ||
} | ||
|
||
// make sure the decoder instance is not broken | ||
const object = { | ||
foo: 1, | ||
bar: 2, | ||
baz: ["one", "two", "three"], | ||
}; | ||
assert.deepStrictEqual(decoder.decode(encode(object)), object); | ||
} |