Skip to content

Commit 1db35b5

Browse files
friedmeta-codesync[bot]
authored andcommitted
Fix for modern cython stdlib 3.1.x for request_context optional.value()
Summary: In cython 3.1.x optional definition in the cython stdlib changed `.value` to have an except + which causes cython to generate broken c++ "most" of the time. ``` ================================================================= ==1176273==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7efd7956ef88 at pc 0x7efd5934d54e bp 0x7ffcf3642b50 sp 0x7ffcf3642b48 READ of size 8 at 0x7efd7956ef88 thread T0 SCARINESS: 23 (8-byte-read-stack-use-after-scope) #0 0x7efd5934d54d in std::basic_string_view<char, std::char_traits<char>>::data() const fbcode/third-party-buck/platform010/build/libgcc/include/c++/trunk/string_view:263 #1 0x7efd5934a17b in __pyx_f_6thrift_6python_11server_impl_15request_context__get_agent_from_metadata[abi:cxx11](std::optional<apache::thrift::ClientMetadataRef>) buck-out/v2/gen/fbcode/a71b5f55c381bd0a/thrift/lib/python/server/__request_context__request_context.cpp__/out/request_context.cpp:21692 ``` In c++ this looks like ``` try { _pyx_s = Opt.value(): } catch (...) { } _pyx_r_s = _pyx_s.value(); ``` So since the first optional is not moveable the variable goes out of scope. and thus address sanitizer has issues. Reviewed By: itamaro Differential Revision: D85457795 fbshipit-source-id: 0befb2e2cb4c9efd62c1fdcaa6ba48f7162b7136
1 parent d17f9d9 commit 1db35b5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

third-party/thrift/src/thrift/lib/python/server/request_context.pxd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from cpython.ref cimport PyObject
1616
from libc.stdint cimport uint64_t
1717
from libcpp cimport bool as cbool
18-
from libcpp.optional cimport optional
1918
from libcpp.memory cimport unique_ptr
2019
from libcpp.string cimport string
2120
from libcpp.utility cimport pair
@@ -26,6 +25,12 @@ from thrift.python.common cimport cPriority
2625
from thrift.python.server_impl.event_handler cimport cfollySocketAddress
2726
from thrift.python.common cimport Headers
2827

28+
# Cython stdlib in 3.1.x has an except+ on the value() which breaks C++ scoping rules.
29+
cdef extern from "<optional>" namespace "std" nogil:
30+
cdef cppclass optional[T]:
31+
cbool has_value()
32+
T& value()
33+
2934
cdef extern from "folly/container/F14Map.h" namespace "folly":
3035
cdef cppclass F14NodeMap[K, T]:
3136
cppclass const_iterator:

0 commit comments

Comments
 (0)