Skip to content

Commit 8b56cba

Browse files
DavidKorczynskithomasvl
authored andcommitted
infra: update introspector and add new light version (google#12983)
Adds a light version of FI that should work on all projects. This will only be used if the existing FI does not work, e.g. due to failures around LTO. Also starts using the CLI version of fuzz-introspector as opposed to calling `main.py`. --------- Signed-off-by: David Korczynski <[email protected]>
1 parent f81026d commit 8b56cba

File tree

3 files changed

+63
-24
lines changed

3 files changed

+63
-24
lines changed

infra/base-images/base-builder/compile

+58-19
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,47 @@ if [ "$SANITIZER" = "introspector" ] || [ "$RUST_SANITIZER" = "introspector" ];
229229

230230
# Install Fuzz-Introspector
231231
pushd /fuzz-introspector/src
232-
python3 -m pip install .
232+
python3 -m pip install -e .
233233
popd
234234

235235
if [ "$FUZZING_LANGUAGE" = "python" ]; then
236236
python3 /fuzz-introspector/src/main.py light --language=python
237+
cp -rf $SRC/inspector/ /tmp/inspector-saved
237238
elif [ "$FUZZING_LANGUAGE" = "jvm" ]; then
238239
python3 /fuzz-introspector/src/main.py light --language=jvm
240+
cp -rf $SRC/inspector/ /tmp/inspector-saved
239241
elif [ "$FUZZING_LANGUAGE" = "rust" ]; then
240242
python3 /fuzz-introspector/src/main.py light --language=rust
243+
cp -rf $SRC/inspector/ /tmp/inspector-saved
241244
else
242245
python3 /fuzz-introspector/src/main.py light
246+
247+
# Make a copy of the light. This is needed because we run two versions of
248+
# introspector: one based on pure statis analysis and one based on
249+
# regular LTO.
250+
cp -rf $SRC/inspector/ /tmp/inspector-saved
251+
252+
253+
# Move coverage report.
254+
if [ -d "$OUT/textcov_reports" ]
255+
then
256+
find $OUT/textcov_reports/ -name "*.covreport" -exec cp {} $SRC/inspector/ \;
257+
find $OUT/textcov_reports/ -name "*.json" -exec cp {} $SRC/inspector/ \;
258+
fi
259+
260+
# Make fuzz-introspector HTML report using light approach.
261+
REPORT_ARGS="--name=$PROJECT_NAME"
262+
263+
# Only pass coverage_url when COVERAGE_URL is set (in cloud builds)
264+
if [[ ! -z "${COVERAGE_URL+x}" ]]; then
265+
REPORT_ARGS="$REPORT_ARGS --coverage-url=${COVERAGE_URL}"
266+
fi
267+
268+
# Run pure static analysis fuzz introspector
269+
fuzz-introspector full --target-dir=$SRC \
270+
--language=${FUZZING_LANGUAGE} \
271+
--out-dir=$SRC/inspector \
272+
${REPORT_ARGS}
243273
fi
244274

245275
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
@@ -313,28 +343,37 @@ if [ "$SANITIZER" = "introspector" ] || [ "$RUST_SANITIZER" = "introspector" ];
313343
unset CFLAGS
314344
export G_ANALYTICS_TAG="G-8WTFM1Y62J"
315345

346+
# If we get to here, it means the e.g. LTO had no problems and succeeded.
347+
# TO this end, we wlil restore the original light analysis and used the
348+
# LTO processing itself.
349+
rm -rf $SRC/inspector
350+
cp -rf /tmp/inspector-saved $SRC/inspector
351+
352+
cd /fuzz-introspector/src
353+
python3 -m pip install -e .
354+
cd /src/
355+
316356
if [ "$FUZZING_LANGUAGE" = "jvm" ]; then
317357
echo "GOING jvm route"
318358

319359
set -x
320360
# Output will be put in /out/
321-
python3 /fuzz-introspector/frontends/java/oss-fuzz-main.py
361+
python3 -m fuzz_introspector.frontends.oss_fuzz --language jvm --target-dir $SRC --entrypoint fuzzerTestOneInput
362+
322363
# Move files temporarily to fit workflow of other languages.
323364
mkdir -p $SRC/my-fi-data
324-
find $OUT/ -name *.data -exec mv {} $SRC/my-fi-data/ \;
325-
find $OUT/ -name *.data.yaml -exec mv {} $SRC/my-fi-data/ \;
365+
find ./ -name *.data -exec mv {} $SRC/my-fi-data/ \;
366+
find ./ -name *.data.yaml -exec mv {} $SRC/my-fi-data/ \;
326367
elif [ "$FUZZING_LANGUAGE" = "rust" ]; then
327368
echo "GOING rust route"
328369

329370
# Run the rust frontend
330-
pushd /fuzz-introspector/frontends/rust/rust_function_analyser
331-
cargo run -- $SRC
371+
python3 -m fuzz_introspector.frontends.oss_fuzz --language rust --target-dir $SRC
332372

333373
# Move files temporarily to fix workflow of other languages.
334374
mkdir -p $SRC/my-fi-data
335375
find ./ -name "*.data" -exec mv {} $SRC/my-fi-data/ \;
336376
find ./ -name "*.data.yaml" -exec mv {} $SRC/my-fi-data/ \;
337-
popd
338377

339378
# Restore the sanitizer flag for rust
340379
export SANITIZER="introspector"
@@ -359,43 +398,43 @@ if [ "$SANITIZER" = "introspector" ] || [ "$RUST_SANITIZER" = "introspector" ];
359398
REPORT_ARGS="--name=$PROJECT_NAME"
360399
# Only pass coverage_url when COVERAGE_URL is set (in cloud builds)
361400
if [[ ! -z "${COVERAGE_URL+x}" ]]; then
362-
REPORT_ARGS="$REPORT_ARGS --coverage_url=${COVERAGE_URL}"
401+
REPORT_ARGS="$REPORT_ARGS --coverage-url=${COVERAGE_URL}"
363402
fi
364403

365404
# Do different things depending on languages
366405
if [ "$FUZZING_LANGUAGE" = "python" ]; then
367406
echo "GOING python route"
368407
set -x
369-
REPORT_ARGS="$REPORT_ARGS --target_dir=$SRC/inspector"
408+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC/inspector"
370409
REPORT_ARGS="$REPORT_ARGS --language=python"
371-
python3 /fuzz-introspector/src/main.py report $REPORT_ARGS
410+
fuzz-introspector report $REPORT_ARGS
372411
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
373412
elif [ "$FUZZING_LANGUAGE" = "jvm" ]; then
374413
echo "GOING jvm route"
375414
set -x
376415
find $OUT/ -name "jacoco.xml" -exec cp {} $SRC/inspector/ \;
377-
REPORT_ARGS="$REPORT_ARGS --target_dir=$SRC/inspector"
416+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC/inspector"
378417
REPORT_ARGS="$REPORT_ARGS --language=jvm"
379-
python3 /fuzz-introspector/src/main.py report $REPORT_ARGS
418+
fuzz-introspector report $REPORT_ARGS
380419
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
381420
elif [ "$FUZZING_LANGUAGE" = "rust" ]; then
382421
echo "GOING rust route"
383-
REPORT_ARGS="$REPORT_ARGS --target_dir=$SRC/inspector"
422+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC/inspector"
384423
REPORT_ARGS="$REPORT_ARGS --language=rust"
385-
python3 /fuzz-introspector/src/main.py report $REPORT_ARGS
424+
fuzz-introspector report $REPORT_ARGS
386425
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
387426
else
388427
# C/C++
389-
428+
mkdir -p $SRC/inspector
390429
# Correlate fuzzer binaries to fuzz-introspector's raw data
391-
python3 /fuzz-introspector/src/main.py correlate --binaries_dir=$OUT/
430+
fuzz-introspector correlate --binaries-dir=$OUT/
392431

393432
# Generate fuzz-introspector HTML report, this generates
394433
# the file exe_to_fuzz_introspector_logs.yaml
395-
REPORT_ARGS="$REPORT_ARGS --target_dir=$SRC/inspector"
434+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC/inspector"
396435
# Use the just-generated correlation file
397-
REPORT_ARGS="$REPORT_ARGS --correlation_file=exe_to_fuzz_introspector_logs.yaml"
398-
python3 /fuzz-introspector/src/main.py report $REPORT_ARGS
436+
REPORT_ARGS="$REPORT_ARGS --correlation-file=exe_to_fuzz_introspector_logs.yaml"
437+
fuzz-introspector report $REPORT_ARGS
399438

400439
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
401440
fi

infra/base-images/base-builder/install_swift.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ apt-get update && apt install -y $SWIFT_PACKAGES && \
3737
apt install -y $SWIFT_SYMBOLIZER_PACKAGES --no-install-recommends
3838

3939

40-
wget -q https://download.swift.org/swift-5.8.1-release/ubuntu2004/swift-5.8.1-RELEASE/swift-5.8.1-RELEASE-ubuntu20.04.tar.gz
41-
tar xzf swift-5.8.1-RELEASE-ubuntu20.04.tar.gz
42-
cp -r swift-5.8.1-RELEASE-ubuntu20.04/usr/* /usr/
43-
rm -rf swift-5.8.1-RELEASE-ubuntu20.04.tar.gz swift-5.8.1-RELEASE-ubuntu20.04/
40+
wget -q https://download.swift.org/swift-5.10.1-release/ubuntu2004/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-ubuntu20.04.tar.gz
41+
tar xzf swift-5.10.1-RELEASE-ubuntu20.04.tar.gz
42+
cp -r swift-5.10.1-RELEASE-ubuntu20.04/usr/* /usr/
43+
rm -rf swift-5.10.1-RELEASE-ubuntu20.04.tar.gz swift-5.10.1-RELEASE-ubuntu20.04/
4444
# TODO: Move to a seperate work dir
4545
git clone https://github.com/llvm/llvm-project.git
4646
cd llvm-project

infra/base-images/base-clang/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ RUN apt-get update && apt-get install -y wget sudo && \
3636
RUN apt-get update && apt-get install -y git && \
3737
git clone https://github.com/ossf/fuzz-introspector.git fuzz-introspector && \
3838
cd fuzz-introspector && \
39-
git checkout 74917384c5a4e368d900862b4bd3d16ce3fe5dd8 && \
39+
git checkout eab8da2f42d07fb63d28b30c1cc12a2bfcd8e648 && \
4040
git submodule init && \
4141
git submodule update && \
4242
apt-get autoremove --purge -y git && \

0 commit comments

Comments
 (0)