From 21316959bc2fe1e531c4084fe6b32a6e3bd9ee20 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Sun, 16 Nov 2025 10:11:28 +0100 Subject: [PATCH 1/3] chore: fuzzing manual test --- .gitignore | 1 + .npmrc | 2 +- benchmarks/fuzzer-check-errors.js | 18 ++++++++++++++++++ benchmarks/fuzzer-check-performance.js | 12 ++++++++++++ package.json | 10 +++++++--- 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 benchmarks/fuzzer-check-errors.js create mode 100644 benchmarks/fuzzer-check-performance.js diff --git a/.gitignore b/.gitignore index d8a5ca2..94bb99c 100644 --- a/.gitignore +++ b/.gitignore @@ -150,3 +150,4 @@ yarn.lock # tap files .tap/ +jazzer-out/ 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..d7802e9 --- /dev/null +++ b/benchmarks/fuzzer-check-errors.js @@ -0,0 +1,18 @@ +const { FuzzedDataProvider } = require('@jazzer.js/core') +const fastContentTypeParse = require('fast-content-type-parse') + +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..ccf3f95 --- /dev/null +++ b/benchmarks/fuzzer-check-performance.js @@ -0,0 +1,12 @@ +const { FuzzedDataProvider } = require('@jazzer.js/core') +const fastContentTypeParse = require('fast-content-type-parse') + +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..ad5783e 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,15 @@ "name": "fast-content-type-parse", "version": "3.0.0", "description": "Parse HTTP Content-Type header according to RFC 7231", - "main": "index.js", - "type": "commonjs", - "types": "./types/index.d.ts", + "main": "fuzzer.js", "scripts": { "benchmark": "node benchmarks/simple.js && node benchmarks/simple-ows.js && node benchmarks/with-param.js && node benchmarks/with-param-quoted.js", "lint": "eslint", "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", + "jazzer:errors": "jazzer benchmarks/fuzzer-check-errors jazzer-out --sync -- -max_total_time=60", + "jazzer:performance": "jazzer benchmarks/fuzzer-check-performance jazzer-out --sync -- -max_total_time=60", "test:unit": "c8 --100 node --test" }, "keywords": [ @@ -58,6 +58,7 @@ } ], "devDependencies": { + "@jazzer.js/core": "^2.1.0", "benchmark": "^2.1.4", "busboy": "^1.6.0", "c8": "^10.1.3", @@ -65,5 +66,8 @@ "eslint": "^9.17.0", "neostandard": "^0.12.0", "tsd": "^0.33.0" + }, + "dependencies": { + "fast-content-type-parse": "^3.0.0" } } From d57c91efc2581ebfd1aa158ae339b345dd65a6e6 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Sun, 16 Nov 2025 10:22:04 +0100 Subject: [PATCH 2/3] cleaning --- .gitignore | 1 - package.json | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 94bb99c..d8a5ca2 100644 --- a/.gitignore +++ b/.gitignore @@ -150,4 +150,3 @@ yarn.lock # tap files .tap/ -jazzer-out/ diff --git a/package.json b/package.json index ad5783e..0e8f4b6 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", - "jazzer:errors": "jazzer benchmarks/fuzzer-check-errors jazzer-out --sync -- -max_total_time=60", - "jazzer:performance": "jazzer benchmarks/fuzzer-check-performance jazzer-out --sync -- -max_total_time=60", + "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": [ From 5dc6f6db65cc9c2b7bcffe82c5cc49cd6b06508c Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Sun, 16 Nov 2025 10:28:39 +0100 Subject: [PATCH 3/3] cleaning --- benchmarks/fuzzer-check-errors.js | 2 +- benchmarks/fuzzer-check-performance.js | 2 +- package.json | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/benchmarks/fuzzer-check-errors.js b/benchmarks/fuzzer-check-errors.js index d7802e9..1acb7f3 100644 --- a/benchmarks/fuzzer-check-errors.js +++ b/benchmarks/fuzzer-check-errors.js @@ -1,5 +1,5 @@ const { FuzzedDataProvider } = require('@jazzer.js/core') -const fastContentTypeParse = require('fast-content-type-parse') +const fastContentTypeParse = require('../index.js') function fuzz (data) { const provider = new FuzzedDataProvider(data) diff --git a/benchmarks/fuzzer-check-performance.js b/benchmarks/fuzzer-check-performance.js index ccf3f95..699d57b 100644 --- a/benchmarks/fuzzer-check-performance.js +++ b/benchmarks/fuzzer-check-performance.js @@ -1,5 +1,5 @@ const { FuzzedDataProvider } = require('@jazzer.js/core') -const fastContentTypeParse = require('fast-content-type-parse') +const fastContentTypeParse = require('../index.js') function fuzz (data) { const provider = new FuzzedDataProvider(data) diff --git a/package.json b/package.json index 0e8f4b6..7cc9f49 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,9 @@ "name": "fast-content-type-parse", "version": "3.0.0", "description": "Parse HTTP Content-Type header according to RFC 7231", - "main": "fuzzer.js", + "main": "index.js", + "type": "commonjs", + "types": "./types/index.d.ts", "scripts": { "benchmark": "node benchmarks/simple.js && node benchmarks/simple-ows.js && node benchmarks/with-param.js && node benchmarks/with-param-quoted.js", "lint": "eslint", @@ -66,8 +68,5 @@ "eslint": "^9.17.0", "neostandard": "^0.12.0", "tsd": "^0.33.0" - }, - "dependencies": { - "fast-content-type-parse": "^3.0.0" } }