Skip to content

Add ASan flag propagation for fuzz testing - #9

Merged
xnorpx merged 1 commit into
xnorpx:mainfrom
alejandroechev:alejandroe/asan-fuzz-support
May 12, 2026
Merged

Add ASan flag propagation for fuzz testing#9
xnorpx merged 1 commit into
xnorpx:mainfrom
alejandroechev:alejandroe/asan-fuzz-support

Conversation

@alejandroechev

@alejandroechev alejandroechev commented May 12, 2026

Copy link
Copy Markdown

Summary

When building under cargo-fuzz, propagate AddressSanitizer flags to the CMake C build so ASan can detect memory errors (buffer overflows, use-after-free, etc.) in the native Opus C code when fuzz testing through Rust FFI wrappers.

Changes

Single change in build.rs: detect CARGO_CFG_FUZZING (set automatically by cargo-fuzz) and pass -fsanitize=address, -fno-omit-frame-pointer, and -g to the CMake C compiler.

Impact

  • Zero impact on normal builds - flags only activate when CARGO_CFG_FUZZING is set
  • Enables ASan in fuzz testing - memory errors in libopus C code are now detectable

Validation

Tested in the media_components nightly pipeline by injecting an intentional heap-buffer-overflow in opus_decode_float and confirming ASan caught it with full source attribution:

==17998==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000178c
WRITE of size 1 at 0x60200000178c thread T0
    #0 opus_decode_float opus_decoder.c:1000:12

Pipeline run: https://skype.visualstudio.com/SCC/_build/results?buildId=77788743

When building under cargo-fuzz (detected via CARGO_CFG_FUZZING env var),
pass -fsanitize=address, -fno-omit-frame-pointer, and -g to the CMake
C build. This enables AddressSanitizer to detect memory errors in the
native Opus C code when fuzz testing through Rust FFI wrappers.

Zero impact on normal builds - flags only activate during fuzzing.

Co-authored-by: Copilot <[email protected]>
@xnorpx
xnorpx merged commit 60484a0 into xnorpx:main May 12, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants