Files
bitvid/scripts/agent/fuzz-magnetUtils.mjs
T
google-labs-jules[bot]andPR0M3TH3AN 28da9e1642 Add fuzzing harnesses for Nostr schemas, DM decryptor, and magnet utils
- Created `scripts/agent/fuzz-nostrEventSchemas.mjs`, `scripts/agent/fuzz-dmDecryptor.mjs`, and `scripts/agent/fuzz-magnetUtils.mjs`.
- Utilized `scripts/agent/fuzz-lib.mjs` for standardized random input generation and reporting.
- Removed legacy/duplicate fuzz scripts (`fuzz-nostr-schemas.mjs`, etc.) in favor of the new standardized ones.
- Verified all fuzzers run successfully with no crashes using 5000 iterations.
- Added huge string injection (1MB+) to stress test inputs.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-01-29 16:31:38 +00:00

45 lines
1.2 KiB
JavaScript

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(5000, fuzzTest).catch(console.error);