From 26dc0e3f5d89d5a685b7610d3e76bf6edb9f42f9 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Tue, 13 Oct 2026 08:20:04 +0100 Subject: [PATCH 1/2] OSS-Fuzz: Move fuzzer to upstream repository Signed-off-by: Arthur Chan --- tests/fuzz/pybind_fuzzer.cc | 51 +++++++++++++++++++++++++++++++++++++ tests/test_gil_scoped.py | 5 +++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/fuzz/pybind_fuzzer.cc diff --git a/tests/fuzz/pybind_fuzzer.cc b/tests/fuzz/pybind_fuzzer.cc new file mode 100644 index 0000000000..32c7e6c2da --- /dev/null +++ b/tests/fuzz/pybind_fuzzer.cc @@ -0,0 +1,51 @@ +/* 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 +#include +#include +#include "pybind11/embed.h" +#include "pybind11/pybind11.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; +} diff --git a/tests/test_gil_scoped.py b/tests/test_gil_scoped.py index 8c0ac9597d..76220d72f8 100644 --- a/tests/test_gil_scoped.py +++ b/tests/test_gil_scoped.py @@ -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): From 52e7a4abc1110674870faec998cfe0f3b2896988 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Oct 2026 09:07:24 +0000 Subject: [PATCH 2/2] style: pre-commit fixes --- tests/fuzz/pybind_fuzzer.cc | 65 +++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/tests/fuzz/pybind_fuzzer.cc b/tests/fuzz/pybind_fuzzer.cc index 32c7e6c2da..0bd9013ce7 100644 --- a/tests/fuzz/pybind_fuzzer.cc +++ b/tests/fuzz/pybind_fuzzer.cc @@ -10,42 +10,43 @@ See the License for the specific language governing permissions and limitations under the License. */ -#include +#include "pybind11/pybind11.h" +#include "pybind11/embed.h" + #include #include -#include "pybind11/embed.h" -#include "pybind11/pybind11.h" + +#include 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; + 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; }