diff --git a/crates/ec-image/fuzz/Cargo.toml b/crates/ec-image/fuzz/Cargo.toml index ce7a1f66..a0b0f74f 100644 --- a/crates/ec-image/fuzz/Cargo.toml +++ b/crates/ec-image/fuzz/Cargo.toml @@ -24,20 +24,6 @@ test = false doc = false bench = false -[[bin]] -name = "decode_with_limits" -path = "fuzz_targets/decode_with_limits.rs" -test = false -doc = false -bench = false - -[[bin]] -name = "info" -path = "fuzz_targets/info.rs" -test = false -doc = false -bench = false - [[bin]] name = "decode_animation" path = "fuzz_targets/decode_animation.rs" @@ -45,48 +31,6 @@ test = false doc = false bench = false -[[bin]] -name = "bmp" -path = "fuzz_targets/bmp.rs" -test = false -doc = false -bench = false - -[[bin]] -name = "gif" -path = "fuzz_targets/gif.rs" -test = false -doc = false -bench = false - -[[bin]] -name = "jpeg" -path = "fuzz_targets/jpeg.rs" -test = false -doc = false -bench = false - -[[bin]] -name = "png" -path = "fuzz_targets/png.rs" -test = false -doc = false -bench = false - -[[bin]] -name = "tiff" -path = "fuzz_targets/tiff.rs" -test = false -doc = false -bench = false - -[[bin]] -name = "webp" -path = "fuzz_targets/webp.rs" -test = false -doc = false -bench = false - [[bin]] name = "probe" path = "fuzz_targets/probe.rs" diff --git a/crates/ec-image/fuzz/fuzz_targets/bmp.rs b/crates/ec-image/fuzz/fuzz_targets/bmp.rs deleted file mode 100644 index 3bb9bd76..00000000 --- a/crates/ec-image/fuzz/fuzz_targets/bmp.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![no_main] - -use ec_image::Limits; -use libfuzzer_sys::fuzz_target; - -// The bmp module's own entry points, called directly so the format signature check in the -// dispatcher does not filter the input first. Header parse, then a decode under small limits. -const LIMITS: Limits = Limits { - max_pixels: 4096 * 4096, - max_alloc: 1 << 26, - max_total_alloc: 1 << 27, -}; - -fuzz_target!(|data: &[u8]| { - let _ = ec_image::bmp::info(data); - let _ = ec_image::bmp::decode(data, LIMITS); -}); diff --git a/crates/ec-image/fuzz/fuzz_targets/decode_with_limits.rs b/crates/ec-image/fuzz/fuzz_targets/decode_with_limits.rs deleted file mode 100644 index bff5b0a8..00000000 --- a/crates/ec-image/fuzz/fuzz_targets/decode_with_limits.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![no_main] - -use ec_image::Limits; -use libfuzzer_sys::fuzz_target; - -// Small limits: 4096x4096 pixels, 64 MiB per buffer, 128 MiB across one call. Under these a -// hostile header is refused before it sizes anything, and every path that multiplies a count by -// a size still gets exercised against a real budget. -const LIMITS: Limits = Limits { - max_pixels: 4096 * 4096, - max_alloc: 1 << 26, - max_total_alloc: 1 << 27, -}; - -fuzz_target!(|data: &[u8]| { - let _ = ec_image::decode_with_limits(data, LIMITS); -}); diff --git a/crates/ec-image/fuzz/fuzz_targets/gif.rs b/crates/ec-image/fuzz/fuzz_targets/gif.rs deleted file mode 100644 index f75b5ce0..00000000 --- a/crates/ec-image/fuzz/fuzz_targets/gif.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![no_main] - -use ec_image::Limits; -use libfuzzer_sys::fuzz_target; - -// The gif module's own entry points, called directly so the format signature check in the -// dispatcher does not filter the input first. Header parse, then a decode under small limits. -const LIMITS: Limits = Limits { - max_pixels: 4096 * 4096, - max_alloc: 1 << 26, - max_total_alloc: 1 << 27, -}; - -fuzz_target!(|data: &[u8]| { - let _ = ec_image::gif::info(data); - let _ = ec_image::gif::decode(data, LIMITS); - let _ = ec_image::gif::decode_animation(data, LIMITS); -}); diff --git a/crates/ec-image/fuzz/fuzz_targets/info.rs b/crates/ec-image/fuzz/fuzz_targets/info.rs deleted file mode 100644 index f6ce5e97..00000000 --- a/crates/ec-image/fuzz/fuzz_targets/info.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![no_main] - -use libfuzzer_sys::fuzz_target; - -// Header-only parse: dimensions and format details without decoding any pixels. -fuzz_target!(|data: &[u8]| { - let _ = ec_image::info(data); -}); diff --git a/crates/ec-image/fuzz/fuzz_targets/jpeg.rs b/crates/ec-image/fuzz/fuzz_targets/jpeg.rs deleted file mode 100644 index f3ad427d..00000000 --- a/crates/ec-image/fuzz/fuzz_targets/jpeg.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![no_main] - -use ec_image::Limits; -use libfuzzer_sys::fuzz_target; - -// The jpeg module's own entry points, called directly so the format signature check in the -// dispatcher does not filter the input first. Header parse, then a decode under small limits. -const LIMITS: Limits = Limits { - max_pixels: 4096 * 4096, - max_alloc: 1 << 26, - max_total_alloc: 1 << 27, -}; - -fuzz_target!(|data: &[u8]| { - let _ = ec_image::jpeg::info(data); - let _ = ec_image::jpeg::decode(data, LIMITS); - let _ = ec_image::jpeg::decode_yuv(data, LIMITS); -}); diff --git a/crates/ec-image/fuzz/fuzz_targets/png.rs b/crates/ec-image/fuzz/fuzz_targets/png.rs deleted file mode 100644 index fd6bf435..00000000 --- a/crates/ec-image/fuzz/fuzz_targets/png.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![no_main] - -use ec_image::Limits; -use libfuzzer_sys::fuzz_target; - -// The png module's own entry points, called directly so the format signature check in the -// dispatcher does not filter the input first. Header parse, then a decode under small limits. -const LIMITS: Limits = Limits { - max_pixels: 4096 * 4096, - max_alloc: 1 << 26, - max_total_alloc: 1 << 27, -}; - -fuzz_target!(|data: &[u8]| { - let _ = ec_image::png::info(data); - let _ = ec_image::png::decode(data, LIMITS); -}); diff --git a/crates/ec-image/fuzz/fuzz_targets/tiff.rs b/crates/ec-image/fuzz/fuzz_targets/tiff.rs deleted file mode 100644 index 43dec73d..00000000 --- a/crates/ec-image/fuzz/fuzz_targets/tiff.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![no_main] - -use ec_image::Limits; -use libfuzzer_sys::fuzz_target; - -// The tiff module's own entry points, called directly so the format signature check in the -// dispatcher does not filter the input first. Header parse, then a decode under small limits. -const LIMITS: Limits = Limits { - max_pixels: 4096 * 4096, - max_alloc: 1 << 26, - max_total_alloc: 1 << 27, -}; - -fuzz_target!(|data: &[u8]| { - let _ = ec_image::tiff::info(data); - let _ = ec_image::tiff::decode(data, LIMITS); -}); diff --git a/crates/ec-image/fuzz/fuzz_targets/webp.rs b/crates/ec-image/fuzz/fuzz_targets/webp.rs deleted file mode 100644 index b74c3714..00000000 --- a/crates/ec-image/fuzz/fuzz_targets/webp.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![no_main] - -use ec_image::Limits; -use libfuzzer_sys::fuzz_target; - -// The webp module's own entry points, called directly so the format signature check in the -// dispatcher does not filter the input first. Header parse, then a decode under small limits. -const LIMITS: Limits = Limits { - max_pixels: 4096 * 4096, - max_alloc: 1 << 26, - max_total_alloc: 1 << 27, -}; - -fuzz_target!(|data: &[u8]| { - let _ = ec_image::webp::info(data); - let _ = ec_image::webp::decode(data, LIMITS); - let _ = ec_image::webp::decode_frames(data, LIMITS); -}); diff --git a/crates/ec-image/fuzz/seed.sh b/crates/ec-image/fuzz/seed.sh index 73f62fc3..cf7b6745 100755 --- a/crates/ec-image/fuzz/seed.sh +++ b/crates/ec-image/fuzz/seed.sh @@ -1,11 +1,7 @@ #!/usr/bin/env bash # seed.sh: fill fuzz/corpus// from the repo's still-image fixtures. # -# Every file under tests/data/stills (PNG, JPEG, WebP, GIF, BMP, TIFF) seeds the whole-file targets: -# decode, decode_with_limits, info, probe, decode_animation. Each format target gets only the files of its -# own format, so its corpus starts on the right signature. The VP8 frames under fixtures/vp8 are -# VP8 bitstreams, not stills, and are not used here. -# +# Every file under tests/data/stills seeds each whole-file target: decode, decode_animation, probe. # Corpus lives under fuzz/corpus, which is git-ignored. set -euo pipefail @@ -14,39 +10,16 @@ STILLS="$FUZZ_DIR/../tests/data/stills" [ -d "$STILLS" ] || { echo "seed.sh: $STILLS missing" >&2; exit 2; } CORPUS="$FUZZ_DIR/corpus" -mkdir -p "$CORPUS"/{decode,decode_with_limits,info,probe,decode_animation,bmp,gif,jpeg,png,tiff,webp} - -python3 -I - "$STILLS" "$CORPUS" <<'PY' -import glob, os, sys - -stills, corpus = sys.argv[1], sys.argv[2] -by_format = { - "png": (".png",), "jpeg": (".jpg", ".jpeg"), "webp": (".webp",), - "gif": (".gif",), "bmp": (".bmp",), "tiff": (".tif", ".tiff"), -} -all_files = sorted(p for p in glob.glob(os.path.join(stills, "*")) if os.path.isfile(p)) -if not all_files: - sys.exit("seed.sh: no still-image fixtures found") - -def write(target, name, data): - with open(os.path.join(corpus, target, name), "wb") as f: - f.write(data) - -count = {} -def bump(t): - count[t] = count.get(t, 0) + 1 +TARGETS=(decode decode_animation probe) +mkdir -p "${TARGETS[@]/#/$CORPUS/}" -for path in all_files: - name = os.path.basename(path) - ext = os.path.splitext(name)[1].lower() - data = open(path, "rb").read() - for t in ("decode", "decode_with_limits", "info", "probe", "decode_animation"): - write(t, name, data) - bump(t) - for fmt, exts in by_format.items(): - if ext in exts: - write(fmt, name, data) - bump(fmt) -for t in ("decode", "decode_with_limits", "info", "decode_animation", "bmp", "gif", "jpeg", "png", "tiff", "webp"): - print(f"{t}: {count.get(t, 0)} seeds") -PY +n=0 +for path in "$STILLS"/*; do + [ -f "$path" ] || continue + for t in "${TARGETS[@]}"; do + cp "$path" "$CORPUS/$t/$(basename "$path")" + n=$((n + 1)) + done +done +[ "$n" -gt 0 ] || { echo "seed.sh: no still-image fixtures found" >&2; exit 2; } +echo "seeded $n files under $CORPUS"