Skip to content

Commit

Permalink
don't access proof after dropping gil (#470)
Browse files Browse the repository at this point in the history
In `validate_proof` the `proof` variable is accessed after dropping the
GIL. This can result in crashes as python may have released that memory
at any time after the GIL is dropped.

Make sure to use a temp var to hold the proof size so we can avoid
referencing this var
  • Loading branch information
emlowe authored Jan 31, 2025
2 parents 183501e + 26235de commit 9055976
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python-bindings/chiapos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ PYBIND11_MODULE(chiapos, m)

std::string proof_str(proof);
const uint8_t *proof_ptr = reinterpret_cast<const uint8_t *>(proof_str.data());
auto proof_size = proof_str.size();

LargeBits quality;
{
py::gil_scoped_release release;
quality = v.ValidateProof(seed_ptr, k, challenge_ptr, proof_ptr, len(proof));
quality = v.ValidateProof(seed_ptr, k, challenge_ptr, proof_ptr, proof_size);
}
if (quality.GetSize() == 0) {
return stdx::optional<py::bytes>();
Expand Down

0 comments on commit 9055976

Please sign in to comment.