From 1d7a7d84309c5b95cf5ef12a22f0d3b214ffdb94 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Thu, 26 Nov 2026 08:16:13 +0000 Subject: [PATCH 1/2] OSS-Fuzz: Add new fuzzer/corpus targets stl binding process Signed-off-by: Arthur Chan --- tests/fuzz/CMakeLists.txt | 25 +- tests/fuzz/corpus_stl_bind_fuzzer/01_vecnew | Bin 0 -> 1 bytes tests/fuzz/corpus_stl_bind_fuzzer/02_append | 1 + tests/fuzz/corpus_stl_bind_fuzzer/03_insert | 1 + tests/fuzz/corpus_stl_bind_fuzzer/04_popget | 1 + tests/fuzz/corpus_stl_bind_fuzzer/05_setdel | 1 + tests/fuzz/corpus_stl_bind_fuzzer/06_slice | 1 + tests/fuzz/corpus_stl_bind_fuzzer/07_mapnew | 1 + tests/fuzz/corpus_stl_bind_fuzzer/08_mapset | 1 + .../fuzz/corpus_stl_bind_fuzzer/09_mapgetdel | 1 + tests/fuzz/corpus_stl_bind_fuzzer/10_iterate | 1 + .../fuzz/corpus_stl_bind_fuzzer/11_wrongtype | 1 + tests/fuzz/corpus_stl_bind_fuzzer/12_mixed | Bin 0 -> 7 bytes tests/fuzz/corpus_stl_bind_fuzzer/13_mapmix | 1 + tests/fuzz/stl_bind_fuzzer.cpp | 268 ++++++++++++++++++ 15 files changed, 295 insertions(+), 9 deletions(-) create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/01_vecnew create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/02_append create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/03_insert create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/04_popget create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/05_setdel create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/06_slice create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/07_mapnew create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/08_mapset create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/09_mapgetdel create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/10_iterate create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/11_wrongtype create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/12_mixed create mode 100644 tests/fuzz/corpus_stl_bind_fuzzer/13_mapmix create mode 100644 tests/fuzz/stl_bind_fuzzer.cpp diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index 44fbf4d159..bb237ce244 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -41,26 +41,33 @@ endif() configure_file("${PYBIND11_FUZZER_INCLUDE_DIR}/fuzzer/FuzzedDataProvider.h" "${CMAKE_CURRENT_BINARY_DIR}/include/fuzzer/FuzzedDataProvider.h" COPYONLY) -set(_pybind11_fuzz_sources pybind_fuzzer.cpp) +# One fuzz target per *_fuzzer.cpp in this directory. +set(_pybind11_fuzz_targets pybind_fuzzer stl_bind_fuzzer) # OSS-Fuzz exports LIB_FUZZING_ENGINE to the object that provides main(). # Locally, link a small file-replay driver instead. if(DEFINED ENV{LIB_FUZZING_ENGINE} AND NOT "$ENV{LIB_FUZZING_ENGINE}" STREQUAL "") set(_pybind11_fuzz_engine "$ENV{LIB_FUZZING_ENGINE}") else() - list(APPEND _pybind11_fuzz_sources fuzz_replay.cpp) set(_pybind11_fuzz_engine "") endif() -add_executable(pybind_fuzzer ${_pybind11_fuzz_sources}) -add_executable(test_fuzz_input test_fuzz_input.cpp) -foreach(target pybind_fuzzer test_fuzz_input) +foreach(target ${_pybind11_fuzz_targets}) + set(_pybind11_fuzz_sources ${target}.cpp) + if(NOT _pybind11_fuzz_engine) + list(APPEND _pybind11_fuzz_sources fuzz_replay.cpp) + endif() + add_executable(${target} ${_pybind11_fuzz_sources}) pybind11_enable_warnings(${target}) target_include_directories(${target} SYSTEM PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include") + target_link_libraries(${target} PRIVATE pybind11::embed) + if(_pybind11_fuzz_engine) + target_link_libraries(${target} PRIVATE ${_pybind11_fuzz_engine}) + endif() endforeach() -target_link_libraries(pybind_fuzzer PRIVATE pybind11::embed) -if(_pybind11_fuzz_engine) - target_link_libraries(pybind_fuzzer PRIVATE ${_pybind11_fuzz_engine}) -endif() + +add_executable(test_fuzz_input test_fuzz_input.cpp) +pybind11_enable_warnings(test_fuzz_input) +target_include_directories(test_fuzz_input SYSTEM PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include") file(GLOB _pybind11_fuzz_corpus CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/corpus/*") add_custom_target( diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/01_vecnew b/tests/fuzz/corpus_stl_bind_fuzzer/01_vecnew new file mode 100644 index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d GIT binary patch literal 1 IcmZPo000310RR91 literal 0 HcmV?d00001 diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/02_append b/tests/fuzz/corpus_stl_bind_fuzzer/02_append new file mode 100644 index 0000000000..6b2aaa7640 --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/02_append @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/03_insert b/tests/fuzz/corpus_stl_bind_fuzzer/03_insert new file mode 100644 index 0000000000..25cb955ba2 --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/03_insert @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/04_popget b/tests/fuzz/corpus_stl_bind_fuzzer/04_popget new file mode 100644 index 0000000000..fc2b5693e0 --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/04_popget @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/05_setdel b/tests/fuzz/corpus_stl_bind_fuzzer/05_setdel new file mode 100644 index 0000000000..45a8ca02bf --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/05_setdel @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/06_slice b/tests/fuzz/corpus_stl_bind_fuzzer/06_slice new file mode 100644 index 0000000000..b0b2b1c8dd --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/06_slice @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/07_mapnew b/tests/fuzz/corpus_stl_bind_fuzzer/07_mapnew new file mode 100644 index 0000000000..f8fa5a2354 --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/07_mapnew @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/08_mapset b/tests/fuzz/corpus_stl_bind_fuzzer/08_mapset new file mode 100644 index 0000000000..303e398c82 --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/08_mapset @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/09_mapgetdel b/tests/fuzz/corpus_stl_bind_fuzzer/09_mapgetdel new file mode 100644 index 0000000000..5a77f05831 --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/09_mapgetdel @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/10_iterate b/tests/fuzz/corpus_stl_bind_fuzzer/10_iterate new file mode 100644 index 0000000000..501a6bbaf1 --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/10_iterate @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/11_wrongtype b/tests/fuzz/corpus_stl_bind_fuzzer/11_wrongtype new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/tests/fuzz/corpus_stl_bind_fuzzer/11_wrongtype @@ -0,0 +1 @@ + diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/12_mixed b/tests/fuzz/corpus_stl_bind_fuzzer/12_mixed new file mode 100644 index 0000000000000000000000000000000000000000..b812a5f44eaa873178abf9875d07bcd37220071d GIT binary patch literal 7 OcmZQzWMpDy + +#include +#include +#include + +#include "pybind11/embed.h" +#include "pybind11/pybind11.h" +#include "pybind11/stl_bind.h" + +namespace py = pybind11; + +namespace pybind11_fuzz { + +enum Op : uint8_t { + kVecNew = 0, + kVecAppend, + kVecInsert, + kVecPopGet, + kVecSetDel, + kVecSliceLen, + kMapNew, + kMapSet, + kMapGetDel, + kIterate, + kWrongType, + kMaxOp // sentinel +}; + +inline uint8_t next_op(FuzzedDataProvider &fdp) { + return fdp.ConsumeIntegralInRange(0, static_cast(kMaxOp - 1)); +} + +inline int next_int(FuzzedDataProvider &fdp) { + return fdp.ConsumeIntegralInRange(-1000, 1000000); +} + +// index used against containers: fuzzed but bounded around realistic sizes +inline py::object next_index_object(FuzzedDataProvider &fdp, int size) { + int raw = fdp.ConsumeIntegralInRange(-6, 14); + if (raw < 0) { + raw += size; // exercise Python negative-index normalisation + } + return py::int_(raw); +} + +inline std::string next_str(FuzzedDataProvider &fdp) { + return fdp.ConsumeRandomLengthString(32); +} + +} // namespace pybind11_fuzz + +PYBIND11_EMBEDDED_MODULE(fzb, m) { + py::bind_vector>(m, "IVec"); + py::bind_vector>(m, "SVec"); + py::bind_map>(m, "SIMap"); +} + +// Handles + interpreter, destruction-safe member order (see header comment). +struct FuzzEnv { + py::scoped_interpreter guard; + py::object gc_mod; + py::object IVec; + py::object SVec; + py::object SIMap; + + FuzzEnv() + : guard{}, gc_mod(py::module_::import("gc")) { + py::object mod = py::module_::import("fzb"); + IVec = mod.attr("IVec"); + SVec = mod.attr("SVec"); + SIMap = mod.attr("SIMap"); + warm_up(); + } + + static FuzzEnv &get() { + static FuzzEnv env; + return env; + } + + void warm_up() { + py::object v = IVec(); + v.attr("append")(1); + v.attr("insert")(0, 2); + (void) v.attr("pop")(0); + (void) v.attr("__getitem__")(0); + v.attr("__setitem__")(0, 3); + (void) py::len(v); + (void) py::iter(v); + py::object m = SIMap(); + m.attr("__setitem__")(py::str("k"), 1); + (void) m.attr("__getitem__")(py::str("k")); + (void) m.attr("__contains__")(py::str("k")); + m.attr("__delitem__")(py::str("k")); + (void) gc_mod.attr("collect")(); + } +}; + +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { + FuzzEnv::get(); + return 0; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + using namespace pybind11_fuzz; + + FuzzEnv &env = FuzzEnv::get(); + FuzzedDataProvider fdp(data, size); + py::object live; // most recent container; replaced per op + bool have = false; + + try { + int ops = 0; + while (fdp.remaining_bytes() > 0 && ops < 24) { + ++ops; + const uint8_t op = next_op(fdp); + try { + switch (op) { + case kVecNew: { + live = env.IVec(); + have = true; + break; + } + case kVecAppend: { + if (!have) { + break; + } + live.attr("append")(next_int(fdp)); + break; + } + case kVecInsert: { + if (!have) { + break; + } + int sz = static_cast(py::len(live)); + live.attr("insert")(next_index_object(fdp, sz), next_int(fdp)); + break; + } + case kVecPopGet: { + if (!have) { + break; + } + int sz = static_cast(py::len(live)); + try { + (void) live.attr("pop")(next_index_object(fdp, sz)); + } catch (const py::error_already_set &) { + } + break; + } + case kVecSetDel: { + if (!have) { + break; + } + int sz = static_cast(py::len(live)); + live.attr("__setitem__")(next_index_object(fdp, sz), next_int(fdp)); + break; + } + case kVecSliceLen: { + if (!have) { + break; + } + (void) py::len(live); + (void) py::iter(live); + (void) live.attr("__getitem__")(py::int_(next_int(fdp))); + break; + } + case kMapNew: { + live = env.SIMap(); + have = true; + break; + } + case kMapSet: { + if (!have) { + break; + } + std::string k = next_str(fdp); + live.attr("__setitem__")(py::str(k), next_int(fdp)); + break; + } + case kMapGetDel: { + if (!have) { + break; + } + std::string k = next_str(fdp); + try { + (void) live.attr("__getitem__")(py::str(k)); + } catch (const py::error_already_set &) { + } + (void) live.attr("__contains__")(py::str(k)); + try { + live.attr("__delitem__")(py::str(k)); + } catch (const py::error_already_set &) { + } + break; + } + case kIterate: { + if (!have) { + break; + } + py::iterator it = py::iter(live); + int steps = 0; + while (it != py::iterator::sentinel() && steps < 32) { + ++steps; + (void) py::reinterpret_borrow(*it); + ++it; + } + break; + } + case kWrongType: { + if (!have) { + break; + } + try { + live.attr("append")(py::str(next_str(fdp))); // str into IVec + } catch (const py::error_already_set &) { + } catch (const py::builtin_exception &) { + } + try { + live.attr("__getitem__")(next_int(fdp)); // int key into map + } catch (const py::error_already_set &) { + } + break; + } + default: + break; + } + if (ops % 6 == 0) { + (void) env.gc_mod.attr("collect")(); + } + } catch (const py::error_already_set &) { + // Expected control flow: IndexError/KeyError/TypeError. + } catch (const py::builtin_exception &) { + // Expected control flow: caster rejections. + } catch (const std::exception &) { + // Keep the gate clean from documented C++ exception paths. + } + } + } catch (const py::error_already_set &) { + } catch (const py::builtin_exception &) { + } catch (const std::exception &) { + } + return 0; +} + From 1ddf536214be1cf00eaaad1528131c835a061201 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:55:11 +0000 Subject: [PATCH 2/2] style: pre-commit fixes --- tests/fuzz/corpus_stl_bind_fuzzer/08_mapset | 2 +- .../fuzz/corpus_stl_bind_fuzzer/09_mapgetdel | 2 +- tests/fuzz/corpus_stl_bind_fuzzer/10_iterate | 2 +- .../fuzz/corpus_stl_bind_fuzzer/11_wrongtype | 1 - tests/fuzz/stl_bind_fuzzer.cpp | 198 +++++++++--------- 5 files changed, 100 insertions(+), 105 deletions(-) diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/08_mapset b/tests/fuzz/corpus_stl_bind_fuzzer/08_mapset index 303e398c82..7149f57e6a 100644 --- a/tests/fuzz/corpus_stl_bind_fuzzer/08_mapset +++ b/tests/fuzz/corpus_stl_bind_fuzzer/08_mapset @@ -1 +1 @@ - \ No newline at end of file + diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/09_mapgetdel b/tests/fuzz/corpus_stl_bind_fuzzer/09_mapgetdel index 5a77f05831..1c990f8e58 100644 --- a/tests/fuzz/corpus_stl_bind_fuzzer/09_mapgetdel +++ b/tests/fuzz/corpus_stl_bind_fuzzer/09_mapgetdel @@ -1 +1 @@ - \ No newline at end of file + diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/10_iterate b/tests/fuzz/corpus_stl_bind_fuzzer/10_iterate index 501a6bbaf1..8b13789179 100644 --- a/tests/fuzz/corpus_stl_bind_fuzzer/10_iterate +++ b/tests/fuzz/corpus_stl_bind_fuzzer/10_iterate @@ -1 +1 @@ - \ No newline at end of file + diff --git a/tests/fuzz/corpus_stl_bind_fuzzer/11_wrongtype b/tests/fuzz/corpus_stl_bind_fuzzer/11_wrongtype index 8b13789179..e69de29bb2 100644 --- a/tests/fuzz/corpus_stl_bind_fuzzer/11_wrongtype +++ b/tests/fuzz/corpus_stl_bind_fuzzer/11_wrongtype @@ -1 +0,0 @@ - diff --git a/tests/fuzz/stl_bind_fuzzer.cpp b/tests/fuzz/stl_bind_fuzzer.cpp index b85a6316be..8bbd438de7 100644 --- a/tests/fuzz/stl_bind_fuzzer.cpp +++ b/tests/fuzz/stl_bind_fuzzer.cpp @@ -22,15 +22,15 @@ // Input layout: op opcodes and small selectors from the END of the buffer // (first op = last byte); strings from the FRONT (ConsumeRandomLengthString). -#include +#include "pybind11/pybind11.h" +#include "pybind11/embed.h" +#include "pybind11/stl_bind.h" #include #include #include -#include "pybind11/embed.h" -#include "pybind11/pybind11.h" -#include "pybind11/stl_bind.h" +#include namespace py = pybind11; @@ -48,7 +48,7 @@ enum Op : uint8_t { kMapGetDel, kIterate, kWrongType, - kMaxOp // sentinel + kMaxOp // sentinel }; inline uint8_t next_op(FuzzedDataProvider &fdp) { @@ -63,16 +63,14 @@ inline int next_int(FuzzedDataProvider &fdp) { inline py::object next_index_object(FuzzedDataProvider &fdp, int size) { int raw = fdp.ConsumeIntegralInRange(-6, 14); if (raw < 0) { - raw += size; // exercise Python negative-index normalisation + raw += size; // exercise Python negative-index normalisation } return py::int_(raw); } -inline std::string next_str(FuzzedDataProvider &fdp) { - return fdp.ConsumeRandomLengthString(32); -} +inline std::string next_str(FuzzedDataProvider &fdp) { return fdp.ConsumeRandomLengthString(32); } -} // namespace pybind11_fuzz +} // namespace pybind11_fuzz PYBIND11_EMBEDDED_MODULE(fzb, m) { py::bind_vector>(m, "IVec"); @@ -88,8 +86,7 @@ struct FuzzEnv { py::object SVec; py::object SIMap; - FuzzEnv() - : guard{}, gc_mod(py::module_::import("gc")) { + FuzzEnv() : guard{}, gc_mod(py::module_::import("gc")) { py::object mod = py::module_::import("fzb"); IVec = mod.attr("IVec"); SVec = mod.attr("SVec"); @@ -130,7 +127,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { FuzzEnv &env = FuzzEnv::get(); FuzzedDataProvider fdp(data, size); - py::object live; // most recent container; replaced per op + py::object live; // most recent container; replaced per op bool have = false; try { @@ -140,113 +137,113 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const uint8_t op = next_op(fdp); try { switch (op) { - case kVecNew: { - live = env.IVec(); - have = true; - break; - } - case kVecAppend: { - if (!have) { + case kVecNew: { + live = env.IVec(); + have = true; break; } - live.attr("append")(next_int(fdp)); - break; - } - case kVecInsert: { - if (!have) { + case kVecAppend: { + if (!have) { + break; + } + live.attr("append")(next_int(fdp)); break; } - int sz = static_cast(py::len(live)); - live.attr("insert")(next_index_object(fdp, sz), next_int(fdp)); - break; - } - case kVecPopGet: { - if (!have) { + case kVecInsert: { + if (!have) { + break; + } + int sz = static_cast(py::len(live)); + live.attr("insert")(next_index_object(fdp, sz), next_int(fdp)); break; } - int sz = static_cast(py::len(live)); - try { - (void) live.attr("pop")(next_index_object(fdp, sz)); - } catch (const py::error_already_set &) { - } - break; - } - case kVecSetDel: { - if (!have) { + case kVecPopGet: { + if (!have) { + break; + } + int sz = static_cast(py::len(live)); + try { + (void) live.attr("pop")(next_index_object(fdp, sz)); + } catch (const py::error_already_set &) { + } break; } - int sz = static_cast(py::len(live)); - live.attr("__setitem__")(next_index_object(fdp, sz), next_int(fdp)); - break; - } - case kVecSliceLen: { - if (!have) { + case kVecSetDel: { + if (!have) { + break; + } + int sz = static_cast(py::len(live)); + live.attr("__setitem__")(next_index_object(fdp, sz), next_int(fdp)); break; } - (void) py::len(live); - (void) py::iter(live); - (void) live.attr("__getitem__")(py::int_(next_int(fdp))); - break; - } - case kMapNew: { - live = env.SIMap(); - have = true; - break; - } - case kMapSet: { - if (!have) { + case kVecSliceLen: { + if (!have) { + break; + } + (void) py::len(live); + (void) py::iter(live); + (void) live.attr("__getitem__")(py::int_(next_int(fdp))); break; } - std::string k = next_str(fdp); - live.attr("__setitem__")(py::str(k), next_int(fdp)); - break; - } - case kMapGetDel: { - if (!have) { + case kMapNew: { + live = env.SIMap(); + have = true; break; } - std::string k = next_str(fdp); - try { - (void) live.attr("__getitem__")(py::str(k)); - } catch (const py::error_already_set &) { - } - (void) live.attr("__contains__")(py::str(k)); - try { - live.attr("__delitem__")(py::str(k)); - } catch (const py::error_already_set &) { - } - break; - } - case kIterate: { - if (!have) { + case kMapSet: { + if (!have) { + break; + } + std::string k = next_str(fdp); + live.attr("__setitem__")(py::str(k), next_int(fdp)); break; } - py::iterator it = py::iter(live); - int steps = 0; - while (it != py::iterator::sentinel() && steps < 32) { - ++steps; - (void) py::reinterpret_borrow(*it); - ++it; - } - break; - } - case kWrongType: { - if (!have) { + case kMapGetDel: { + if (!have) { + break; + } + std::string k = next_str(fdp); + try { + (void) live.attr("__getitem__")(py::str(k)); + } catch (const py::error_already_set &) { + } + (void) live.attr("__contains__")(py::str(k)); + try { + live.attr("__delitem__")(py::str(k)); + } catch (const py::error_already_set &) { + } break; } - try { - live.attr("append")(py::str(next_str(fdp))); // str into IVec - } catch (const py::error_already_set &) { - } catch (const py::builtin_exception &) { + case kIterate: { + if (!have) { + break; + } + py::iterator it = py::iter(live); + int steps = 0; + while (it != py::iterator::sentinel() && steps < 32) { + ++steps; + (void) py::reinterpret_borrow(*it); + ++it; + } + break; } - try { - live.attr("__getitem__")(next_int(fdp)); // int key into map - } catch (const py::error_already_set &) { + case kWrongType: { + if (!have) { + break; + } + try { + live.attr("append")(py::str(next_str(fdp))); // str into IVec + } catch (const py::error_already_set &) { + } catch (const py::builtin_exception &) { + } + try { + live.attr("__getitem__")(next_int(fdp)); // int key into map + } catch (const py::error_already_set &) { + } + break; } - break; - } - default: - break; + default: + break; } if (ops % 6 == 0) { (void) env.gc_mod.attr("collect")(); @@ -265,4 +262,3 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { } return 0; } -