Skip to content

Commit 3aaf732

Browse files
committed
Merge bitcoin/bitcoin#29774: build: Enable fuzz binary in MSVC
18fd522 ci, msvc: Add "Run fuzz binaries" step (Hennadii Stepanov) 52933d7 fuzz: Pass `SystemRoot` environment variable to subprocess (Hennadii Stepanov) 23cb820 ci, msvc: Add "Clone fuzz corpus" step (Hennadii Stepanov) 19dcedd build, msvc: Build `fuzz.exe` binary (Hennadii Stepanov) 4c078d7 build, msvc: Enable preprocessor conformance mode (Hennadii Stepanov) 09f5a74 fuzz: Re-implement `read_stdin` in portable way (Hennadii Stepanov) Pull request description: Closes bitcoin/bitcoin#29760. Suggested in bitcoin/bitcoin#29758 (comment). ACKs for top commit: maflcko: lgtm ACK 18fd522 🔍 sipsorcery: tACK 18fd522 sipa: utACK 18fd522 Tree-SHA512: 672ed6926ee9091f68f13780e77b60fc1d48731f16e847d849374f8426ffe1dafd9bcab06a27af62e8052ba345bb57f20f40579d6be8540c12ef85c23a6eec8b
2 parents 7fee0ca + 18fd522 commit 3aaf732

File tree

10 files changed

+131
-10
lines changed

10 files changed

+131
-10
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,16 @@ jobs:
295295
TEST_RUNNER_EXTRA: ${{ github.event_name != 'pull_request' && '--extended' || '' }}
296296
shell: cmd
297297
run: py -3 test\functional\test_runner.py --jobs %NUMBER_OF_PROCESSORS% --ci --quiet --tmpdirprefix=%RUNNER_TEMP% --combinedlogslen=99999999 --timeout-factor=%TEST_RUNNER_TIMEOUT_FACTOR% %TEST_RUNNER_EXTRA%
298+
299+
- name: Clone fuzz corpus
300+
run: |
301+
git clone --depth=1 https://github.com/bitcoin-core/qa-assets "$env:RUNNER_TEMP\qa-assets"
302+
Set-Location "$env:RUNNER_TEMP\qa-assets"
303+
Write-Host "Using qa-assets repo from commit ..."
304+
git log -1
305+
306+
- name: Run fuzz binaries
307+
env:
308+
BITCOINFUZZ: "${{ github.workspace}}\\src\\fuzz.exe"
309+
shell: cmd
310+
run: py -3 test\fuzz\test_runner.py --par %NUMBER_OF_PROCESSORS% --loglevel DEBUG %RUNNER_TEMP%\qa-assets\fuzz_seed_corpus

build_msvc/bitcoin.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtest_util", "libtest_uti
4848
EndProject
4949
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_bitcoin-qt", "test_bitcoin-qt\test_bitcoin-qt.vcxproj", "{51201D5E-D939-4854-AE9D-008F03FF518E}"
5050
EndProject
51-
Project("{542007E3-BE0D-4B0D-A6B0-AA8813E2558D}") = "libminisketch", "libminisketch\libminisketch.vcxproj", "{542007E3-BE0D-4B0D-A6B0-AA8813E2558D}"
51+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libminisketch", "libminisketch\libminisketch.vcxproj", "{542007E3-BE0D-4B0D-A6B0-AA8813E2558D}"
52+
EndProject
53+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fuzz", "fuzz\fuzz.vcxproj", "{AFCEE6C1-89FB-49AB-A694-BA580A59E2D8}"
5254
EndProject
5355
Global
5456
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -152,6 +154,10 @@ Global
152154
{542007E3-BE0D-4B0D-A6B0-AA8813E2558D}.Debug|x64.Build.0 = Debug|x64
153155
{542007E3-BE0D-4B0D-A6B0-AA8813E2558D}.Release|x64.ActiveCfg = Release|x64
154156
{542007E3-BE0D-4B0D-A6B0-AA8813E2558D}.Release|x64.Build.0 = Release|x64
157+
{AFCEE6C1-89FB-49AB-A694-BA580A59E2D8}.Debug|x64.ActiveCfg = Debug|x64
158+
{AFCEE6C1-89FB-49AB-A694-BA580A59E2D8}.Debug|x64.Build.0 = Debug|x64
159+
{AFCEE6C1-89FB-49AB-A694-BA580A59E2D8}.Release|x64.ActiveCfg = Release|x64
160+
{AFCEE6C1-89FB-49AB-A694-BA580A59E2D8}.Release|x64.Build.0 = Release|x64
155161
EndGlobalSection
156162
GlobalSection(SolutionProperties) = preSolution
157163
HideSolutionNode = FALSE

build_msvc/bitcoind/bitcoind.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<ReplaceInFile FilePath="$(ConfigIniOut)"
8181
Replace="@BUILD_BITCOIND_TRUE@" By=""></ReplaceInFile>
8282
<ReplaceInFile FilePath="$(ConfigIniOut)"
83-
Replace="@ENABLE_FUZZ_BINARY_TRUE@" By="#"></ReplaceInFile>
83+
Replace="@ENABLE_FUZZ_BINARY_TRUE@" By=""></ReplaceInFile>
8484
<ReplaceInFile FilePath="$(ConfigIniOut)"
8585
Replace="@ENABLE_ZMQ_TRUE@" By=""></ReplaceInFile>
8686
<ReplaceInFile FilePath="$(ConfigIniOut)"

build_msvc/common.init.vcxproj.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@
8787
<ClCompile>
8888
<WarningLevel>Level3</WarningLevel>
8989
<PrecompiledHeader>NotUsing</PrecompiledHeader>
90-
<AdditionalOptions>/utf-8 /Zc:__cplusplus /std:c++20 %(AdditionalOptions)</AdditionalOptions>
90+
<AdditionalOptions>/utf-8 /Zc:preprocessor /Zc:__cplusplus /std:c++20 %(AdditionalOptions)</AdditionalOptions>
9191
<DisableSpecificWarnings>4018;4244;4267;4715;4805</DisableSpecificWarnings>
9292
<TreatWarningAsError>true</TreatWarningAsError>
93-
<PreprocessorDefinitions>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;SECP256K1_STATIC;ZMQ_STATIC;NOMINMAX;WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_WIN32_WINNT=0x0601;_WIN32_IE=0x0501;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
93+
<PreprocessorDefinitions>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;SECP256K1_STATIC;ZMQ_STATIC;NOMINMAX;WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_WIN32_WINNT=0x0601;_WIN32_IE=0x0501;WIN32_LEAN_AND_MEAN;PROVIDE_FUZZ_MAIN_FUNCTION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
9494
<AdditionalIncludeDirectories>..\..\src;..\..\src\minisketch\include;..\..\src\univalue\include;..\..\src\secp256k1\include;..\..\src\leveldb\include;..\..\src\leveldb\helpers\memenv;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
9595
</ClCompile>
9696
<Link>

build_msvc/fuzz/fuzz.vcxproj

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\common.init.vcxproj" />
4+
<PropertyGroup Label="Globals">
5+
<ProjectGuid>{AFCEE6C1-89FB-49AB-A694-BA580A59E2D8}</ProjectGuid>
6+
</PropertyGroup>
7+
<PropertyGroup Label="Configuration">
8+
<ConfigurationType>Application</ConfigurationType>
9+
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<!-- TODO: Fix the code and remove bitdeque.cpp and miniscript.cpp exclusion. -->
13+
<ClCompile Include="..\..\src\test\fuzz\*.cpp" Exclude="..\..\src\test\fuzz\bitdeque.cpp;..\..\src\test\fuzz\miniscript.cpp" />
14+
<ClCompile Include="..\..\src\test\fuzz\util\descriptor.cpp">
15+
<ObjectFileName>$(IntDir)test_fuzz_util_descriptor.obj</ObjectFileName>
16+
</ClCompile>
17+
<ClCompile Include="..\..\src\test\fuzz\util\mempool.cpp">
18+
<ObjectFileName>$(IntDir)test_fuzz_util_mempool.obj</ObjectFileName>
19+
</ClCompile>
20+
<ClCompile Include="..\..\src\test\fuzz\util\net.cpp">
21+
<ObjectFileName>$(IntDir)test_fuzz_util_net.obj</ObjectFileName>
22+
</ClCompile>
23+
<ClCompile Include="..\..\src\wallet\test\fuzz\coincontrol.cpp">
24+
<ObjectFileName>$(IntDir)wallet_test_fuzz_coincontrol.obj</ObjectFileName>
25+
</ClCompile>
26+
<ClCompile Include="..\..\src\wallet\test\fuzz\coinselection.cpp">
27+
<ObjectFileName>$(IntDir)wallet_test_fuzz_coinselection.obj</ObjectFileName>
28+
</ClCompile>
29+
<ClCompile Include="..\..\src\wallet\test\fuzz\fees.cpp">
30+
<ObjectFileName>$(IntDir)wallet_test_fuzz_fees.obj</ObjectFileName>
31+
</ClCompile>
32+
<ClCompile Include="..\..\src\wallet\test\fuzz\notifications.cpp">
33+
<ObjectFileName>$(IntDir)wallet_test_fuzz_notifications.obj</ObjectFileName>
34+
</ClCompile>
35+
<ClCompile Include="..\..\src\wallet\test\fuzz\parse_iso8601.cpp">
36+
<ObjectFileName>$(IntDir)wallet_test_fuzz_parse_iso8601.obj</ObjectFileName>
37+
</ClCompile>
38+
<ClCompile Include="..\..\src\wallet\test\fuzz\scriptpubkeyman.cpp">
39+
<ObjectFileName>$(IntDir)wallet_test_fuzz_scriptpubkeyman.obj</ObjectFileName>
40+
</ClCompile>
41+
</ItemGroup>
42+
<ItemGroup>
43+
<ProjectReference Include="..\libminisketch\libminisketch.vcxproj">
44+
<Project>{542007e3-be0d-4b0d-a6b0-aa8813e2558d}</Project>
45+
</ProjectReference>
46+
<ProjectReference Include="..\libbitcoin_consensus\libbitcoin_consensus.vcxproj">
47+
<Project>{2b384fa8-9ee1-4544-93cb-0d733c25e8ce}</Project>
48+
</ProjectReference>
49+
<ProjectReference Include="..\libbitcoin_cli\libbitcoin_cli.vcxproj">
50+
<Project>{0667528c-d734-4009-adf9-c0d6c4a5a5a6}</Project>
51+
</ProjectReference>
52+
<ProjectReference Include="..\libbitcoin_common\libbitcoin_common.vcxproj">
53+
<Project>{7c87e378-df58-482e-aa2f-1bc129bc19ce}</Project>
54+
</ProjectReference>
55+
<ProjectReference Include="..\libbitcoin_crypto\libbitcoin_crypto.vcxproj">
56+
<Project>{6190199c-6cf4-4dad-bfbd-93fa72a760c1}</Project>
57+
</ProjectReference>
58+
<ProjectReference Include="..\libbitcoin_node\libbitcoin_node.vcxproj">
59+
<Project>{460fee33-1fe1-483f-b3bf-931ff8e969a5}</Project>
60+
</ProjectReference>
61+
<ProjectReference Include="..\libbitcoin_util\libbitcoin_util.vcxproj">
62+
<Project>{b53a5535-ee9d-4c6f-9a26-f79ee3bc3754}</Project>
63+
</ProjectReference>
64+
<ProjectReference Include="..\libbitcoin_wallet\libbitcoin_wallet.vcxproj">
65+
<Project>{93b86837-b543-48a5-a89b-7c87abb77df2}</Project>
66+
</ProjectReference>
67+
<ProjectReference Include="..\libbitcoin_zmq\libbitcoin_zmq.vcxproj">
68+
<Project>{792d487f-f14c-49fc-a9de-3fc150f31c3f}</Project>
69+
</ProjectReference>
70+
<ProjectReference Include="..\libtest_util\libtest_util.vcxproj">
71+
<Project>{1e065f03-3566-47d0-8fa9-daa72b084e7d}</Project>
72+
</ProjectReference>
73+
<ProjectReference Include="..\libunivalue\libunivalue.vcxproj">
74+
<Project>{5724ba7d-a09a-4ba8-800b-c4c1561b3d69}</Project>
75+
</ProjectReference>
76+
<ProjectReference Include="..\libsecp256k1\libsecp256k1.vcxproj">
77+
<Project>{bb493552-3b8c-4a8c-bf69-a6e7a51d2ea6}</Project>
78+
</ProjectReference>
79+
<ProjectReference Include="..\libleveldb\libleveldb.vcxproj">
80+
<Project>{18430fef-6b61-4c53-b396-718e02850f1b}</Project>
81+
</ProjectReference>
82+
</ItemGroup>
83+
<ItemDefinitionGroup>
84+
<ClCompile>
85+
<DisableSpecificWarnings>4018;4244;4267;4334;4715;4805</DisableSpecificWarnings>
86+
</ClCompile>
87+
</ItemDefinitionGroup>
88+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
89+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
90+
<Import Project="..\common.vcxproj" />
91+
</Project>

src/test/fuzz/addition_overflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ void TestAdditionOverflow(FuzzedDataProvider& fuzzed_data_provider)
2424
assert(is_addition_overflow_custom == AdditionOverflow(j, i));
2525
assert(maybe_add == CheckedAdd(j, i));
2626
assert(sat_add == SaturatingAdd(j, i));
27+
#ifndef _MSC_VER
2728
T result_builtin;
2829
const bool is_addition_overflow_builtin = __builtin_add_overflow(i, j, &result_builtin);
2930
assert(is_addition_overflow_custom == is_addition_overflow_builtin);
3031
if (!is_addition_overflow_custom) {
3132
assert(i + j == result_builtin);
3233
}
34+
#endif
3335
if (is_addition_overflow_custom) {
3436
assert(sat_add == std::numeric_limits<T>::min() || sat_add == std::numeric_limits<T>::max());
3537
} else {

src/test/fuzz/deserialize.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <optional>
3434
#include <stdexcept>
3535
#include <stdint.h>
36-
#include <unistd.h>
3736

3837
using node::SnapshotMetadata;
3938

src/test/fuzz/fuzz.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <memory>
2626
#include <string>
2727
#include <tuple>
28-
#include <unistd.h>
2928
#include <utility>
3029
#include <vector>
3130

@@ -135,9 +134,9 @@ void initialize()
135134
#if defined(PROVIDE_FUZZ_MAIN_FUNCTION)
136135
static bool read_stdin(std::vector<uint8_t>& data)
137136
{
138-
uint8_t buffer[1024];
139-
ssize_t length = 0;
140-
while ((length = read(STDIN_FILENO, buffer, 1024)) > 0) {
137+
std::istream::char_type buffer[1024];
138+
std::streamsize length;
139+
while ((std::cin.read(buffer, 1024), length = std::cin.gcount()) > 0) {
141140
data.insert(data.end(), buffer, buffer + length);
142141
}
143142
return length == 0;

src/test/fuzz/multiplication_overflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ void TestMultiplicationOverflow(FuzzedDataProvider& fuzzed_data_provider)
1717
const T i = fuzzed_data_provider.ConsumeIntegral<T>();
1818
const T j = fuzzed_data_provider.ConsumeIntegral<T>();
1919
const bool is_multiplication_overflow_custom = MultiplicationOverflow(i, j);
20+
#ifndef _MSC_VER
2021
T result_builtin;
2122
const bool is_multiplication_overflow_builtin = __builtin_mul_overflow(i, j, &result_builtin);
2223
assert(is_multiplication_overflow_custom == is_multiplication_overflow_builtin);
2324
if (!is_multiplication_overflow_custom) {
2425
assert(i * j == result_builtin);
2526
}
27+
#else
28+
if (!is_multiplication_overflow_custom) {
29+
(void)(i * j);
30+
}
31+
#endif
2632
}
2733
} // namespace
2834

test/fuzz/test_runner.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
import configparser
1212
import logging
1313
import os
14+
import platform
1415
import random
1516
import subprocess
1617
import sys
1718

1819

1920
def get_fuzz_env(*, target, source_dir):
2021
symbolizer = os.environ.get('LLVM_SYMBOLIZER_PATH', "/usr/bin/llvm-symbolizer")
21-
return {
22+
fuzz_env = {
2223
'FUZZ': target,
2324
'UBSAN_OPTIONS':
2425
f'suppressions={source_dir}/test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1:report_error_type=1',
@@ -27,6 +28,10 @@ def get_fuzz_env(*, target, source_dir):
2728
'ASAN_SYMBOLIZER_PATH':symbolizer,
2829
'MSAN_SYMBOLIZER_PATH':symbolizer,
2930
}
31+
if platform.system() == "Windows":
32+
# On Windows, `env` option must include valid `SystemRoot`.
33+
fuzz_env = {**fuzz_env, 'SystemRoot': os.environ.get('SystemRoot')}
34+
return fuzz_env
3035

3136

3237
def main():

0 commit comments

Comments
 (0)