Repository navigation
Conversation
A blob that turns up in a column typed as text was read as a C string, so it was silently cut at the first NUL byte, and bytes that are not UTF-8 were passed on as an R string marked UTF-8. The bytes are now checked: well-formed UTF-8 without NUL bytes becomes the full string, anything else becomes NA with one warning per column that counts the values. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01EpBkzNMeuMBGy4nxTafYH6
|
Review of this PR at 65a0c07, by a Claude Code reviewer with clean context that read the diff against Checked and found sound: the UTF-8 validator in Generated by Claude Code |
|
Does Did the reviewer find no limitations? |
|
No, it doesn't need to be. It is a header only so that this pull request and #795, whose Arrow path validates text with the same function, can each add the identical On limitations: the only review of this pull request is the one above, from 2026-09-27 at 65a0c07. It read the diff and ran Generated by Claude Code |
|
Review of this PR at 867813e, by a Claude Code reviewer with clean context that read the full diff against Line numbers refer to commit 867813e. "Confirmed" means reproduced by running code; "by reading" means not run. What holds. All of the following are Confirmed.
HighNo findings. MediumM1.
Confirmed with: con <- dbConnect(SQLite())
dbExecute(con, "CREATE TABLE t (x)")
dbExecute(con, "INSERT INTO t VALUES ('a'), (X'00ff'), (X'6162')")
res <- dbSendQuery(con, "SELECT x FROM t")
dbFetch(res, 1)
dbColumnInfo(res) # or dbFetch(res, 0)
dbFetch(res)$xThe peek warns "1 blob value is not valid UTF-8 text, NA is returned" although it returns no rows. The last call then returns Suggested fix: for a blob, do not call LowL1. In a UTF-16 database the blob bytes are transcoded before validation. Confirmed. With L2. A column name is used as a Confirmed. L3. The warning text for a non-ASCII column name is passed as native-encoding bytes. Confirmed. The message is correct in a UTF-8 locale, though the condition message is not marked UTF-8. Under L4. The peek counts and warns for a row it does not return. Confirmed, see M1. L5. Blobs that hold a NUL-terminated C string now become Confirmed. L6. Test coverage is narrower than the claims. By reading, plus the run on
The values Memory safety and the counter. No findings. The validator never reads past Generated by Claude Code |
Superseded: Accepted limitationsSuperseded by this comment. The clean review of 867813e8 found one Medium and six Low issues. The Medium (a peek with
Generated by Claude Code |
A blob in a text column is now read with `sqlite3_column_blob()` and `sqlite3_column_bytes()`, then checked and turned into a string from those bytes. `sqlite3_column_text()` changed the value to text in place, so after a peek with `dbFetch(res, n = 0)` or `dbColumnInfo(res)` the next fetch of the same row returned it unchecked, as before this pull request. In a UTF-16 database it also transcoded the blob before the check, so `X'6162'` came back as `"扡"`. An empty blob still gives `""`. A blob holding a NUL byte, such as a NUL-terminated C string, now becomes `NA` with a warning, where it was truncated at the NUL byte before. Text values are read as before and are not checked. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
A zero-row peek with `dbFetch(res, n = 0)` or `dbColumnInfo(res)` reads the next row without returning it. It no longer warns about a blob in that row that is not valid UTF-8, so each value is reported once, by the fetch that returns it. The warning about mixed types in a column is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The warnings about mixed types and about blobs that are not valid UTF-8 passed their message, which holds the column name, to `cpp11::warning()` as the format. A name such as `x%s%d` printed garbage in its place, reading arguments that did not exist. Both now pass the message through `"%s"`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
The new tests cover the malformed UTF-8 forms (overlong, surrogate, beyond U+10FFFF, truncated) and a NUL-terminated C string, an empty blob, a fetch in chunks where a later chunk holds only blobs, a peek with `dbFetch(res, n = 0)` or `dbColumnInfo(res)` between two chunks, a UTF-16 database, and a column name that holds `%s%d`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
|
Review of the fixes at d26413c (the four commits after 867813e), by a Claude Code reviewer with clean context that read the pull request description, the review of 867813e8, the accepted limitations, the diff The earlier findings.
What else holds. Everything below is Confirmed unless marked otherwise.
HighNo findings. MediumNo findings. LowL7. The con <- dbConnect(SQLite())
dbGetQuery(con, "PRAGMA hard_heap_limit = 50000000")
q <- "SELECT CASE WHEN column1 = 1 THEN 'a' ELSE zeroblob(100000000) END AS x FROM (VALUES (1), (2), (1))"
dbGetQuery(con, q) # Error: out of memory (main: segfault)
res <- dbSendQuery(con, q)
dbFetch(res, 1) # "a"
dbFetch(res, 0) # zero rows, no error
dbFetch(res) # Error: out of memorySuggested fix: the behavior can stay. Extend the comment, for example to "An empty blob, or out of memory while expanding a zeroblob(): the next sqlite3_step() then fails with SQLITE_NOMEM", so that a future code path that reads a row without stepping afterwards does not turn an allocation failure into L8. The description and the accepted limitations are behind the code in a few places. By reading, except where marked. The accepted limitations link to lines of 867813e; at d26413c the rule that turns a blob with a NUL byte into Outside this pull requestThese are not findings against this change. Each is the same kind of defect as one this pull request fixes, found while checking it.
Generated by Claude Code |
Superseded: Accepted limitationsSuperseded by this comment. The clean review of 867813e8 found one Medium and six Low issues; the Medium and four of the Low ones are fixed in d26413c, which the second clean review confirmed without High or Medium findings. Its comment on the out-of-memory branch of
Generated by Claude Code |
…g()` `sqlite3_column_blob()` also returns `NULL` when it runs out of memory while expanding a `zeroblob()`, not only for an empty blob. The comment now says so, and that returning `""` is safe only because the next `sqlite3_step()` then fails with `SQLITE_NOMEM`. No change in behavior. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
|
The checks for BLOBs look like an edge case, whereas the lax handling of text columns feels like much more commonplace in practice. This is a breaking change so needs to be behind an option, defaulting to the current behavior. Reimplement from scratch in a stacked PR: first the UTF-8 infrastructure (that also seems to be needed for the Arrow PRs), then the fixes. |
|
Reimplemented from Generated by Claude Code |
Accepted limitationsThe clean review of 867813e8 found one Medium and six Low issues; the Medium and four of the Low ones are fixed in d26413c, which the second clean review confirmed without High or Medium findings. Its comment on the out-of-memory branch of
Generated by Claude Code |
|
#845 (the UTF-8 validator) and #846 ( Generated by Claude Code |
|
Closing as superseded: #845 (the UTF-8 validator) and #846 ( Generated by Claude Code |
When a column is typed as text from its first values and a blob turns up later, the blob was read with
sqlite3_column_text()as a C string: it was silently cut at the first NUL byte, and bytes that are not UTF-8 were handed to R as a string marked UTF-8. A blobX'00ff'came back as"".A blob in a text column is now read with
sqlite3_column_blob()andsqlite3_column_bytes()and validated infetch_string(). A blob that is well-formed UTF-8 without NUL bytes becomes the full string, an empty blob becomes"", and anything else becomesNA, with one warning per column and fetch that counts the replaced values, next to the existing mixed-type warning:Because
sqlite3_column_text()is never called on a blob, the value keeps its storage class. A peek withdbFetch(res, n = 0)ordbColumnInfo(res)therefore no longer switches the check off for the next fetch of the same row, and in a UTF-16 database the blob is no longer transcoded before the check (X'6162'used to come back as"扡"). The peek itself does not warn about invalid blobs; the fetch that returns the row does, so each value is reported once. Both column warnings now pass their message as an argument rather than as a format, so a column name containing%is printed as is; onmain, a column name containing%naborted R (*** %n in writable segment detected ***).Behavior change: a blob holding a NUL byte, such as a NUL-terminated C string stored with its terminator, now becomes
NAwith a warning, wheremainreturned the string up to the NUL.Text values are not checked and are read as before: text with an embedded NUL is still cut silently, and text that is not valid UTF-8 is still returned marked as UTF-8. The warning text for a non-ASCII column name is not marked as UTF-8, as in the existing mixed-type warning, and a peek still emits the mixed-type warning, so it appears twice for the same row, as on
main. The validator lives in a new headersrc/utf8.h, shared with the Arrow path of #795; whether it moves into a.cppfile is an open question on #829.The tests in
tests/testthat/test-blob.Rcover the malformed UTF-8 forms (overlong, surrogate, beyond U+10FFFF, truncated), a NUL-terminated C string, an empty blob, a fetch in chunks where a later chunk holds only blobs, a peek between two chunks, a UTF-16 database, and a column name containing%s%d.No open issue covers this. The closed #439 is the related case of text coerced to 0 in numeric columns.
A clean review of 867813e found one Medium and six Low issues. The Medium and four of the Low ones are fixed in d26413c, which a second clean review confirmed without High or Medium findings; what remains is listed under Accepted limitations.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EpBkzNMeuMBGy4nxTafYH6
https://claude.ai/code/session_01Hr1rd3gjmufoKCWVDBPCgE
Generated by Claude Code