Fix truncation of strings containing non-terminal NUL characters - #1880
Open
nesevis wants to merge 3 commits into
Open
Fix truncation of strings containing non-terminal NUL characters#1880nesevis wants to merge 3 commits into
nesevis wants to merge 3 commits into
Conversation
`sqlite3_bind_text` and `sqlite3_result_text` treat a negative length as "the number of bytes up to the first zero terminator", so a Swift string containing a NUL was truncated on the way in. Passing the byte count of the UTF-8 buffer makes those strings roundtrip. It also avoids the length scan SQLite performs for a negative length value, and the NUL-terminated copy that `withCString` allocates.
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.
See #1878 for more context on this fix.
This PR resolves an issue where strings containing non-terminal NUL characters were truncated when persisted, and again when retrieved. It adds regression and performance tests.
This change also reduces allocation and saves a
strlencall during writes, at the cost of incurring a newsqlite3_column_bytescall during reads. The largest tangible benefit will be had by users of Swift string functions (capitalize,lowercase,uppercase, etc), with some benefits to writes in general.The fix itself is the last commit in the branch, so regression and performance tests can be confirmed by checking out the first and second commits.
Pull Request Checklist
developmentbranch.make smokeTestterminal command runs without failure.