Files
bitvid/scripts/agent/fuzz-magnetUtils.mjs
T
google-labs-jules[bot]andPR0M3TH3AN 26b1552af5 feat: add fuzz testing harnesses for schemas, dm, and magnet utils
- Harmonize fuzzing iteration counts to 50,000 for robustness
- Add documentation headers to fuzz scripts
- Verify robustness of `nostrEventSchemas.js`, `dmDecryptor.js`, and `magnetUtils.js`
- Clean up temporary reproducers and crash reports

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-01-31 17:22:54 +00:00

56 lines
1.5 KiB
JavaScript

/**
* Fuzz harness for js/magnetUtils.js
*
* Targets:
* - normalizeAndAugmentMagnet
*
* Strategy:
* - Generates malformed magnet URIs and random strings.
* - Fuzzes options object (trackers, webseeds).
* - Checks for parsing crashes.
*/
import "./setup-test-env.js";
import { Fuzzer } from "./fuzz-lib.mjs";
import { normalizeAndAugmentMagnet } from "../../js/magnetUtils.js";
const fuzzer = new Fuzzer("magnetUtils");
async function fuzzTest(fuzzer, state) {
// Generate inputs
const rawValue = fuzzer.randBool() ? fuzzer.randString(100) : "magnet:?xt=urn:btih:" + fuzzer.randString(40, "0123456789abcdef");
// Inject garbage into magnet link
let malformedValue = rawValue;
if (fuzzer.randBool()) {
// url encode some chars
malformedValue = encodeURIComponent(rawValue);
}
if (fuzzer.randBool()) {
// Inject huge string
malformedValue += fuzzer.randString(10000);
}
const options = {
webSeed: fuzzer.randBool() ? fuzzer.randString(50) : [fuzzer.randString(50)],
torrentUrl: fuzzer.randString(50),
xs: fuzzer.randString(50),
extraTrackers: fuzzer.randArray(() => fuzzer.randString(30), 0, 3),
appProtocol: fuzzer.randBool() ? "http:" : "https:",
logger: () => {}
};
state.input = {
rawValue: malformedValue,
options
};
try {
normalizeAndAugmentMagnet(malformedValue, options);
} catch (err) {
throw err;
}
}
fuzzer.runFuzzLoop(50000, fuzzTest).catch(console.error);