File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change 1+ Fix UB in ` FunctionDescription::extract_arguments_fastcall ` due to creating slices from a null pointer.
Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ impl FunctionDescription {
221221 /// Equivalent of `extract_arguments_tuple_dict` which uses the Python C-API "fastcall" convention.
222222 ///
223223 /// # Safety
224- /// - `args` must be a pointer to a C-style array of valid `ffi::PyObject` pointers.
224+ /// - `args` must be a pointer to a C-style array of valid `ffi::PyObject` pointers, or NULL .
225225 /// - `kwnames` must be a pointer to a PyTuple, or NULL.
226226 /// - `nargs + kwnames.len()` is the total length of the `args` array.
227227 #[ cfg( not( Py_LIMITED_API ) ) ]
@@ -240,7 +240,11 @@ impl FunctionDescription {
240240 // Safety: Option<&PyAny> has the same memory layout as `*mut ffi::PyObject`
241241 let args = args as * const Option < & PyAny > ;
242242 let positional_args_provided = nargs as usize ;
243- let args_slice = std:: slice:: from_raw_parts ( args, positional_args_provided) ;
243+ let args_slice = if args. is_null ( ) {
244+ & [ ]
245+ } else {
246+ std:: slice:: from_raw_parts ( args, positional_args_provided)
247+ } ;
244248
245249 let num_positional_parameters = self . positional_parameter_names . len ( ) ;
246250
You can’t perform that action at this time.
0 commit comments