Skip to content

Commit 978a7ab

Browse files
committed
Add fuzzing of try_scientific_to_int to CI
1 parent f20a688 commit 978a7ab

File tree

4 files changed

+270
-0
lines changed

4 files changed

+270
-0
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
# https://github.com/llvm/llvm-project/issues/59827: disabled 2b/23 for clang-17 with libstdc++13 in 24.04
129129
- { compiler: clang-17, cxxstd: '11,14,17,20', os: ubuntu-24.04 }
130130
- { compiler: clang-18, cxxstd: '11,14,17,20,23,2c', os: ubuntu-24.04 }
131+
- { compiler: clang-18, cxxstd: '20', os: ubuntu-24.04, fuzzing: yes }
131132

132133
# libc++
133134
- { compiler: clang-6.0, cxxstd: '11,14', os: ubuntu-22.04, container: 'ubuntu:18.04', stdlib: libc++, install: 'clang-6.0 libc++-dev libc++abi-dev' }
@@ -368,6 +369,10 @@ jobs:
368369
COVERITY_SCAN_NOTIFICATION_EMAIL: ${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }}
369370
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
370371

372+
- name: Run fuzzing
373+
if: matrix.fuzzing == 'yes'
374+
run: B2_TARGETS="libs/$SELF/fuzzing" ci/build.sh
375+
371376
windows:
372377
defaults:
373378
run:

fuzzing/Jamfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) 2024 Matt Borland
2+
# Copyright (c) 2025 Alexander Grund
3+
#
4+
# Distributed under the Boost Software License, Version 1.0.
5+
# https://www.boost.org/LICENSE_1_0.txt.
6+
7+
8+
import common ;
9+
import regex ;
10+
11+
local all_fuzzers = [ regex.replace-list
12+
[ glob "fuzz_*.cpp" ] : ".cpp" : ""
13+
] ;
14+
15+
for local fuzzer in $(all_fuzzers)
16+
{
17+
local fuzz_time = 60 ;
18+
19+
# Create the output corpus directories
20+
make /tmp/corpus/$(fuzzer) : : common.MkDir ;
21+
make /tmp/mincorpus/$(fuzzer) : : common.MkDir ;
22+
23+
# Build the fuzzer
24+
exe $(fuzzer)
25+
:
26+
$(fuzzer).cpp
27+
: requirements
28+
<debug-symbols>on
29+
<optimization>speed
30+
<address-sanitizer>on
31+
<undefined-sanitizer>norecover
32+
<cxxflags>-fsanitize=fuzzer
33+
<linkflags>-fsanitize=fuzzer
34+
<library>/boost/locale//boost_locale
35+
;
36+
37+
# Run the fuzzer for a short while
38+
run $(fuzzer)
39+
: <testing.arg>"seedcorpus/$(fuzzer) -max_total_time=$(fuzz_time)"
40+
: target-name $(fuzzer)-fuzzing
41+
: requirements
42+
<dependency>/tmp/corpus/$(fuzzer)
43+
;
44+
45+
# Minimize the corpus
46+
run $(fuzzer)
47+
: <testing.arg>"/tmp/mincorpus/$(fuzzer) /tmp/corpus/$(fuzzer) -merge=1"
48+
: target-name $(fuzzer)-minimize-corpus
49+
: requirements
50+
<dependency>$(fuzzer)-fuzzing
51+
<dependency>/tmp/corpus/$(fuzzer)
52+
<dependency>/tmp/mincorpus/$(fuzzer)
53+
;
54+
}

fuzzing/fuzz_scientific_to_int.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright (c) 2025 Alexander Grund
3+
//
4+
// Distributed under the Boost Software License, Version 1.0.
5+
// https://www.boost.org/LICENSE_1_0.txt
6+
7+
#include "../src/util/numeric_conversion.hpp"
8+
9+
#include <boost/charconv.hpp>
10+
#include <boost/core/detail/string_view.hpp>
11+
#include <cstdint>
12+
#include <exception>
13+
#include <iostream>
14+
15+
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size)
16+
{
17+
using boost::locale::util::try_scientific_to_int;
18+
try {
19+
const boost::core::string_view sv{reinterpret_cast<const char*>(data), size};
20+
21+
uint8_t u8{};
22+
try_scientific_to_int(sv, u8);
23+
24+
uint16_t u16{};
25+
try_scientific_to_int(sv, u16);
26+
27+
uint32_t u32{};
28+
try_scientific_to_int(sv, u32);
29+
30+
uint8_t u64{};
31+
try_scientific_to_int(sv, u64);
32+
} catch(...) {
33+
std::cerr << "Error with: " << data << std::endl;
34+
std::terminate();
35+
}
36+
37+
return 0;
38+
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
1
2+
1E0
3+
0.1E1
4+
0.01E2
5+
0.001E3
6+
10
7+
10E0
8+
1E1
9+
0.1E2
10+
0.01E3
11+
100
12+
1E2
13+
10E1
14+
0.1E3
15+
0.01E4
16+
123
17+
1.23E2
18+
12.3E1
19+
123E0
20+
0.123E3
21+
0
22+
0E0
23+
0.0E1
24+
0.000E3
25+
255
26+
255E0
27+
2.55E2
28+
25.5E1
29+
0.255E3
30+
50
31+
5E1
32+
0.5E2
33+
0.05E3
34+
450
35+
4.5E2
36+
45E1
37+
0.45E3
38+
-50
39+
-5E1
40+
-0.5E2
41+
-0.05E3
42+
250
43+
2.5E2
44+
25E1
45+
250E0
46+
0.25E3
47+
2.5E+2
48+
-700
49+
-7E2
50+
-70E1
51+
-700E0
52+
-0.7E3
53+
1234
54+
1.234E3
55+
123.4E1
56+
1234E0
57+
12.34E2
58+
0.01234E5
59+
123000
60+
123E3
61+
1.23E5
62+
12.3E4
63+
0.000123E9
64+
-0.0005E0
65+
-0.005E1
66+
-0.05E2
67+
-5E-4
68+
9999
69+
9.999E3
70+
99.99E2
71+
999.9E1
72+
9999E0
73+
1.5
74+
1.5E0
75+
0.15E1
76+
0.015E2
77+
-1
78+
-1E0
79+
-0.1E1
80+
-0.01E2
81+
-10
82+
-10E0
83+
-1E1
84+
-0.1E2
85+
-100
86+
-1E2
87+
-10E1
88+
-100E0
89+
45
90+
4.5E1
91+
0.45E2
92+
5678
93+
5.678E3
94+
56.78E2
95+
567.8E1
96+
5678E0
97+
999000
98+
9.99E5
99+
99.9E4
100+
999E3
101+
9990E2
102+
200
103+
2E2
104+
20E1
105+
200E0
106+
2.0E+2
107+
2147483648
108+
2.147483648E9
109+
4294967296
110+
4.294967296E9
111+
10000000000
112+
1E10
113+
18446744074.073709551615E9
114+
9223372036854775808
115+
9.223372036854775808E18
116+
100000000000
117+
1E11
118+
1000000000000
119+
1E12
120+
1234567890123
121+
1.234567890123E12
122+
9876543210000
123+
9.87654321E12
124+
9999999999999
125+
9.999999999999E12
126+
99999999999999
127+
9.9999999999999E13
128+
100000000000000
129+
1E14
130+
123456789012345
131+
1.23456789012345E14
132+
987654321098765
133+
9.87654321098765E14
134+
1000000000000000
135+
1E15
136+
1844674400000000000
137+
1.8446744E18
138+
9000000000000000000
139+
9E18
140+
9990000000000000000
141+
9.99E18
142+
10000000000000000000
143+
1E19
144+
12345678900000000000
145+
1.23456789E19
146+
9876543210000000000
147+
9.87654321E18
148+
18440000000000000000
149+
1.844E19
150+
900000000000000
151+
9E14
152+
1844674400000000
153+
1.8446744E15
154+
1844674407000000000
155+
1.844674407E18
156+
12300000000000000000
157+
1.23E19
158+
18446744073700000000
159+
1.84467440737E19
160+
9999999999999999999
161+
9.999999999999999999E18
162+
1844674400000000000
163+
1.8446744E15
164+
10.5E18
165+
100.0000E18
166+
5E
167+
15E
168+
225E
169+
5E-
170+
15E-
171+
225E-
172+
5e1
173+
5.5e1

0 commit comments

Comments
 (0)