fix: replace from_utf8_unchecked with from_utf8_lossy in SqliteError#4202
Open
joaquinhuigomez wants to merge 1 commit intolaunchbadge:mainfrom
Open
fix: replace from_utf8_unchecked with from_utf8_lossy in SqliteError#4202joaquinhuigomez wants to merge 1 commit intolaunchbadge:mainfrom
joaquinhuigomez wants to merge 1 commit intolaunchbadge:mainfrom
Conversation
sqlite3_errmsg() returns UTF-8 in practice but the spec does not guarantee it. Using from_utf8_unchecked is unsound if non-UTF-8 bytes are returned (e.g. from malformed schema element names). Closes launchbadge#4193
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.
Replace
from_utf8_uncheckedwithfrom_utf8_lossyinSqliteError::try_new().sqlite3_errmsg()can return non-UTF-8 bytes when schema element names contain invalid UTF (e.g. from a malicious or corrupted database file). The currentfrom_utf8_uncheckedcall is unsound in that case since it constructs an invalid RustString.from_utf8_lossyreplaces invalid sequences with U+FFFD, which preserves the error message while maintaining soundness. Thefrom_code()path usingsqlite3_errstr()is left as-is since SQLite documents that function as returning UTF-8.Closes #4193