Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions tests/fuzz/pybind_fuzzer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Copyright 2023 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "pybind11/pybind11.h"
#include "pybind11/embed.h"

#include <iostream>
#include <string>

#include <fuzzer/FuzzedDataProvider.h>

namespace py = pybind11;

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
FuzzedDataProvider fdp(data, size);

static py::scoped_interpreter guard{};
try {
auto locals = py::dict();
py::exec(fdp.ConsumeRandomLengthString().c_str(), py::globals(), locals);
} catch (pybind11::error_already_set &e) {
}

try {
py::object os = py::module_::import("os");
py::object makedirs = os.attr(fdp.ConsumeRandomLengthString().c_str());
} catch (py::error_already_set &e) {
}

try {
py::tuple args = py::make_tuple(fdp.ConsumeRandomLengthString().c_str(), py::none());
py::object Decimal = py::module_::import("decimal").attr("Decimal");
py::object pi = Decimal(fdp.ConsumeRandomLengthString().c_str());
py::object exp_pi = pi.attr(fdp.ConsumeRandomLengthString().c_str())();
} catch (py::error_already_set &e) {
}

try {
py::object obj = py::str(fdp.ConsumeRandomLengthString().c_str());
} catch (py::error_already_set &e) {
}
return 0;
}
5 changes: 4 additions & 1 deletion tests/test_gil_scoped.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ def _intentional_deadlock():
m.intentional_deadlock()


ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = (*ALL_BASIC_TESTS, _intentional_deadlock)
ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = (
*ALL_BASIC_TESTS,
pytest.param(_intentional_deadlock, marks=skipif_not_free_threaded),
)


def _run_in_process(target, *args, **kwargs):
Expand Down
Loading