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

オープン 初心者向け
#545 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, rust
領域
api, database

調査の方向性

Custom アームから始めます。これは CassDataTypeInner::typecheck_equals の scylla-rust-wrapper/src/cql_types/data_type.rs(305-307 行あたり)にあり、次に CassCqlValue::is_type_compatible を通る再帰を scylla-rust-wrapper/src/cql_types/value.rs でたどって、どの呼び出し元が結果を CASS_ERROR_LIB_INVALID_VALUE_TYPE として表に出すかを確認します。issue にスケッチされている単体テスト(list<custom> を tuple<list<int>> に入れる)で再現し、何も変更する前に実行して abort を確認します。完了とは、そのテスト経路が panic せずにエラーを返し、既存の cql_types テストが引き続き通ることです。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C++
スター
27
フォーク
18
平均マージ
1日 7時間
マージ済み PR(30日)
5

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

scylladb/cpp-rs-driver のほかの issue

scylladb/cpp-rs-driver の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。