Skip to content

fix: replace from_utf8_unchecked with from_utf8_lossy in SqliteError#4202

Open
joaquinhuigomez wants to merge 1 commit intolaunchbadge:mainfrom
joaquinhuigomez:fix/sqlite-error-utf8-safety
Open

fix: replace from_utf8_unchecked with from_utf8_lossy in SqliteError#4202
joaquinhuigomez wants to merge 1 commit intolaunchbadge:mainfrom
joaquinhuigomez:fix/sqlite-error-utf8-safety

Conversation

@joaquinhuigomez
Copy link
Copy Markdown
Contributor

Replace from_utf8_unchecked with from_utf8_lossy in SqliteError::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 current from_utf8_unchecked call is unsound in that case since it constructs an invalid Rust String.

from_utf8_lossy replaces invalid sequences with U+FFFD, which preserves the error message while maintaining soundness. The from_code() path using sqlite3_errstr() is left as-is since SQLite documents that function as returning UTF-8.

Closes #4193

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
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.

sqlite: SqliteError::try_new() unsafely assumes sqlite3_errmsg() is UTF-8

1 participant