capnproto / pycapnp

Cap'n Proto serialization/RPC system - Python bindings
BSD 2-Clause "Simplified" License
468 stars 124 forks source link

Avoid reading random values for reader options from dangling reference #300

Closed sndmitriev closed 1 year ago

sndmitriev commented 1 year ago

This patch fixes a problem of reading random values for reader options in pycapnp. The code which adds task to the list captures 'opts' by reference and that causes a problem in case when 'opts' is allocated on on the caller's stack. By the time when task is handled the stack frame holding the 'opts' is gone which leaves dangling reference to 'opts' in lambda's captures. As a result pycapnp reads random values for reader options which sometimes causes unexpected errors (for example an error that nesting level is negative).

sndmitriev commented 1 year ago

Failure on "LGTM analysis: C/C++" does not look related to this change.

haata commented 1 year ago

Looks great! Thank you!

Do you expect any compatibility issues with previous releases?

sndmitriev commented 1 year ago

No, I think there should be no compatibility issues.

sndmitriev commented 1 year ago

But I think it makes sense to make a new release (v1.2.2) since the problem actually shows up quite often on intensive use.

haata commented 1 year ago

I'll see if I can find some time this weekend to do a release. Thanks!

sndmitriev commented 1 year ago

That would be great. Thank you!