Repository navigation
Catch panics and guard null pointers across vortex-ffi - #12331
lwwmanning wants to merge 4 commits into
Conversation
Signed-off-by: Will Manning <will@willmanning.io>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
roborev: Combined Review (
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7cdabd1af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
The switch from C-unwind to C is the right fix. The try_as_ref guards in functions that take error_out are a clear improvement. My concern is the fallback values in functions with no error channel. Before this PR those inputs panicked. Now several return a wrong answer that looks valid.
- vortex-ffi/src/dtype.rs lines 213 to 220: vx_dtype_get_variant reports DTYPE_NULL for Map, Union, Variant and FixedSizeBinary. Import an Arrow schema with a Map field and walk it. The Map column then reads as a Null column, in the C example and in the C++ DataType::variant(). At line 234, vx_dtype_primitive_ptype returns PTYPE_U8 for any non-primitive dtype. I would let both abort on these inputs, which extern "C" already does for a panic. A new DTYPE_UNKNOWN value also works, but it changes the generated header and the C++ enum.
- vortex-ffi/src/scalar.rs lines 82 to 337 and vortex-ffi/src/array.rs line 575: the getters now return 0, false or a null view when the input is wrong. For example, vx_scalar_get_decimal_i32 returns 0 for a decimal(12, 0) scalar that holds 100000000000. The doc comments and cinclude/vortex.h still say these functions panic. Please keep the panic here, or name the fallback in each doc comment and regenerate the header.
- Proportion: many sites wrap bodies that cannot fail on caller input in catch_or. Examples are dtype.rs lines 104 and 110, scalar.rs line 72, expression.rs line 62 and lib.rs line 178. Under extern "C", a panic there already aborts. Dropping catch_or from these sites removes a large share of the added lines.
- vortex-ffi/src/dtype.rs line 198: vx_dtype_new_decimal now returns NULL with no error for invalid precision or scale. The C++ wrapper at lang/cpp/src/dtype.cpp line 177 adopts that NULL, so the C++ DataType fails later, far from the cause. Please throw in the C++ wrapper when the call returns NULL.
…guard C++ decimal Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Addressed all four points in
|
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
Commit d8899d2 resolves my earlier review. The getters with no error channel panic again, so they abort instead of returning a value that looks valid. That covers vx_dtype_get_variant, vx_dtype_primitive_ptype, the scalar getters and vx_array_get_bool. The C++ decimal wrapper now throws when the C call returns a null pointer, and with catch_or gone the diff is in proportion. One optional nit: the doc comment at vortex-ffi/src/dtype.rs line 180 could say that vx_dtype_new_decimal returns a null pointer for an invalid precision or scale. That change also needs a header regeneration.
…pe_new_decimal Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Updated the doc comment on |
lwwmanning
left a comment
There was a problem hiding this comment.
Review by Gemini 4 Carbon on behalf of @lwwmanning.
Switching all vortex-ffi entrypoints to extern "C" and keeping panic-to-abort on the infallible getters looks good. Two concrete contract/wrapper bugs need fixes before merge:
- Arrow C Data Interface leak on null/error paths (
vx_array_from_arrowandvx_dtype_from_arrow_schema):- Both functions document in
vortex.hthatarrayandschemaare unconditionally consumed (theirreleasecallbacks are invoked by the callee and the caller must not release them afterwards). Unlikevx_partition_scan_arrowandvx_struct_fields_builder_add_field,vx_array_from_arrowandvx_dtype_from_arrow_schemacurrently checkvx_session::try_as_ref(session)?(and the sibling pointer) beforeptr::replace(..., FFI_Arrow*::empty()). Now that a nullsession(or mixed-null(array, NULL)/(NULL, schema)call) returnsNULL+error_outinstead of aborting, any validFFI_ArrowArrayorFFI_ArrowSchemapassed to the call is left unreleased and leaked.
- Both functions document in
- C++
Expression::selectadoptsnullptron invalid UTF-8 (lang/cpp/src/expression.cpp):vx_expression_selectnow returnsNULLinstead of panicking whennamescontains invalid UTF-8, butselect_implinlang/cpp/src/expression.cpp:54passes the result straight toAccess::adopt<Expression>(...)without checkingout == nullptr(unlikeExpression::operator[]right above it anddtype::decimal), constructing a C++Expressionwrapping a null handle.vx_expression_select's doc comment andvortex.halso omit itsNULLreturn contract.
Remediation Plan
vortex-ffi/src/array.rs(vx_array_from_arrow): Move out whichever ofarrayandschemais non-null viaptr::replace(..., FFI_ArrowArray::empty())/ptr::replace(..., FFI_ArrowSchema::empty())before checking for nullarray, nullschema, orvx_session::try_as_ref(session)?(matchingvortex-jni-native/src/writer.rs'swriteBatch), soDropinvokes the exporter'sreleasecallback on every error path. Add an assertion invortex-ffitests verifyingreleaseis cleared whenvx_array_from_arrowfails on a nullsession.vortex-ffi/src/dtype.rs(vx_dtype_from_arrow_schema): Aftervortex_ensure!(!schema.is_null(), "null arrow schema"), immediately take ownership vialet ffi_schema = unsafe { ptr::replace(schema, FFI_ArrowSchema::empty()) };beforevx_session::try_as_ref(session)?, and add a test assertion thatschema.releaseis cleared whensessionis null.lang/cpp/src/expression.cpp(select_impl) &vortex-ffi/src/expression.rs(vx_expression_select):- In
select_impl(lang/cpp/src/expression.cpp:54), checkif (out == nullptr) { throw VortexException("select: field name is not valid UTF-8"); }beforeAccess::adopt<Expression>(out), and add aREQUIRE_THROWS_AScase inlang/cpp/tests/(mirroringdtype.cpp's invalid UTF-8 test). - Document on
vx_expression_selectinvortex-ffi/src/expression.rsthat it returnsNULLifchildis null,namesis null withlen > 0, or any field name is not valid UTF-8, and regeneratevortex-ffi/cinclude/vortex.h.
- In
…ion::select Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Addressed both findings:
|
Several
vortex-ffientrypoints usedextern "C-unwind"(allowing Rust panics to unwind across C frames without-fexceptions) or unwrappedextern "C"calls that panicked on null pointers, null slice elements, or invalid decimal parameters. All C FFI entrypoints now useextern "C", catch panics viatry_or/try_or_defaulton error-returning paths, validate pointer arguments before dereferencing, and consume and release passed Arrow C Data Interface structs (vx_array_from_arrow,vx_dtype_from_arrow_schema) on error paths. Value-returning getters without an error channel (vx_dtype_get_variant,vx_dtype_primitive_ptype,vx_scalar_get_*,vx_array_get_bool) keep their documented panic-to-abort behavior on invalid inputs rather than returning misleading fallback values, and the C++dtype::decimalandExpression::selectwrappers throwVortexExceptionon invalid parameters.Assisted by Antigravity and Devin.