From a9d0d01892db50b2a1c0cf84ed13234340c3f3d0 Mon Sep 17 00:00:00 2001 From: danieljesus Date: Sun, 15 Nov 2026 21:06:33 +0100 Subject: [PATCH 1/4] ci: run the parser tests and fuzzers under ASan and UBSan Several parser regression tests only fail on a broken parser under a sanitizer: a keyblob line written past its table, a 1-byte heap write in the NPDM capability read, a read past an IPSwitch line. The GCC and clang-cl jobs build without one, so those tests could not catch a regression there. A new build-check job builds the tests and the nine fuzz harnesses with LICHII_FUZZERS (clang 21 from apt.llvm.org, ASan and UBSan on every object), runs the parser test tags under them ([fuzz_regressions], [edge_values], [file_sys], [crypto], [cheats], [ncz], [nup-validation]), and runs each harness for 60 seconds from an empty corpus, keeping any crash input as an artifact. LICHII_FUZZERS also stops reporting memcpy/memset with a null pointer and a size of 0 (nonnull-attribute): with -fno-sanitize-recover they ended every run though they touch no memory, and a null pointer with a real size still faults under ASan. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RcHkcwudvegGodeDQGVvr5 --- .github/workflows/build-check.yml | 122 ++++++++++++++++++++++++++++++ CMakeLists.txt | 4 + 2 files changed, 126 insertions(+) diff --git a/.github/workflows/build-check.yml b/.github/workflows/build-check.yml index 12e0380dac1..4f9bfdc2ca6 100644 --- a/.github/workflows/build-check.yml +++ b/.github/workflows/build-check.yml @@ -162,6 +162,128 @@ jobs: .ccache key: gcc13-qt683-${{ runner.os }}-${{ github.sha }} + linux-clang-sanitizers: + name: Linux clang parser tests and fuzzers under ASan and UBSan + needs: changes + if: needs.changes.outputs.build == 'true' + runs-on: ubuntu-24.04 + timeout-minutes: 120 + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 1G + CCACHE_COMPILERCHECK: content + # LeakSanitizer reports a few start-up allocations once per process (docs/Fuzzing.md). + # The clang the fuzz tree is known to build with, from apt.llvm.org as release-binaries.yml + # installs its PGO clang; Ubuntu 24.04's clang 18 is untested here. + SAN_LLVM_VERSION: "21" + ASAN_OPTIONS: detect_leaks=0 + UBSAN_OPTIONS: print_stacktrace=1 + steps: + - name: Check out source + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 + with: + persist-credentials: false + + - name: Install Linux dependencies + run: | + curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | + sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc > /dev/null + echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-$SAN_LLVM_VERSION main" | + sudo tee /etc/apt/sources.list.d/llvm.list > /dev/null + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + "clang-$SAN_LLVM_VERSION" "libclang-rt-$SAN_LLVM_VERSION-dev" \ + autoconf git glslang-tools libglu1-mesa-dev \ + libpulse-dev libtool libudev-dev mesa-common-dev nasm ninja-build \ + libavfilter-dev libavcodec-dev libswscale-dev pkg-config zlib1g-dev \ + libva-dev libvdpau-dev spirv-tools spirv-headers libusb-1.0-0-dev \ + libboost-dev libboost-fiber-dev libboost-context-dev libopus-dev \ + libasound2-dev ccache pipx + pipx install cmake==4.4.4 + echo "$HOME/.local/bin" >> "$GITHUB_PATH" + + - name: Restore dependencies and compiler objects + uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 + with: + path: | + .cache/cpm + .ccache + key: clang-sanitizers-${{ runner.os }}-${{ github.sha }} + restore-keys: | + clang-sanitizers-${{ runner.os }}- + + # LICHII_FUZZERS builds everything with ASan and UBSan; the tests target then runs under + # them too, which is what the ASan-only parser regressions need. + - name: Configure sanitizer build + run: | + cmake -S . -B build-san -G Ninja \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + "-DCMAKE_C_COMPILER=clang-$SAN_LLVM_VERSION" \ + "-DCMAKE_CXX_COMPILER=clang++-$SAN_LLVM_VERSION" \ + -DLICHII_FUZZERS=ON \ + -DLICHII_TESTS=ON \ + -DENABLE_WERROR=OFF \ + -DENABLE_QT=OFF \ + -DLICHII_CMD=OFF \ + -DLICHII_ROOM=OFF \ + -DLICHII_ROOM_STANDALONE=OFF \ + -DLICHII_USE_BUNDLED_SDL3=ON \ + -DVulkanHeaders_FORCE_BUNDLED=ON \ + -DVulkanUtilityLibraries_FORCE_BUNDLED=ON \ + -DUSE_DISCORD_PRESENCE=OFF \ + -DUSE_CCACHE=ON + + - name: Build tests and fuzzers + run: | + ccache --zero-stats + cmake --build build-san --parallel "$(nproc)" --target tests \ + fuzz_partition_romfs fuzz_nca fuzz_package fuzz_cheats fuzz_ips fuzz_meta \ + fuzz_nup fuzz_ncz fuzz_keys + ccache --show-stats + + # The parser tests: the fuzzers' inputs, the header edge values and each parser's own + # cases. Several of them only fail on a broken parser under a sanitizer. + - name: Run parser tests under the sanitizers + run: | + build-san/bin/tests \ + "[fuzz_regressions],[edge_values],[file_sys],[crypto],[cheats],[ncz],[nup-validation]" + + # A short run of each harness from an empty corpus (the NUP one from a made-up seed), to + # catch a parser change that crashes on the first inputs. Longer runs are done by hand + # (docs/Fuzzing.md). + - name: Smoke-run the fuzzers + run: | + mkdir -p fuzz-ci/nup + FUZZ_NUP_SEED=fuzz-ci/nup/seed.nup build-san/bin/fuzz_nup + for harness in partition_romfs nca package cheats ips meta nup ncz keys; do + mkdir -p "fuzz-ci/$harness" + echo "::group::fuzz_$harness" + (cd "fuzz-ci/$harness" && "../../build-san/bin/fuzz_$harness" . \ + -max_total_time=60 -max_len=32768 -rss_limit_mb=2048 -malloc_limit_mb=2048 \ + -timeout=25 -print_final_stats=1) + echo "::endgroup::" + done + + - name: Keep fuzzer crash inputs + if: failure() + uses: actions/upload-artifact@v7 + with: + name: fuzzer-crashes + path: | + fuzz-ci/*/crash-* + fuzz-ci/*/oom-* + fuzz-ci/*/timeout-* + if-no-files-found: ignore + + - name: Save dependencies and compiler objects + if: always() + uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 + with: + path: | + .cache/cpm + .ccache + key: clang-sanitizers-${{ runner.os }}-${{ github.sha }} + windows-clang-cl: name: Windows clang-cl production build and tests needs: changes diff --git a/CMakeLists.txt b/CMakeLists.txt index a388417d190..90c593a2be4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,10 @@ if (LICHII_FUZZERS) add_compile_options( $<$:-fsanitize=address,undefined,fuzzer-no-link> $<$:-fno-sanitize-recover=undefined> + # memcpy and memset with a null pointer and a size of 0 would stop every run under + # -fno-sanitize-recover, though they touch no memory; a null pointer with a real size + # still faults, and ASan reports that. + $<$:-fno-sanitize=nonnull-attribute> $<$:-fno-omit-frame-pointer>) add_link_options(-fsanitize=address,undefined) endif() From cea81b08f2fc5664621dc55f094da82aba684e0e Mon Sep 17 00:00:00 2001 From: danieljesus Date: Mon, 16 Nov 2026 01:21:33 +0100 Subject: [PATCH 2/4] ci: start the NCA, package and NCZ fuzzer smoke runs from made-up seeds From an empty corpus, the 60 s runs of fuzz_nca and fuzz_ncz never got past the header magic at 0x200 or 0x4000, so they checked almost none of those parsers. Write each harness's FUZZ_*_SEED seeds into its corpus directory first, as the NUP run already does. -runs=0 makes a harness without seed support exit after one empty input instead of fuzzing with no time limit. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RcHkcwudvegGodeDQGVvr5 --- .github/workflows/build-check.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-check.yml b/.github/workflows/build-check.yml index 4f9bfdc2ca6..c7570edd75a 100644 --- a/.github/workflows/build-check.yml +++ b/.github/workflows/build-check.yml @@ -248,13 +248,17 @@ jobs: build-san/bin/tests \ "[fuzz_regressions],[edge_values],[file_sys],[crypto],[cheats],[ncz],[nup-validation]" - # A short run of each harness from an empty corpus (the NUP one from a made-up seed), to - # catch a parser change that crashes on the first inputs. Longer runs are done by hand + # A short run of each harness, to catch a parser change that crashes on the first inputs. + # The NUP, NCA, package and NCZ ones start from made-up seeds: from an empty corpus the NCA + # and NCZ ones never get past their header magic. Longer runs are done by hand # (docs/Fuzzing.md). - name: Smoke-run the fuzzers run: | mkdir -p fuzz-ci/nup FUZZ_NUP_SEED=fuzz-ci/nup/seed.nup build-san/bin/fuzz_nup + FUZZ_NCA_SEED=fuzz-ci/nca build-san/bin/fuzz_nca -runs=0 + FUZZ_PACKAGE_SEED=fuzz-ci/package build-san/bin/fuzz_package -runs=0 + FUZZ_NCZ_SEED=fuzz-ci/ncz build-san/bin/fuzz_ncz -runs=0 for harness in partition_romfs nca package cheats ips meta nup ncz keys; do mkdir -p "fuzz-ci/$harness" echo "::group::fuzz_$harness" From cedb74b50f35e329b391c4494b4c075771084495 Mon Sep 17 00:00:00 2001 From: danieljesus Date: Wed, 18 Nov 2026 06:56:11 +0100 Subject: [PATCH 3/4] ci: run the sanitizer job nightly and on parser pull requests only In build-check the job ran on every pull request, and with a per-commit cache key each run started cold (84 min of compiling) and saved another 0.5 GB to a repository cache already at its limit. It moves to its own sanitizers workflow: - each night on nx2, by hand, and on pull requests that touch file_sys, crypto, loader, the fuzzers or the core tests; - only nx2 runs save the compiler cache, and they drop the older entry, so the job keeps one cache in all and pull requests restore it; - it is no longer part of build-check, so it doesn't hold up merges. docs/Fuzzing.md says where it runs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RcHkcx3CbFgcY6d7BpdyKC --- .github/workflows/build-check.yml | 126 ---------------------- .github/workflows/sanitizers.yml | 171 ++++++++++++++++++++++++++++++ docs/Fuzzing.md | 4 + 3 files changed, 175 insertions(+), 126 deletions(-) create mode 100644 .github/workflows/sanitizers.yml diff --git a/.github/workflows/build-check.yml b/.github/workflows/build-check.yml index 0b5e4859ac5..c6ab3d88e45 100644 --- a/.github/workflows/build-check.yml +++ b/.github/workflows/build-check.yml @@ -163,132 +163,6 @@ jobs: .ccache key: gcc13-qt683-${{ runner.os }}-${{ github.sha }} - linux-clang-sanitizers: - name: Linux clang parser tests and fuzzers under ASan and UBSan - needs: changes - if: needs.changes.outputs.build == 'true' - runs-on: ubuntu-24.04 - timeout-minutes: 120 - env: - CCACHE_DIR: ${{ github.workspace }}/.ccache - CCACHE_MAXSIZE: 1G - CCACHE_COMPILERCHECK: content - # LeakSanitizer reports a few start-up allocations once per process (docs/Fuzzing.md). - # The clang the fuzz tree is known to build with, from apt.llvm.org as release-binaries.yml - # installs its PGO clang; Ubuntu 24.04's clang 18 is untested here. - SAN_LLVM_VERSION: "21" - ASAN_OPTIONS: detect_leaks=0 - UBSAN_OPTIONS: print_stacktrace=1 - steps: - - name: Check out source - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 - with: - persist-credentials: false - - - name: Install Linux dependencies - run: | - curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | - sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc > /dev/null - echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-$SAN_LLVM_VERSION main" | - sudo tee /etc/apt/sources.list.d/llvm.list > /dev/null - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - "clang-$SAN_LLVM_VERSION" "libclang-rt-$SAN_LLVM_VERSION-dev" \ - autoconf git glslang-tools libglu1-mesa-dev \ - libpulse-dev libtool libudev-dev mesa-common-dev nasm ninja-build \ - libavfilter-dev libavcodec-dev libswscale-dev pkg-config zlib1g-dev \ - libva-dev libvdpau-dev spirv-tools spirv-headers libusb-1.0-0-dev \ - libboost-dev libboost-fiber-dev libboost-context-dev libopus-dev \ - libasound2-dev ccache pipx - pipx install cmake==4.4.4 - echo "$HOME/.local/bin" >> "$GITHUB_PATH" - - - name: Restore dependencies and compiler objects - uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 - with: - path: | - .cache/cpm - .ccache - key: clang-sanitizers-${{ runner.os }}-${{ github.sha }} - restore-keys: | - clang-sanitizers-${{ runner.os }}- - - # LICHII_FUZZERS builds everything with ASan and UBSan; the tests target then runs under - # them too, which is what the ASan-only parser regressions need. - - name: Configure sanitizer build - run: | - cmake -S . -B build-san -G Ninja \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - "-DCMAKE_C_COMPILER=clang-$SAN_LLVM_VERSION" \ - "-DCMAKE_CXX_COMPILER=clang++-$SAN_LLVM_VERSION" \ - -DLICHII_FUZZERS=ON \ - -DLICHII_TESTS=ON \ - -DENABLE_WERROR=OFF \ - -DENABLE_QT=OFF \ - -DLICHII_CMD=OFF \ - -DLICHII_ROOM=OFF \ - -DLICHII_ROOM_STANDALONE=OFF \ - -DLICHII_USE_BUNDLED_SDL3=ON \ - -DVulkanHeaders_FORCE_BUNDLED=ON \ - -DVulkanUtilityLibraries_FORCE_BUNDLED=ON \ - -DUSE_DISCORD_PRESENCE=OFF \ - -DUSE_CCACHE=ON - - - name: Build tests and fuzzers - run: | - ccache --zero-stats - cmake --build build-san --parallel "$(nproc)" --target tests \ - fuzz_partition_romfs fuzz_nca fuzz_package fuzz_cheats fuzz_ips fuzz_meta \ - fuzz_nup fuzz_ncz fuzz_keys - ccache --show-stats - - # The parser tests: the fuzzers' inputs, the header edge values and each parser's own - # cases. Several of them only fail on a broken parser under a sanitizer. - - name: Run parser tests under the sanitizers - run: | - build-san/bin/tests \ - "[fuzz_regressions],[edge_values],[file_sys],[crypto],[cheats],[ncz],[nup-validation]" - - # A short run of each harness, to catch a parser change that crashes on the first inputs. - # The NUP, NCA, package and NCZ ones start from made-up seeds: from an empty corpus the NCA - # and NCZ ones never get past their header magic. Longer runs are done by hand - # (docs/Fuzzing.md). - - name: Smoke-run the fuzzers - run: | - mkdir -p fuzz-ci/nup - FUZZ_NUP_SEED=fuzz-ci/nup/seed.nup build-san/bin/fuzz_nup - FUZZ_NCA_SEED=fuzz-ci/nca build-san/bin/fuzz_nca -runs=0 - FUZZ_PACKAGE_SEED=fuzz-ci/package build-san/bin/fuzz_package -runs=0 - FUZZ_NCZ_SEED=fuzz-ci/ncz build-san/bin/fuzz_ncz -runs=0 - for harness in partition_romfs nca package cheats ips meta nup ncz keys; do - mkdir -p "fuzz-ci/$harness" - echo "::group::fuzz_$harness" - (cd "fuzz-ci/$harness" && "../../build-san/bin/fuzz_$harness" . \ - -max_total_time=60 -max_len=32768 -rss_limit_mb=2048 -malloc_limit_mb=2048 \ - -timeout=25 -print_final_stats=1) - echo "::endgroup::" - done - - - name: Keep fuzzer crash inputs - if: failure() - uses: actions/upload-artifact@v7 - with: - name: fuzzer-crashes - path: | - fuzz-ci/*/crash-* - fuzz-ci/*/oom-* - fuzz-ci/*/timeout-* - if-no-files-found: ignore - - - name: Save dependencies and compiler objects - if: always() - uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 - with: - path: | - .cache/cpm - .ccache - key: clang-sanitizers-${{ runner.os }}-${{ github.sha }} - windows-clang-cl: name: Windows clang-cl production build and tests needs: changes diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml new file mode 100644 index 00000000000..74eb91ef697 --- /dev/null +++ b/.github/workflows/sanitizers.yml @@ -0,0 +1,171 @@ +name: sanitizers + +# The parser tests and the fuzzer harnesses under ASan and UBSan. They run each night on nx2 and +# on pull requests that touch the parsers, the fuzzers or their tests, instead of in build-check +# on every pull request: a cold build takes over an hour. Pull requests restore the nightly +# compiler cache, so theirs only rebuild what they change. The check is not required: a failure +# reports the crashing inputs as an artifact. +on: + schedule: + - cron: "23 3 * * *" + workflow_dispatch: + pull_request: + branches: [nx2] + paths: + - "src/core/file_sys/**" + - "src/core/crypto/**" + - "src/core/loader/**" + - "src/fuzz/**" + - "src/tests/core/**" + - ".github/workflows/sanitizers.yml" + +permissions: + contents: read + +concurrency: + group: sanitizers-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + linux-clang-sanitizers: + name: Linux clang parser tests and fuzzers under ASan and UBSan + runs-on: ubuntu-24.04 + permissions: + contents: read + actions: write # drops the older compiler cache + timeout-minutes: 120 + env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 1G + CCACHE_COMPILERCHECK: content + # LeakSanitizer reports a few start-up allocations once per process (docs/Fuzzing.md). + # The clang the fuzz tree is known to build with, from apt.llvm.org as release-binaries.yml + # installs its PGO clang; Ubuntu 24.04's clang 18 is untested here. + SAN_LLVM_VERSION: "21" + ASAN_OPTIONS: detect_leaks=0 + UBSAN_OPTIONS: print_stacktrace=1 + steps: + - name: Check out source + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 + with: + persist-credentials: false + + - name: Install Linux dependencies + run: | + curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | + sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc > /dev/null + echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-$SAN_LLVM_VERSION main" | + sudo tee /etc/apt/sources.list.d/llvm.list > /dev/null + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + "clang-$SAN_LLVM_VERSION" "libclang-rt-$SAN_LLVM_VERSION-dev" \ + autoconf git glslang-tools libglu1-mesa-dev \ + libpulse-dev libtool libudev-dev mesa-common-dev nasm ninja-build \ + libavfilter-dev libavcodec-dev libswscale-dev pkg-config zlib1g-dev \ + libva-dev libvdpau-dev spirv-tools spirv-headers libusb-1.0-0-dev \ + libboost-dev libboost-fiber-dev libboost-context-dev libopus-dev \ + libasound2-dev ccache pipx + pipx install cmake==4.4.4 + echo "$HOME/.local/bin" >> "$GITHUB_PATH" + + - name: Restore dependencies and compiler objects + uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 + with: + path: | + .cache/cpm + .ccache + key: clang-sanitizers-${{ runner.os }}-${{ github.run_id }} + restore-keys: | + clang-sanitizers-${{ runner.os }}- + + # LICHII_FUZZERS builds everything with ASan and UBSan; the tests target then runs under + # them too, which is what the ASan-only parser regressions need. + - name: Configure sanitizer build + run: | + cmake -S . -B build-san -G Ninja \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + "-DCMAKE_C_COMPILER=clang-$SAN_LLVM_VERSION" \ + "-DCMAKE_CXX_COMPILER=clang++-$SAN_LLVM_VERSION" \ + -DLICHII_FUZZERS=ON \ + -DLICHII_TESTS=ON \ + -DENABLE_WERROR=OFF \ + -DENABLE_QT=OFF \ + -DLICHII_CMD=OFF \ + -DLICHII_ROOM=OFF \ + -DLICHII_ROOM_STANDALONE=OFF \ + -DLICHII_USE_BUNDLED_SDL3=ON \ + -DVulkanHeaders_FORCE_BUNDLED=ON \ + -DVulkanUtilityLibraries_FORCE_BUNDLED=ON \ + -DUSE_DISCORD_PRESENCE=OFF \ + -DUSE_CCACHE=ON + + - name: Build tests and fuzzers + run: | + ccache --zero-stats + cmake --build build-san --parallel "$(nproc)" --target tests \ + fuzz_partition_romfs fuzz_nca fuzz_package fuzz_cheats fuzz_ips fuzz_meta \ + fuzz_nup fuzz_ncz fuzz_keys + ccache --show-stats + + # The parser tests: the fuzzers' inputs, the header edge values and each parser's own + # cases. Several of them only fail on a broken parser under a sanitizer. + - name: Run parser tests under the sanitizers + run: | + build-san/bin/tests \ + "[fuzz_regressions],[edge_values],[file_sys],[crypto],[cheats],[ncz],[nup-validation]" + + # A short run of each harness, to catch a parser change that crashes on the first inputs. + # The NUP, NCA, package and NCZ ones start from made-up seeds: from an empty corpus the NCA + # and NCZ ones never get past their header magic. Longer runs are done by hand + # (docs/Fuzzing.md). + - name: Smoke-run the fuzzers + run: | + mkdir -p fuzz-ci/nup + FUZZ_NUP_SEED=fuzz-ci/nup/seed.nup build-san/bin/fuzz_nup + FUZZ_NCA_SEED=fuzz-ci/nca build-san/bin/fuzz_nca -runs=0 + FUZZ_PACKAGE_SEED=fuzz-ci/package build-san/bin/fuzz_package -runs=0 + FUZZ_NCZ_SEED=fuzz-ci/ncz build-san/bin/fuzz_ncz -runs=0 + for harness in partition_romfs nca package cheats ips meta nup ncz keys; do + mkdir -p "fuzz-ci/$harness" + echo "::group::fuzz_$harness" + (cd "fuzz-ci/$harness" && "../../build-san/bin/fuzz_$harness" . \ + -max_total_time=60 -max_len=32768 -rss_limit_mb=2048 -malloc_limit_mb=2048 \ + -timeout=25 -print_final_stats=1) + echo "::endgroup::" + done + + - name: Keep fuzzer crash inputs + if: failure() + uses: actions/upload-artifact@v7 + with: + name: fuzzer-crashes + path: | + fuzz-ci/*/crash-* + fuzz-ci/*/oom-* + fuzz-ci/*/timeout-* + if-no-files-found: ignore + + # Only the nx2 runs save, and they drop the older entry: one cache of about 0.5 GB in all, + # which pull requests restore without adding their own. + - name: Save dependencies and compiler objects + if: always() && github.event_name != 'pull_request' + uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 + with: + path: | + .cache/cpm + .ccache + key: clang-sanitizers-${{ runner.os }}-${{ github.run_id }} + + - name: Drop older compiler caches + if: always() && github.event_name != 'pull_request' + env: + GH_TOKEN: ${{ github.token }} + KEEP: clang-sanitizers-${{ runner.os }}-${{ github.run_id }} + run: | + gh cache list --repo "$GITHUB_REPOSITORY" --key "clang-sanitizers-${RUNNER_OS}-" \ + --limit 100 --json key --jq '.[].key' | + while read -r key; do + if [ "$key" != "$KEEP" ]; then + gh cache delete "$key" --repo "$GITHUB_REPOSITORY" || true + fi + done diff --git a/docs/Fuzzing.md b/docs/Fuzzing.md index db072269872..d2bf8ae35e0 100644 --- a/docs/Fuzzing.md +++ b/docs/Fuzzing.md @@ -32,3 +32,7 @@ Start `fuzz_nca`, `fuzz_package` and `fuzz_ncz` from their `FUZZ_*_SEED` seeds ( Each harness file starts with the flags it was run with. `fuzz_meta` and `fuzz_ncz` reach header fields that size allocations, so give them `-rss_limit_mb` and `-malloc_limit_mb`, and use `-fork=1 -ignore_ooms=1` to keep going past out-of-memory reports. `fuzz_keys` needs `ASAN_OPTIONS=detect_leaks=0`: LeakSanitizer reports about 65 bytes allocated at start-up, once per process, not per input. With `-DLICHII_TESTS=ON`, the same build directory also builds `tests` under the sanitizers. + +## In CI + +The `sanitizers` workflow (`.github/workflows/sanitizers.yml`) builds `tests` and the harnesses with `LICHII_FUZZERS=ON`, runs the parser test tags under ASan and UBSan and gives each harness a 60-second run. It runs each night on nx2, by hand (`workflow_dispatch`), and on pull requests that touch `src/core/file_sys`, `src/core/crypto`, `src/core/loader`, `src/fuzz` or `src/tests/core`. Only the nx2 runs save its compiler cache, one entry in all, and pull requests restore it. The check is not required. When a harness crashes, its inputs are uploaded as the `fuzzer-crashes` artifact: replay them as above. From e04c56d2b8ff4e890f4c3f0e5bd364c00a5d1205 Mon Sep 17 00:00:00 2001 From: danieljesus Date: Wed, 18 Nov 2026 07:39:27 +0100 Subject: [PATCH 4/4] ci: sanitizers saves and prunes its cache only on nx2, after the new entry exists - The pull request filter also covers the cheat parser (core/memory/cheat_engine), which fuzz_cheats checks. - A manual run on another branch saved a cache no pull request could restore, then deleted nx2's. Saving and pruning now need refs/heads/nx2. - If the save failed or was skipped, the prune named an entry that didn't exist and deleted every older one. It now lists nx2's entries first and deletes nothing unless the new key is among them. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RcHkcx3CbFgcY6d7BpdyKC --- .github/workflows/sanitizers.yml | 25 ++++++++++++++++--------- docs/Fuzzing.md | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index 74eb91ef697..940d0a2049f 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -15,6 +15,7 @@ on: - "src/core/file_sys/**" - "src/core/crypto/**" - "src/core/loader/**" + - "src/core/memory/cheat_engine.*" - "src/fuzz/**" - "src/tests/core/**" - ".github/workflows/sanitizers.yml" @@ -148,7 +149,7 @@ jobs: # Only the nx2 runs save, and they drop the older entry: one cache of about 0.5 GB in all, # which pull requests restore without adding their own. - name: Save dependencies and compiler objects - if: always() && github.event_name != 'pull_request' + if: always() && github.event_name != 'pull_request' && github.ref == 'refs/heads/nx2' uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 with: path: | @@ -156,16 +157,22 @@ jobs: .ccache key: clang-sanitizers-${{ runner.os }}-${{ github.run_id }} + # Only once the new entry is there: a save that failed or was skipped keeps the old one. - name: Drop older compiler caches - if: always() && github.event_name != 'pull_request' + if: always() && github.event_name != 'pull_request' && github.ref == 'refs/heads/nx2' env: GH_TOKEN: ${{ github.token }} KEEP: clang-sanitizers-${{ runner.os }}-${{ github.run_id }} run: | - gh cache list --repo "$GITHUB_REPOSITORY" --key "clang-sanitizers-${RUNNER_OS}-" \ - --limit 100 --json key --jq '.[].key' | - while read -r key; do - if [ "$key" != "$KEEP" ]; then - gh cache delete "$key" --repo "$GITHUB_REPOSITORY" || true - fi - done + caches="repos/$GITHUB_REPOSITORY/actions/caches" + keys=$(gh api "$caches?key=clang-sanitizers-${RUNNER_OS}-&ref=refs/heads/nx2&per_page=100" \ + --jq '.actions_caches[].key') + if ! printf '%s\n' "$keys" | grep -qxF "$KEEP"; then + echo "The new cache $KEEP is not there; keeping the older ones." + exit 0 + fi + printf '%s\n' "$keys" | while read -r key; do + if [ -n "$key" ] && [ "$key" != "$KEEP" ]; then + gh api -X DELETE "$caches?key=$key&ref=refs/heads/nx2" > /dev/null || true + fi + done diff --git a/docs/Fuzzing.md b/docs/Fuzzing.md index d2bf8ae35e0..cb62d447e64 100644 --- a/docs/Fuzzing.md +++ b/docs/Fuzzing.md @@ -35,4 +35,4 @@ With `-DLICHII_TESTS=ON`, the same build directory also builds `tests` under the ## In CI -The `sanitizers` workflow (`.github/workflows/sanitizers.yml`) builds `tests` and the harnesses with `LICHII_FUZZERS=ON`, runs the parser test tags under ASan and UBSan and gives each harness a 60-second run. It runs each night on nx2, by hand (`workflow_dispatch`), and on pull requests that touch `src/core/file_sys`, `src/core/crypto`, `src/core/loader`, `src/fuzz` or `src/tests/core`. Only the nx2 runs save its compiler cache, one entry in all, and pull requests restore it. The check is not required. When a harness crashes, its inputs are uploaded as the `fuzzer-crashes` artifact: replay them as above. +The `sanitizers` workflow (`.github/workflows/sanitizers.yml`) builds `tests` and the harnesses with `LICHII_FUZZERS=ON`, runs the parser test tags under ASan and UBSan and gives each harness a 60-second run. It runs each night on nx2, by hand (`workflow_dispatch`), and on pull requests that touch `src/core/file_sys`, `src/core/crypto`, `src/core/loader`, the cheat parser, `src/fuzz` or `src/tests/core`. Only the nx2 runs save its compiler cache, one entry in all, and pull requests restore it. The check is not required. When a harness crashes, its inputs are uploaded as the `fuzzer-crashes` artifact: replay them as above.