You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Atheris instruments only Python code, so the existing BSON fuzz tasks cannot see memory-safety bugs in the C extensions. This change builds the extensions with ASan and libFuzzer instrumentation and runs the three BSON fuzz targets natively in a daily Evergreen task.
Under FUZZ_NATIVE=1 the fuzz targets also decode inputs through a sentinel-free array.array view, since CPython's hidden NUL sentinel masks over-reads from ASan.
New build and runner scripts rebuild the extensions with clang ASan, verify the instrumentation, and time-box the targets against the spec seed corpus plus fuzz/corpus/.
The fuzz-native task runs both scripts as plain subprocess.exec because the generic run-tests function reinstalls pymongo without sanitizer flags, and runs in the nightly Fuzz RHEL8 variant.
Test Plan
just test test/test_fuzz_shared.py: 14 tests covering the input views, native-mode behavior, and replay of every committed reproducer.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The editable install causes fuzz targets to fall back to Python after extension cleanup, bypassing the instrumented native code and undermining sanitizer coverage.
Adds native AddressSanitizer (ASan) fuzzing for PyMongo’s BSON C extensions, complementing the existing Python-level fuzzing to detect memory-safety errors.
Changes:
Introduces instrumented build and time-boxed runner scripts for the three BSON fuzz targets.
Adds sentinel-free input buffers and tests for native-mode behavior and regression replay.
Schedules daily native fuzzing in Evergreen, moves fuzz variants to larger RHEL8 hosts, and updates documentation.
File
Description
test/test_fuzz_shared.py
Tests input views, target behavior, and committed regression replay.
fuzz/run_native.sh
Prepares seeds and runs time-boxed native fuzzing.
fuzz/README.md
Documents native fuzzing requirements and usage.
fuzz/fuzz_shared.py
Adds native-mode input views and defers the Atheris import.
fuzz/fuzz_is_valid.py
Checks decoding across input views while preserving bytes-only validity checks.
fuzz/fuzz_decode.py
Runs decoding comparisons across input views.
fuzz/fuzz_decode_all.py
Runs multi-document decoding comparisons across input views.
fuzz/build_native.sh
Builds and installs instrumented C extensions with validation checks.
AGENTS.md
Updates the fuzz-directory description to mention native ASan fuzzing.
.evergreen/scripts/test_generate_config.py
Tests native task wiring, scheduling, and host selection.
.evergreen/scripts/generate_config.py
Defines the native task and updates fuzz variants.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The fuzz helper overallocates its input buffer, leaving short over-reads inside addressable memory and preventing ASan from detecting them.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Use an exact-sized copy to expose short over-reads to ASan
fuzz/fuzz_shared.py:81
Constructing an array from bytes overallocates its backing buffer, so removing the NUL sentinel does not put an ASan redzone immediately after the input. For example, an 8-byte input produces an 11-byte allocation, leaving the short over-reads this helper is intended to expose inside addressable memory even with PYTHONMALLOC=malloc. Yield an exact-sized copy (a full array slice allocates exactly its length), and check allocation size in the helper test so this masking cannot recur.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The script unconditionally deletes existing corpus inputs, and its noncanonical path validation allows the deletion to reach directories outside the repository.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because an unpublished finding indicates that fuzz regression silently switches to mutation runs, losing deterministic known-bug coverage.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Both native discovery and capture subprocesses omit Evergreen’s FUZZ_MAX_TIME expansion, silently using 300-second per-target budgets instead of configured values.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Maintainer confirmation is needed that Evergreen’s external PR webhook still selects fuzz-native-regression on the now-untagged fuzzing-rhel8 variant, since repository tests do not cover webhook selection.
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
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.
PYTHON-6169
Changes in this PR
Atheris instruments only Python code, so the existing BSON fuzz tasks cannot see memory-safety bugs in the C extensions. This change builds the extensions with ASan and libFuzzer instrumentation and runs the three BSON fuzz targets natively in a daily Evergreen task.
FUZZ_NATIVE=1the fuzz targets also decode inputs through a sentinel-freearray.arrayview, since CPython's hidden NUL sentinel masks over-reads from ASan.fuzz/corpus/.fuzz-nativetask runs both scripts as plainsubprocess.execbecause the generic run-tests function reinstalls pymongo without sanitizer flags, and runs in the nightlyFuzz RHEL8variant.Test Plan
just test test/test_fuzz_shared.py: 14 tests covering the input views, native-mode behavior, and replay of every committed reproducer.Checklist
Checklist for Author
Checklist for Reviewer