Repository navigation
feat: Add a UTF-8 validator for strings read from SQLite - #845
Conversation
`rsqlite_is_utf8_string()`, declared in `src/utf8.h` and defined in `src/utf8.cpp`, tells whether a byte range is well-formed UTF-8 without a NUL byte, which is what an R string can hold. It follows RFC 3629, so it rejects overlong forms, surrogates, and code points beyond U+10FFFF. ASCII text is checked eight bytes at a time. Nothing calls the validator yet, so there is no user-visible change. It is the shared infrastructure for checking text that is read from SQLite, in the data frame path and in the Arrow path. The unexported `utf8_valid()` exposes it for the tests, which compare it with `validUTF8()` from base R. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
|
CI note for #845 and #846: the smoke test failed on both before any R code ran. The shared install step could not resolve the Ubuntu package mirrors ( Generated by Claude Code |
|
Review of this pull request at fe9f927, by a Claude Code reviewer with clean context that read the description and commit message, What was run
What holds
HighNone. MediumNone. Low1. The truncation tests cannot detect a read past the end (Confirmed). 2. No test passes NULL (Confirmed). 3. The test for non-raw input accepts any error (by reading). At Generated by Claude Code |
The test hook utf8_valid() now copies each input into a buffer with three continuation bytes behind it. A validator that reads past the end then sees a truncated sequence as valid, and the truncation tests fail. Empty input is passed to the validator as NULL, which the header allows, so the empty-input test covers it. The non-raw input test now checks for cpp11's "expected 'raw'" message instead of accepting any error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The build regenerated it with system headers, and the previous commit picked that up by mistake. The includes did not change, so the committed file stands. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Superseded: Accepted limitationsSuperseded by the current copy. The clean review found nothing above Low. Its three Low findings, all about what the tests can detect, are fixed in eda8143: the test hook copies each input into a buffer with continuation bytes behind it, so that a read past the end fails the truncation tests, passes NULL for empty input, and the test for non-raw input expects cpp11's message. 1dc1f28 only removes a generated build file that eda8143 added by mistake. This remains:
Generated by Claude Code |
`load_all()` sources `tests/testthat/helper*.R` but not the top level of a test file. `utf8_reference()`, `hex()`, `ascii()`, `pad()` and `expect_utf8()` move to `helper-utf8.R`. Helper files are shared by every test file, so the generic `hex()`, `ascii()` and `pad()` become `raw_hex()`, `raw_ascii()` and `raw_pad()`. Every `test_that()` block of `test-utf8.R` now runs on its own after `load_all()`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The CI's auto-update regenerated `src/cpp11.dd` and `src/utf8.dd` with GCC, whose dependency output indents continuation lines by one space, which the filter in `src/Makevars.deps` does not drop, so the files gained hundreds of absolute and vendored paths (#836). This restores them as they were and keeps the auto-update's formatting of `src/utf8.cpp`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Question: avoid the conflict on
|
Accepted limitationsThe clean review found nothing above Low. Its three Low findings, all about what the tests can detect, are fixed in eda8143: the test hook copies each input into a buffer with continuation bytes behind it, so that a read past the end fails the truncation tests, passes NULL for empty input, and the test for non-raw input expects cpp11's message. 1dc1f28 only removes a generated build file that eda8143 added by mistake. This remains:
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7mthffYErGmWTGDfQ
As asked on #799, which is reimplemented from
mainas a stack: this pull request adds the UTF-8 infrastructure, and #846 builds the checks of text columns on it.rsqlite_is_utf8_string(), declared insrc/utf8.hand defined insrc/utf8.cpp, tells whether a byte range is well-formed UTF-8 without a NUL byte, which is what an R string can hold. It follows RFC 3629, so it rejects overlong forms, surrogates and code points beyond U+10FFFF. ASCII text is checked eight bytes at a time; a word that holds a NUL or a byte above 127 is checked sequence by sequence, and the loop then returns to whole words.textmay be NULL whensizeis 0.Nothing calls the validator yet, so there is no user-visible change. #795 carries its own copy of the validator for the Arrow path (
src/utf8.h, with the fast path insrc/SqliteArrowColumn.cpp); when it switches to this one is a question on #829. Defining the function in a.cppfile follows the recommended answer to the question about the header.The unexported
utf8_valid()exposes the validator to the tests, whose fixtures live intests/testthat/helper-utf8.R, so every block runs on its own afterload_all().tests/testthat/test-utf8.Rcompares it with a reference built from base R (validUTF8()after a check for NUL bytes) on every 1- and 2-byte string, grids of 3- and 4-byte strings, padding across the eight-byte words, a NUL at every position up to 20 bytes, and random strings. Breaking the validator in six ways, one at a time (the limits after E0, ED and F4, NUL detection in the fast path and for single bytes, accepting C0 and C1), makes the tests fail each time.R CMD check --no-manualreports Status OK.A clean review found nothing above Low; its three findings about what the tests can detect are fixed in eda8143, so the test hook now copies each input into a buffer with continuation bytes behind it and passes NULL for empty input, and what remains is under Accepted limitations.
https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Generated by Claude Code