Skip to content

fix(libsql): preserve embedded NULs in Row::get_value, return error on bad UTF-8 - #2288

Open
Sanjays2402 wants to merge 1 commit into
tursodatabase:mainfrom
Sanjays2402:fix-2285-owned-text-nul
Open

Sanjays2402 wants to merge 1 commit into
tursodatabase:mainfrom
Sanjays2402:fix-2285-owned-text-nul

Conversation

@Sanjays2402

Copy link
Copy Markdown

Fixes #2285

Hi, ran into this while round-tripping TEXT through the local driver: Row::get_value silently chopped any text at the first NUL byte, and outright panicked when stored TEXT was not valid UTF-8. The SQLite side keeps the full bytes, so the loss was all in the owned-value conversion.

The fix is small and keeps the SQL engine untouched. get_value now goes through the existing length-aware get_ref path (which already reads the exact byte count), detaches the value, and maps failed UTF-8 decoding to Error::InvalidColumnType instead of unwrapping.

Repro (before the fix, on current main):

  • SELECT ?1 with Value::Text("a\0b") returned Text("a")
  • SELECT CAST(x'80' AS TEXT) panicked with an Utf8Error unwrap

After the fix:

  • SELECT ?1 with Value::Text("a\0b") returns Text("a\0b")
  • SELECT CAST(x'80' AS TEXT) returns Err(InvalidColumnType), no panic
  • NULL, integer, real, BLOB, empty TEXT, and Unicode values all keep their storage types, and the connection stays usable afterwards

Tests:

  • new regression tests in libsql/tests/get_value_text.rs (3 tests, all pass)
  • cargo test -p libsql --lib: 23 passed, 0 failed
  • cargo test -p libsql --test integration_tests: 27 passed, 0 failed (1 pre-existing ignore)

Convert owned TEXT values through the length-aware get_ref path
instead of a NUL-terminated CStr. Embedded NULs are preserved, and
malformed UTF-8 now returns Error::InvalidColumnType instead of
panicking.

Fixes tursodatabase#2285

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant