| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,3 +11,6 @@ isolate-*.log | |||
| 11 | 11 | ||
| 12 | 12 | # flamebearer | |
| 13 | 13 | flamegraph.html | |
| 14 | + | ||
| 15 | + # jsfuzz | ||
| 16 | + corpus/ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,9 +20,10 @@ | |||
| 20 | 20 | "test:te": "TEXT_ENCODING=force mocha 'test/**/*.test.ts'", | |
| 21 | 21 | "test:dist:purejs": "TS_NODE_PROJECT=tsconfig.test-dist-es5-purejs.json npm run test:purejs -- --reporter=dot", | |
| 22 | 22 | "test:cover": "npm run cover:clean && npm-run-all 'test:cover:*' && npm run cover:report", | |
| 23 | - "test:cover:purejs": "npx nyc --no-clean npm run test:purejs", | ||
| 24 | - "test:cover:te": "npx nyc --no-clean npm run test:te", | ||
| 23 | + "test:cover:purejs": "npm exec nyc --no-clean npm run test:purejs", | ||
| 24 | + "test:cover:te": "npm exec nyc --no-clean npm run test:te", | ||
| 25 | 25 | "test:deno": "deno test test/deno_test.ts", | |
| 26 | + "test:fuzz": "npm exec -- jsfuzz@git+https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz.git --fuzzTime 5 --rss-limit-mb 256 --no-versifier test/decode.jsfuzz.js corpus", | ||
| 26 | 27 | "cover:clean": "rimraf .nyc_output coverage/", | |
| 27 | 28 | "cover:report": "npx nyc report --reporter=text-summary --reporter=html --reporter=json", | |
| 28 | 29 | "test:browser": "karma start --single-run", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,30 @@ | |||
| 1 | + /* eslint-disable */ | ||
| 2 | + const assert = require("assert"); | ||
| 3 | + const { Decoder, encode, DecodeError, DataViewIndexOutOfBoundsError } = require("../dist/index.js"); | ||
| 4 | + | ||
| 5 | + /** | ||
| 6 | + * @param {Buffer} bytes | ||
| 7 | + * @returns {void} | ||
| 8 | + */ | ||
| 9 | + module.exports.fuzz = function fuzz(bytes) { | ||
| 10 | + const decoder = new Decoder(); | ||
| 11 | + try { | ||
| 12 | + decoder.decode(bytes); | ||
| 13 | + } catch (e) { | ||
| 14 | + if (e instanceof DecodeError) { | ||
| 15 | + // ok | ||
| 16 | + } else if (e instanceof DataViewIndexOutOfBoundsError) { | ||
| 17 | + // ok | ||
| 18 | + } else { | ||
| 19 | + throw e; | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + // make sure the decoder instance is not broken | ||
| 24 | + const object = { | ||
| 25 | + foo: 1, | ||
| 26 | + bar: 2, | ||
| 27 | + baz: ["one", "two", "three"], | ||
| 28 | + }; | ||
| 29 | + assert.deepStrictEqual(decoder.decode(encode(object)), object); | ||
| 30 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments