Skip to content

Commit 26dc0e3

Browse files
committed
OSS-Fuzz: Move fuzzer to upstream repository
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
1 parent 6254086 commit 26dc0e3

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

‎tests/fuzz/pybind_fuzzer.cc‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright 2023 Google LLC
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
Unless required by applicable law or agreed to in writing, software
7+
distributed under the License is distributed on an "AS IS" BASIS,
8+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
See the License for the specific language governing permissions and
10+
limitations under the License.
11+
*/
12+
13+
#include <fuzzer/FuzzedDataProvider.h>
14+
#include <iostream>
15+
#include <string>
16+
#include "pybind11/embed.h"
17+
#include "pybind11/pybind11.h"
18+
19+
namespace py = pybind11;
20+
21+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
22+
FuzzedDataProvider fdp(data, size);
23+
24+
static py::scoped_interpreter guard{};
25+
try {
26+
auto locals = py::dict();
27+
py::exec(fdp.ConsumeRandomLengthString().c_str(), py::globals(), locals);
28+
} catch (pybind11::error_already_set &e) {
29+
}
30+
31+
try {
32+
py::object os = py::module_::import("os");
33+
py::object makedirs = os.attr(fdp.ConsumeRandomLengthString().c_str());
34+
} catch (py::error_already_set &e) {
35+
}
36+
37+
try {
38+
py::tuple args =
39+
py::make_tuple(fdp.ConsumeRandomLengthString().c_str(), py::none());
40+
py::object Decimal = py::module_::import("decimal").attr("Decimal");
41+
py::object pi = Decimal(fdp.ConsumeRandomLengthString().c_str());
42+
py::object exp_pi = pi.attr(fdp.ConsumeRandomLengthString().c_str())();
43+
} catch (py::error_already_set &e) {
44+
}
45+
46+
try {
47+
py::object obj = py::str(fdp.ConsumeRandomLengthString().c_str());
48+
} catch (py::error_already_set &e) {
49+
}
50+
return 0;
51+
}

‎tests/test_gil_scoped.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ def _intentional_deadlock():
195195
m.intentional_deadlock()
196196

197197

198-
ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = (*ALL_BASIC_TESTS, _intentional_deadlock)
198+
ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = (
199+
*ALL_BASIC_TESTS,
200+
pytest.param(_intentional_deadlock, marks=skipif_not_free_threaded),
201+
)
199202

200203

201204
def _run_in_process(target, *args, **kwargs):

0 commit comments

Comments
 (0)