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

Aperta Adatta ai principianti
#545 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp, rust
Ambito
api, database

Direzione di ricerca

Inizia dal ramo Custom di CassDataTypeInner::typecheck_equals in scylla-rust-wrapper/src/cql_types/data_type.rs (intorno alle righe 305-307), poi segui la ricorsione attraverso CassCqlValue::is_type_compatible in scylla-rust-wrapper/src/cql_types/value.rs per vedere quali chiamanti espongono il risultato come CASS_ERROR_LIB_INVALID_VALUE_TYPE. Riproduci con lo unit test abbozzato nell’issue (list<custom> inserito in un tuple<list<int>>) ed eseguilo per confermare l’interruzione prima di modificare qualsiasi cosa. Fatto significa che quel percorso di test restituisce un errore invece di andare in panic, con i test cql_types esistenti che continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
27
Fork
18
Merge medio
1g 7h
PR unite (30g)
5

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scylladb/cpp-rs-driver

Tutte le issue di scylladb/cpp-rs-driver

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.