Add ASan flag propagation for fuzz testing - #9
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: detectCARGO_CFG_FUZZING(set automatically by cargo-fuzz) and pass-fsanitize=address,-fno-omit-frame-pointer, and-gto the CMake C compiler.Impact
CARGO_CFG_FUZZINGis setValidation
Tested in the media_components nightly pipeline by injecting an intentional heap-buffer-overflow in
opus_decode_floatand confirming ASan caught it with full source attribution:Pipeline run: https://skype.visualstudio.com/SCC/_build/results?buildId=77788743