Repository navigation
fix(libsql): preserve embedded NULs in Row::get_value, return error on bad UTF-8 - #2288
Open
Sanjays2402 wants to merge 1 commit into
Open
Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2285
Hi, ran into this while round-tripping TEXT through the local driver:
Row::get_valuesilently 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_valuenow goes through the existing length-awareget_refpath (which already reads the exact byte count), detaches the value, and maps failed UTF-8 decoding toError::InvalidColumnTypeinstead of unwrapping.Repro (before the fix, on current main):
SELECT ?1withValue::Text("a\0b")returnedText("a")SELECT CAST(x'80' AS TEXT)panicked with anUtf8ErrorunwrapAfter the fix:
SELECT ?1withValue::Text("a\0b")returnsText("a\0b")SELECT CAST(x'80' AS TEXT)returnsErr(InvalidColumnType), no panicTests:
libsql/tests/get_value_text.rs(3 tests, all pass)cargo test -p libsql --lib: 23 passed, 0 failedcargo test -p libsql --test integration_tests: 27 passed, 0 failed (1 pre-existing ignore)