diff --git a/.npmrc b/.npmrc index 3757b30..34cf20f 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -ignore-scripts=true +ignore-scripts=false package-lock=false diff --git a/benchmarks/fuzzer-check-errors.js b/benchmarks/fuzzer-check-errors.js new file mode 100644 index 0000000..1acb7f3 --- /dev/null +++ b/benchmarks/fuzzer-check-errors.js @@ -0,0 +1,18 @@ +const { FuzzedDataProvider } = require('@jazzer.js/core') +const fastContentTypeParse = require('../index.js') + +function fuzz (data) { + const provider = new FuzzedDataProvider(data) + + const fmtString = provider.consumeRemainingAsString() + try { + fastContentTypeParse.parse(fmtString) + } catch (error) { + // Ignore all expected errors + if (!(error instanceof TypeError)) { + throw error + } + } +} + +module.exports = { fuzz } diff --git a/benchmarks/fuzzer-check-performance.js b/benchmarks/fuzzer-check-performance.js new file mode 100644 index 0000000..699d57b --- /dev/null +++ b/benchmarks/fuzzer-check-performance.js @@ -0,0 +1,12 @@ +const { FuzzedDataProvider } = require('@jazzer.js/core') +const fastContentTypeParse = require('../index.js') + +function fuzz (data) { + const provider = new FuzzedDataProvider(data) + + const fmtString = provider.consumeRemainingAsString() + // Ignore errors; we're interested in performance slowdown + fastContentTypeParse.safeParse(fmtString) +} + +module.exports = { fuzz } diff --git a/package.json b/package.json index 93aafa6..7cc9f49 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", + "jazzer:errors": "jazzer benchmarks/fuzzer-check-errors --sync --timeout=100 -- -max_total_time=120", + "jazzer:performance": "jazzer benchmarks/fuzzer-check-performance --sync --timeout=100 -- -max_total_time=120", "test:unit": "c8 --100 node --test" }, "keywords": [ @@ -58,6 +60,7 @@ } ], "devDependencies": { + "@jazzer.js/core": "^2.1.0", "benchmark": "^2.1.4", "busboy": "^1.6.0", "c8": "^10.1.3",