Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Rust local Row::get_value truncates embedded NUL TEXT and panics on malformed UTF-8 (0.9.30)

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

@Sanjays2402 がすでに取り組んでいます。

2026年10月12日 から。

  • #2288 @Sanjays2402 による — オープン

評価

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

調査の方向性

libsql/src/local/rows.rs から始め、正確なバイト長を保持する既存の get_ref パスと Row::get_value を比較します。所有された TEXT 値が埋め込まれた NUL バイトを保持し、不正な UTF-8 に対してエラーを返すことを確認します。その一方で、NULL、数値、BLOB、空、Unicode の値が期待される型を維持することも確認します。関連するローカル Rust テストを実行するか、カバレッジが不足している場合はリグレッションテストを追加します。

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

説明

The local Rust driver in libsql 0.9.30 silently truncates owned TEXT values at an embedded NUL, and panics rather than returning an error when the stored TEXT contains malformed UTF-8. The SQLite value remains intact; the loss happens in the owned-value conversion.

Reproduced on macOS arm64 with Rust 1.98.1, using registry libsql/libsql-sys/libsql-ffi 0.9.30 and the local core feature. There is no downstream patch in this reproduction.

Cargo.toml:

[package]
name = "libsql-owned-text-report"
version = "0.1.0"
edition = "2024"

[dependencies]
libsql = { version = "=0.9.30", default-features = false, features = ["core"] }
tokio = { version = "=1.47.1", features = ["rt", "macros"] }

src/main.rs:

use libsql::{Builder, Value};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let database = Builder::new_local(":memory:").build().await?;
    let connection = database.connect()?;
    let mut rows = connection.query("SELECT ?1", ["a\0b"]).await?;
    let row = rows.next().await?.unwrap();
    println!("expected {:?}, actual {:?}",
        Value::Text("a\0b".into()), row.get_value(0)?);
    drop(row);
    drop(rows);

    let mut rows = connection.query("SELECT CAST(x'80' AS TEXT)", ()).await?;
    let row = rows.next().await?.unwrap();
    let result = std::panic::catch_unwind(
        std::panic::AssertUnwindSafe(|| row.get_value(0))
    );
    println!("malformed UTF-8 panicked={}", result.is_err());
    Ok(())
}

Observed:

expected Text("a\0b"), actual Text("a")
... value.rs:237:40: called Result::unwrap() on an Err value: Utf8Error ...
malformed UTF-8 panicked=true

Expected: the first owned value preserves all three bytes; the second returns a decoding error through Result instead of panicking. Truncation also makes distinct persisted TEXT keys appear identical to code reading owned values.

The local Row::get_value path converts sqlite3_column_text using a NUL-terminated CStr, then the owned FromValue conversion unwraps UTF-8 decoding. The existing Row::get_ref path already obtains the exact byte length. A downstream correction detaches those ValueRef values, preserving TEXT length and returning InvalidColumnType on failed std::str::from_utf8. NULL, integer, real and BLOB retain their storage types; empty TEXT/BLOB and Unicode remain supported.

Our downstream regressions cover embedded NUL/Unicode, empty values, malformed UTF-8 refusal, detached owned values and subsequent connection reuse. This report is independent of the connection teardown issue #2251.

Proposed local-driver patch (the SQL engine is unchanged):

--- a/libsql/src/local/rows.rs
+++ b/libsql/src/local/rows.rs
@@ -127,8 +127,17 @@
     }
 
     pub fn get_value(&self, idx: i32) -> Result<Value> {
-        let val = self.stmt.inner.column_value(idx);
-        <crate::Value as FromValue>::from_sql(val)
+        // Use the exact byte length, preserve NULs,
+        // and reject invalid UTF-8 instead of truncating or panicking.
+        match self.get_ref(idx)? {
+            ValueRef::Null => Ok(Value::Null),
+            ValueRef::Integer(n) => Ok(Value::Integer(n)),
+            ValueRef::Real(n) => Ok(Value::Real(n)),
+            ValueRef::Text(bytes) => std::str::from_utf8(bytes)
+                .map(|text| Value::Text(text.to_owned()))
+                .map_err(|_| Error::InvalidColumnType),
+            ValueRef::Blob(bytes) => Ok(Value::Blob(bytes.to_vec())),
+        }
     }
 
     pub fn column_type(&self, idx: i32) -> Result<ValueType> {
主要言語
C
スター
17.3k
フォーク
545
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

tursodatabase/libsql のほかの issue

tursodatabase/libsql の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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