This is a draft pull request, so Ralph reviewed only its concept. Code review runs on the first push after it is marked ready for review.
Design and approach
The goal is to make MSan fuzz runs usable without startup false positives while retaining sanitizer checking. The targeted upstream workaround is worth pursuing: #30760 records a failure before testing, and OSS-Fuzz #16707 reports successful corpus execution after unpoisoning startup arguments. This is downstream operational evidence, not independent validation across toolchains.
This proposal confines the treatment to argument storage before SetArgs, preserves option forwarding, and leaves the fuzz-input callback unchanged. The decisive question is whether supported callers supply fully initialized argument storage, so clearing its shadow removes stale state rather than hiding a real engine defect. Establish the affected configurations without assuming this resolves every historical MSan failure, and keep any CI re-enabling of libFuzzer separate.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
Reading command-line arguments during fuzz initialization is intentional: it lets tests receive Bitcoin Core configuration options rather than reserving all arguments for the fuzz engine.
The original proposal, #23373, sought more flexible tests and configurable addrman consistency checking. At the pinned base, LLVMFuzzerInitialize calls SetArgs before target initialization; SetArgs retains double-dash arguments for BasicTestingSetup while leaving engine arguments distinct. This explains why instrumented harness code reads argc and argv at this boundary.
The downstream diagnosis attributes the startup warning to stale sanitizer shadow state across an instrumentation boundary, not to genuinely uninitialized command-line values.
OSS-Fuzz #16707 describes use-after-destruction instrumentation poisoning temporary-object stack storage during global initialization. Uninstrumented libFuzzer main then reuses that storage for argc/argv without clearing its shadow, and instrumented SetArgs encounters the stale poison. Bitcoin Core #30760 independently records the same startup call chain and a destruction origin in global initialization. The patch acts immediately before that argument read.
The downstream workaround was deliberately limited to startup argument storage so that full MSan and use-after-destruction checking could remain enabled.
OSS-Fuzz #16707 explicitly describes unpoisoning argc, argv, the pointer array including its terminating null entry, and the argument strings while retaining those checks. It reports successful corpus execution after an Ubuntu 24.04 migration that had previously been reverted because it broke MSan plus libFuzzer. The pinned head follows that same boundary treatment under an MSan feature guard.
Earlier Bitcoin Core CI history explicitly traded some fuzz-engine functionality for dependable MSan execution when repeated false positives lacked a known cause.
Proposal #33666 dropped libFuzzer from the MSan fuzz task, accepting loss of nonessential statistics and the 60-second fuzz-from-scratch sanity check for targets without a corpus. A participant reported that libFuzzer plus MSan worked in a different infrastructure setup, including a different LLVM version. This establishes the operational cost of the historical workaround without establishing that every environment has the same failure.
Ralph's inferences
The affected boundary treats process-startup arguments as initialized harness configuration, separately from the fuzz-generated bytes under test.
The pinned documentation warns that MSan requires linked code to be instrumented. Against that constraint, the head introduces a narrowly scoped shadow-state adjustment in LLVMFuzzerInitialize, while LLVMFuzzerTestOneInput continues forwarding its input buffer unchanged. The design tradeoff is therefore about sanitizer interoperability at startup, rather than weakening Bitcoin protocol validation or reclassifying fuzz input as initialized.