|
| 1 | +#!/bin/bash -eu |
| 2 | + |
| 3 | +# Install grpcio-tools first so generate_proto.py can compile the protobufs. |
| 4 | +pip3 install grpcio-tools |
| 5 | + |
| 6 | +# Generate the protobuf Python bindings required by the SDK. |
| 7 | +python3 generate_proto.py |
| 8 | + |
| 9 | +# Install the SDK and all runtime dependencies (uses current CFLAGS/CXXFLAGS so |
| 10 | +# any C extensions such as grpcio and cryptography are built with the right flags). |
| 11 | +pip3 install . |
| 12 | + |
| 13 | +# Install Atheris (the Python fuzzing engine) and PyInstaller (used to produce |
| 14 | +# self-contained fuzzer executables that ClusterFuzzLite can run reliably). |
| 15 | +pip3 install atheris pyinstaller |
| 16 | + |
| 17 | +# Build every *_fuzzer.py target found in the .clusterfuzzlite directory. |
| 18 | +for fuzzer in $(find "$SRC/hiero-sdk-python/.clusterfuzzlite" -name '*_fuzzer.py'); do |
| 19 | + fuzzer_basename=$(basename -s .py "$fuzzer") |
| 20 | + fuzzer_package="${fuzzer_basename}.pkg" |
| 21 | + |
| 22 | + # Bundle the fuzzer and all its dependencies into a single portable package. |
| 23 | + pyinstaller --distpath "$OUT" --onefile --name "$fuzzer_package" "$fuzzer" |
| 24 | + |
| 25 | + # Write a thin shell wrapper that ClusterFuzzLite uses to invoke the fuzzer. |
| 26 | + # The wrapper preloads the sanitizer library and sets ASAN_OPTIONS. |
| 27 | + # LD_PRELOAD is required here because the SDK uses C extensions (grpcio, |
| 28 | + # cryptography, protobuf) that must be covered by the sanitizer. |
| 29 | + cat > "$OUT/$fuzzer_basename" << EOF |
| 30 | +#!/bin/sh |
| 31 | +# LLVMFuzzerTestOneInput for fuzzer detection. |
| 32 | +this_dir=\$(dirname "\$0") |
| 33 | +LD_PRELOAD=\$this_dir/sanitizer_with_fuzzer.so \\ |
| 34 | +PYCRYPTODOME_DISABLE_DEEPBIND=1 \\ |
| 35 | +ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$this_dir/llvm-symbolizer:detect_leaks=0 \\ |
| 36 | + "\$this_dir/$fuzzer_package" "\$@" |
| 37 | +EOF |
| 38 | + chmod +x "$OUT/$fuzzer_basename" |
| 39 | +done |
0 commit comments