typecheck_equals aborts the process on custom data types (unimplemented!)

Open Beginner friendly
#545 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, rust
Domain
api, database

Research direction

Start at the Custom arm of CassDataTypeInner::typecheck_equals in scylla-rust-wrapper/src/cql_types/data_type.rs (around lines 305-307), then follow the recursion through CassCqlValue::is_type_compatible in scylla-rust-wrapper/src/cql_types/value.rs to see which callers surface the result as CASS_ERROR_LIB_INVALID_VALUE_TYPE. Reproduce with the unit test sketched in the issue (list<custom> set into a tuple<list<int>>) and run it to confirm the abort before changing anything. Done means that test path returns an error instead of panicking, with the existing cql_types tests still passing.

Written by the indexing model from the issue text.

Description

area/Driver_-_cpp-rs-driver bug

What goes wrong

CassDataTypeInner::typecheck_equals ends with:

https://github.com/scylladb/cpp-rs-driver/blob/7a86e01c2f6e07ceb45633f697c7507349a6108b/scylla-rust-wrapper/src/cql_types/data_type.rs#L305-L307

so any typecheck where the value-side type is (or contains) a Custom type panics. It runs inside extern "C" setters, so the process aborts.

A Custom data type is reachable through the public API: cass_data_type_new(CASS_VALUE_TYPE_CUSTOM) returns one, and cass_data_type_add_sub_type accepts it as a subtype:

https://github.com/scylladb/cpp-rs-driver/blob/7a86e01c2f6e07ceb45633f697c7507349a6108b/scylla-rust-wrapper/src/cql_types/data_type.rs#L613

Building a collection/tuple/UDT from such a type and then setting it into a typed tuple, UDT or collection (or binding it) goes through CassCqlValue::is_type_compatible -> typecheck_equals, which recurses into the subtypes and hits the Custom arm:

https://github.com/scylladb/cpp-rs-driver/blob/7a86e01c2f6e07ceb45633f697c7507349a6108b/scylla-rust-wrapper/src/cql_types/value.rs#L154-L196

The expected outcome is CASS_ERROR_LIB_INVALID_VALUE_TYPE (or rejecting CUSTOM up front), not an abort.

Related: #158 (plan to drop custom types entirely). Until that lands, the API still hands out Custom types that later crash the process.

Reproduction

Temporary unit test in scylla-rust-wrapper/src/cql_types/data_type.rs tests:

// list<custom>
let custom = cass_data_type_new(CassValueType::CASS_VALUE_TYPE_CUSTOM);
let list_custom = cass_data_type_new(CassValueType::CASS_VALUE_TYPE_LIST);
cass_data_type_add_sub_type(list_custom.borrow(), custom.borrow().into_c_const());
// tuple<list<int>>
let int_t = cass_data_type_new(CassValueType::CASS_VALUE_TYPE_INT);
let list_int = cass_data_type_new(CassValueType::CASS_VALUE_TYPE_LIST);
cass_data_type_add_sub_type(list_int.borrow(), int_t.borrow().into_c_const());
let tup_t = cass_data_type_new(CassValueType::CASS_VALUE_TYPE_TUPLE);
cass_data_type_add_sub_type(tup_t.borrow(), list_int.borrow().into_c_const());

let coll = cass_collection_new_from_data_type(list_custom.borrow().into_c_const(), 0);
let mut tup = cass_tuple_new_from_data_type(tup_t.borrow().into_c_const());
cass_tuple_set_collection(tup.borrow_mut(), 0, coll.borrow().into_c_const());
panicked at src/cql_types/data_type.rs:306:17:
not implemented: cpp-rs-driver does not support custom types!
panicked at .../core/src/panicking.rs:225:5:
panic in a function that cannot unwind
thread caused non-unwinding panic. aborting.

Fix direction

Make the Custom arm of typecheck_equals return a result instead of panicking: either false (so the setter returns CASS_ERROR_LIB_INVALID_VALUE_TYPE), or, closer to cpp-driver, compare the custom class names when other is also Custom. Alternatively, since custom types are not supported (#158), have cass_data_type_new(CASS_VALUE_TYPE_CUSTOM) return NULL so a Custom type can never reach the typecheck.

Dominant language
C++
Stars
27
Forks
18
Avg merge
1d 7h
Merged PRs (30d)
5

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from scylladb/cpp-rs-driver

All issues in scylladb/cpp-rs-driver

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.