Preserve embedded NUL bytes in TEXT values - #331
Open
sbking wants to merge 1 commit into
Open
Conversation
rhashimoto
requested changes
Jul 19, 2026
rhashimoto
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR! I have one requested change and one question inline.
| verifyStatement(stmt); | ||
| const result = f(stmt, iCol); | ||
| return result; | ||
| const address = f(stmt, iCol); |
Owner
There was a problem hiding this comment.
address can be 0 if the column is SQL NULL, in which case we should return null.
| return result; | ||
| const address = f(stmt, iCol); | ||
| const nBytes = sqlite3.column_bytes(stmt, iCol); | ||
| const parts = []; |
Owner
There was a problem hiding this comment.
I don't think I understand this part. Why wouldn't we use TextDecoder on the whole buffer here?
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.
Summary
sqlite3_bind_textso embedded NUL bytes are not treated as a C-string terminatorsqlite3_column_textwith itssqlite3_column_byteslength and preserve embedded NULs without changing the existing Emscripten UTF-8 decoding behaviorTesting
yarn testunder Node 20 and Chrome: 2,993 passed, 0 failednode --check src/sqlite-api.jsReferences
sqlite3_bind_textcontract specifies that a negative byte length stops at the first NUL, while an explicit non-negative length preserves embedded NULs.sqlite3_column_bytesas the full UTF-8 byte length and recommends callingsqlite3_column_textbeforesqlite3_column_bytes.Checklist
non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
derivative works of, publicly display, sublicense, and distribute this
Contribution and such derivative works.
Contribution contains no content requiring a license from any third party.