Skip to content

feat: Check dictionary indices, 64-bit lengths and self-binding of Arrow parameters - #867

Draft
krlmlr wants to merge 11 commits into
claude/arrow-bind-streamfrom
claude/arrow-param-checks
Draft

krlmlr wants to merge 11 commits into
claude/arrow-bind-streamfrom
claude/arrow-param-checks

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Pull request 12 of the Arrow rework plan. It stacks on #866 (bind the rows of an Arrow stream to a statement), which stacks on #865, #864, #863, #862, #861, #860, #859, #857, #856, #855, #830 and #850. It picks up what #866 left to it: dictionaries, 64-bit lengths and self-binding.

What changes

All of it is behind the internal bind_arrow_stream() of #866; no DBI method calls it yet, and the default dbBind() path is unchanged.

Dictionaries. A dictionary-encoded column, such as a factor of a data frame converted by nanoarrow, binds the value its index points to, for every value type that #866 binds on its own (text, blobs, integers, reals, times and so on, also their large variants), with indices of any integer type from int8 to uint64. A null index and a null value of the dictionary bind NULL; unused levels don't matter. The index is checked also for a dictionary of the null type, whose values all bind NULL. Validation of an array doesn't look at the indices, so each index is checked at its row: one that is negative or beyond the dictionary fails with "Can't bind the dictionary index 2 of parameter 1 in row 2, out of range for 2 values." (a uint64 index shows its unsigned value) before anything is read. A dictionary of values that can't be bound fails before any row runs with the type error of #866, now naming the whole dictionary type. The slicing of #866 carries over: the index array and the dictionary each add their own offset.

Offsets and lengths. nanoarrow's default validation, which ArrowArrayViewSetArray() runs on each array, checks only the first and the last offset of a string or binary array. Each value of utf8, large utf8, binary and large binary (also as dictionary values) now has its own two offsets checked before it is read: offsets that are negative, decreasing or beyond the data fail with "Invalid Arrow parameters: the offsets of parameter 1 in row 2 point outside its data." A value longer than the connection's SQLITE_LIMIT_LENGTH (by default SQLITE_MAX_LENGTH, which src/Makevars sets to 2147483647 bytes) is refused by sqlite3_bind_text64() or sqlite3_bind_blob64() before its data is read, and fails through the shared check_bind() of dbBind(), with its message and state: "Can't bind parameter 2 in row 1: string or blob too big." Sizes are 64-bit throughout, so a large value isn't truncated into a small one. At the default limit only large utf8 and large binary values can exceed it, since 32-bit offsets can't; a limit lowered with sqlite3_limit() applies to all four types. Whether that message should also name the size and the limit is an open question. The check of the offsets costs two loads and a few comparisons per value, full validation through ArrowArrayViewValidate() would also have covered dictionary indices, but it walks every chunk's dictionary again and reports neither the parameter nor the row. Rows are counted across the arrays of the stream, from 1, null struct rows included.

Self-binding. Binding a result to an Arrow stream of RSQLite that reads the same result, from this execution or an earlier one, fails up front with "Can't bind a result to an Arrow stream of its own rows." A chain of results whose parameters read each other's streams, which would recurse into the busy guard or leave the results holding each other, fails with "Can't bind a result to an Arrow stream of a result whose parameters read the rows of this one." DbResult::check_arrow_params() follows the chain: from the stream to the result it reads (a new arrow_stream_result() recognizes RSQLite's streams by their release callback), then to the Arrow stream that result is bound to, and so on, with a set of visited results. bind_arrow_stream() calls it through a new result_check_arrow_params() before reading the schema, since the schema of a stream of RSQLite fetches the first chunk; DbResult::bind_arrow() calls it again. A refused stream is neither read nor taken over, and the result keeps its previous bind. Before, a result bound to its own stream failed only at the first row, through #864's check of the execution, after the schema had fetched a chunk. A stream that has ended no longer reads its result, so it doesn't count as a link: binding the first result of a chain to the stream at its end is allowed and runs once the first stream has ended, because the rows that result would read are already in the chunks the next result holds, and nothing reads the first result again. Reading the schemas along a chain fetches ahead, so a chain of five results over three rows in chunks of one row is already in that state, and the first result then reads the chain's rows without recursion.

Test hook. A new internal connection_limit_length(con, n) sets SQLITE_LIMIT_LENGTH and returns the previous limit, so that the tests use 31-byte values instead of gigabytes. SQLite doesn't go below 30 bytes.

Deliberately left out

  • A stream implemented in R, or any other wrapper, that reads a stream of RSQLite hides the chain from the check: such a cycle still fails at its first row through the busy guard or feat: Read a result as a lazy Arrow array stream #864's check of the execution, as before.
  • The C data interface carries no buffer sizes, so the last offset of a string or binary array gives the size of its data. A producer whose last offset lies beyond its data buffer is still trusted; nothing on the consumer side can check that.
  • The uint64 message of feat: Bind the rows of an Arrow stream to a statement #866 names the parameter but not the row; it is unchanged here.
  • Requested types: pull requests 13 and 14. dbBindArrow() and the other DBI methods: pull request 17.

Tests

tests/testthat/test-arrow-bind-checks.R, through nanoarrow, with helpers in helper-arrow.R that build dictionaries and string arrays by hand, without validation:

  • a factor with NA and an unused level; dictionaries with every index type from int8 to uint64 over utf8, int32, binary and large utf8 values, with null indices and null values; a sliced dictionary array over a sliced dictionary
  • indices out of range at the second row (too large, negative, 255 in uint8 and 2^64 − 1 in uint64), raised by the bind of an INSERT after the first row
  • with the length limit lowered to 30 bytes, 31-byte values of utf8, large utf8, binary, large binary and a dictionary fail at their row with SQLite's "string or blob too big", after the first row; with the default limit, a large binary claiming 3e9 bytes over a one-byte buffer fails before its data is read; an index out of range in a later array of the stream names its row counted across arrays
  • negative, decreasing and out-of-range middle offsets for all four string and binary types fail at their row
  • a dictionary of the null type with an index out of range, which fails like the others
  • a result bound to its own stream, which is left unread; a cycle of two and of three results on separate connections, after which the stream still reads all rows
  • the first result of a chain of five bound to the stream at its end once the first stream has ended, which is allowed and reads the right rows

test-arrow-bind.R keeps its test of types that can't be bound, with a date64 column in place of the factor. Every test_that() block of both files passes on its own after load_all(). devtools::test() with NOT_CRAN=true passes except five expectations in test-dbBind.R from #868, which wait on the question on the state after a failed dbBind(). valgrind (--leak-check=full) reports no errors and nothing lost for test-arrow-bind-checks.R and test-arrow-bind.R; an AddressSanitizer and UBSan build reports nothing from the new code (only the known memcpy(…, NULL, 0) in fetch_blob() noted on #866).

https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn (merge of 3.54.1: https://claude.ai/code/session_01Hr1rd8MVXyvU7qoMeruD1R)


Generated by Claude Code

…row parameters

`bind_arrow_stream()` binds a dictionary, such as a factor,
by the values its indices point to, with indices of any integer type,
for every value type that binds on its own.
A null index or a null value binds NULL,
an index out of range fails with its parameter and row.

The offsets of each string or binary value are checked,
since validation checks only the first and the last one,
so that negative, decreasing or out-of-range offsets fail
rather than read out of bounds.
A value beyond SQLite's length limit fails with its size, parameter and row
before its data is read.
`connection_limit_length()` lowers the limit for the tests.

A stream of RSQLite that reads the result it would be bound to,
directly or through the parameters of other results,
fails up front, before its schema reads any rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
@krlmlr
krlmlr added this pull request to stack #851 November 13, 2026 00:11
krlmlr and others added 2 commits November 13, 2026 00:18
The CI's auto-update regenerated `src/SqliteParamSource.dd` and `src/cpp11.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 at 944a0be
and keeps the auto-update's formatting of `src/SqliteParamSource.cpp`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn

krlmlr commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Review of this pull request at 944a0be, by a Claude Code reviewer with clean context that read the descriptions of #867 and #866, the diff 0f7e7934..944a0bea with the code around it (SqliteParamSource.cpp, SqliteArrowStream.cpp, DbResult.cpp, nanoarrow 0.9.0's validation) and the tests. It built the pull request and its base into separate libraries, plus an AddressSanitizer and UBSan build, ran the tests and its own reproducers, and posted nothing on GitHub itself.

What was run

  • test-arrow-bind-checks.R and test-arrow-bind.R against both builds: all 16 blocks pass on the PR; on the base, the new file fails as expected (dictionaries, offsets, limit and cycle tests) and test-arrow-bind.R passes.
  • Each of the 16 changed or added test_that() blocks on its own after pkgload::load_all(): all pass.
  • devtools::test() with NOT_CRAN=true: only the three known test-httpvfs.R errors (test: Run the HTTP VFS tests for real, and make their errors fail the check #832, testthat hides a test's error when the test records another result after it #837); DBItest passes.
  • Under ASan+UBSan and under valgrind (--leak-check=full): both test files and four reproducers covering dictionaries, offsets and lengths, cycles and an ended chain. ASan reports nothing. UBSan reports only the known memcpy(…, NULL, 0) at SqliteColumnDataSource.cpp:92. valgrind reports 0 errors and 0 bytes definitely, indirectly or possibly lost. A positive control, with a last offset beyond a 2000-byte buffer, makes ASan report a heap-buffer-overflow, so the instrumentation works.
  • A benchmark binding 2e6 rows of two utf8 columns to the base and the PR, three times each.
  • cpp11::cpp_register() leaves the registration files unchanged. No src/*.dd file is touched. R CMD check was not run, because DESCRIPTION, NAMESPACE and the documentation are unchanged.

What holds

  • Dictionaries: all 8 index types × 21 value types (every type feat: Bind the rows of an Arrow stream to a statement #866 binds, including large utf8 and binary) bind the right values. Null indices and null values bind NULL. A sliced index array over a sliced dictionary works for all four string and binary types. Dictionaries that change between chunks work, and an out-of-range index in the third chunk reports "row 5", counted across the stream. Extreme indices (int8 −128 and 127, 255, −32768, 65535, INT32_MIN, UINT32_MAX, INT64_MIN and INT64_MAX, uint64 2^63 and 2^64−1) and index == length fail with the right value. An empty dictionary takes null indices and refuses a valid one. A dictionary of list, date64 or another dictionary fails up front with the whole type named, and leaves the stream readable.
  • Offsets: negative, decreasing and past-the-end middle offsets (also −2^31+1) fail at their row for all four types. They also fail inside a slice, while a bad offset outside the slice is ignored, and they fail as dictionary values. NULL offset or data buffers are refused by nanoarrow. 2^62 and 2^63−1024 large offsets fail on the length limit without being read. end - start can't overflow after the checks.
  • Length limit: with the limit at 30, a 30-byte value binds and a 31-byte one fails with its size, parameter and row. An INSERT of a 29- or 30-byte value then fails at the step with SQLite's own "string or blob too big", because the record has overhead, as with dbBind().
  • Cycles: own stream, a stream of an earlier execution, and cycles of 2, 3 and 200 results are refused, the 200-result cycle in 2 ms. Binding to the end of a non-cyclic 200-result chain reads all 1000 rows. A cycle through a cleared, disconnected and garbage-collected middle result is still refused, with no ASan or valgrind report. In a chain of 5 results, the first stream has ended before the binds return, so binding the first result to the last stream is allowed and returns the right rows (7, 8, 9), which confirms the "ended stream is no link" rule.
  • connection_limit_length() is not exported. It rejects a NULL pointer and a disconnected connection ("disconnected"), treats NA or a negative value as a query, and SQLite clamps 0 to 30. It changes only the connection it is given.
  • Performance: binding 4e6 values without steps took 0.30–0.33 s on the PR against 0.29–0.32 s on the base (medians), within run-to-run noise. INSERT took 0.65 against 0.60 s.

High

None.

Medium

None.

Low

  1. The description gives the wrong default length limit: RSQLite compiles SQLite with a limit of 2147483647 bytes, not 1e9.

    -DSQLITE_MAX_LENGTH=2147483647 \
    sets -DSQLITE_MAX_LENGTH=2147483647. connection_limit_length(con@ptr, -1L) returns 2147483647, and the 3e9-byte value fails with "… beyond SQLite's length limit of 2147483647 bytes.", not the "1000000000 bytes" the description quotes (Confirmed). As a consequence, no utf8 or binary value with 32-bit offsets can exceed the default limit. The description also says the check costs "two loads and two comparisons", but each value also calls sqlite3_db_handle() and sqlite3_limit() (
    const int64_t limit =
    sqlite3_limit(sqlite3_db_handle(stmt), SQLITE_LIMIT_LENGTH, -1);
    ). The measured cost is within noise. Suggested fix: correct the limit and the example message in the description, and optionally read the limit once per row or once per array.

  2. A dictionary whose values have the null type skips the index check, so an index of 99 into a one-value dictionary binds NULL silently.

    if (type.type == NANOARROW_TYPE_NA || ArrowArrayViewIsNull(values, row)) {
    return;
    }
    // A dictionary binds the value of its index, or NULL for a null value.
    // Validation of the array doesn't look at the indices.
    if (values->dictionary != NULL) {
    returns on NANOARROW_TYPE_NA before the dictionary branch, and type holds the value type there (Confirmed: dict_array(c(0, 99), <null array of 1>) binds two NULLs). Nothing is read out of bounds, but the data is invalid and unlike every other value type. Suggested fix: test type.type == NANOARROW_TYPE_NA after the index check, or accept this and say so in a comment.

  3. The case the description calls allowed, binding to the end of a chain whose first stream has ended, has no test.

    test_that("results whose parameters read each other's rows fail up front", {
    skip_if_not_installed("nanoarrow")
    # One connection for each, as a connection has one open result
    env <- environment()
    sql <- c("SELECT :c * 10 AS a", "SELECT :a * 10 AS b", "SELECT :b * 10 AS c")
    results <- lapply(sql, function(sql) {
    local_result(local_con(envir = env), sql, envir = env)
    })
    dbBind(results[[1]], list(c = 1:3))
    bind_arrow_stream(results[[2]], read_arrow_stream(results[[1]], 1))
    # Of two results
    stream <- read_arrow_stream(results[[2]], 1)
    expect_snapshot(error = TRUE, bind_arrow_stream(results[[1]], stream))
    # Of three results
    bind_arrow_stream(results[[3]], stream)
    stream <- read_arrow_stream(results[[3]], 1)
    expect_snapshot(error = TRUE, bind_arrow_stream(results[[1]], stream))
    expect_equal(nanoarrow::convert_array_stream(stream), data.frame(c = c(1000, 2000, 3000)))
    })
    only covers refusals. A chain of five results with three rows and 1-row chunks already reaches this state, because the schema reads fetch ahead. The bind is then allowed and fetches 7, 8, 9 (Confirmed). This is also why a 5-result cycle over three rows is not refused, which is correct but surprising without a test. Suggested fix: add a test that the first result binds to the last stream of such a chain and fetches its rows.

  4. Pre-existing, not from this PR: the default dbBind() path ignores the result of sqlite3_bind_text() and sqlite3_bind_blob(), so a value beyond the length limit binds NULL silently, while the Arrow path now fails.

    sqlite3_bind_text(stmt, pos, CHAR(value), -1, SQLITE_TRANSIENT);
    }
    } else if (TYPEOF(value_) == VECSXP) {
    SEXP value = VECTOR_ELT(value_, i);
    if (TYPEOF(value) == NILSXP) {
    sqlite3_bind_null(stmt, pos);
    } else if (TYPEOF(value) == RAWSXP) {
    sqlite3_bind_blob(
    stmt,
    pos,
    RAW(value),
    Rf_length(value),
    SQLITE_TRANSIENT
    );
    . With the limit at 30, dbGetQuery(con, "SELECT length(?), typeof(?1)", params = list(strrep("y", 31))) returns NA and null, also for a blob (Confirmed). Suggested fix: a separate issue to check these return codes in SqliteListParamSource, so that both paths agree.


Generated by Claude Code

…ded chain

A dictionary whose values are of the null type skipped the check of its indices,
so an index out of range bound NULL without an error;
the index is now checked before a null-type value binds NULL.
A test binds the first result of a chain to the stream at its end
once the first stream has ended, which is allowed and reads the right rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn

krlmlr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by this newer copy.

The clean review of 944a0be found nothing above Low: dictionaries of every index and value type, invalid offsets and lengths, and cycles of up to 200 results behave as described; AddressSanitizer and valgrind are clean on the tests and on reproducers for each; binding a large utf8 stream shows no slowdown beyond noise; devtools::test() and DBItest show only the three known test-httpvfs.R errors. Three of its four Lows are fixed in e8f66d9 (the length limit stated correctly, the index check for null-type dictionary values, and a test for a chain whose first stream has ended). These remain:

  • src/SqliteParamSource.cpp#L442: the offsets of each value are checked against the array's last offset, the only data size the Arrow C interface carries, so a producer whose last offset points past its real buffer is still read out of bounds; no consumer can detect that. The description lists it. Relevance: low; reviewer's confidence: high (recorded).
  • src/DbResult.cpp#L160: the self-binding check follows RSQLite's own streams, recognized by their release callback (src/SqliteArrowStream.cpp#L264); a stream implemented in R that wraps one hides the link, and such a cycle still fails at the first row through the busy guard or feat: Read a result as a lazy Arrow array stream #864's execution check, as before. A chain whose first stream has ended is allowed and binds the right rows. Relevance: low; reviewer's confidence: high (recorded).
  • src/SqliteParamSource.cpp#L447: each text or blob value reads the connection's length limit, within benchmark noise. Relevance: low; reviewer's confidence: high.
  • On main and unchanged here, the data-frame path of dbBind() ignores the return codes of sqlite3_bind_text() and sqlite3_bind_blob() (src/SqliteResultImpl.cpp#L276), so a value over the length limit binds NULL silently there, while the Arrow path fails. A separate pull request from main is proposed in the coordination pull request. Relevance: medium; reviewer's confidence: high.

Generated by Claude Code

krlmlr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Question: guard against an Arrow producer whose last offset points past its data buffer?

The offsets of each text or binary value are checked against the array's last offset (src/SqliteParamSource.cpp#L439-L444), the only data size that the Arrow C data interface carries. A producer whose last offset points past its real buffer is therefore still read out of bounds, and no consumer of the interface can detect that, since it carries no buffer sizes. The code comment above value_bytes() records this. No reproducer: it needs a producer that exports such a malformed array.

  • Accept it (recommended): such an array is a bug of its producer, for every consumer of the interface
  • Also say in the documentation of dbBindArrow(), when pull request 17 adds it, that the parameters must be valid Arrow arrays

If nobody decides, nothing changes, and the code comment stays the record.


Generated by Claude Code

krlmlr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Question: detect a self-binding cycle through a stream implemented in R as well?

The check for self-binding follows RSQLite's own streams (src/DbResult.cpp#L152-L160), which it recognizes by their release callback (src/SqliteArrowStream.cpp#L264-L269). A stream implemented in R that wraps one hides the link: such a cycle isn't refused up front, and fails at the first row through #830's busy guard or #864's check of the execution, as before this pull request. A chain whose first stream has ended is allowed and binds the right rows. No reproducer: it needs a stream implemented in R, which nanoarrow doesn't offer.

  • Accept it (recommended): the cycle still fails cleanly, only with a less specific message
  • Detect the cycle at run time, when a stream's get_next() reaches a result that is binding, and report it as self-binding

If nobody decides, such a cycle keeps failing at the first row.


Generated by Claude Code

krlmlr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Question: read SQLite's length limit once per bind instead of once per text or blob value?

Each text or blob value reads the connection's length limit with sqlite3_limit() (src/SqliteParamSource.cpp#L446-L447). In the clean review, binding a large utf8 stream showed no slowdown beyond benchmark noise. No reproducer: the cost is a function call per value.

  • Accept it (recommended): the cost is within noise, and the value always reflects the connection's current limit
  • Read the limit once when the parameter source is created

If nobody decides, the limit is read per value.


Generated by Claude Code

krlmlr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by the copy of 2026-11-29.

The clean review of 944a0be found nothing above Low: dictionaries of every index and value type, invalid offsets and lengths, and cycles of up to 200 results behave as described; AddressSanitizer and valgrind are clean on the tests and on reproducers for each; binding a large utf8 stream shows no slowdown beyond noise; devtools::test() and DBItest show only the three known test-httpvfs.R errors. Three of its four Lows are fixed in e8f66d9 (the length limit stated correctly, the index check for null-type dictionary values, and a test for a chain whose first stream has ended). Since then, the branch has only merged its base (d63d63d). These remain:

  • src/SqliteParamSource.cpp#L439-L444: offsets are checked against the array's last offset, the only data size the Arrow C data interface carries, so a producer whose last offset points past its real buffer is still read out of bounds (question). Relevance: low; reviewer's confidence: high (recorded).
  • src/DbResult.cpp#L152-L160: the self-binding check follows only RSQLite's own streams, so a cycle through a stream implemented in R fails at the first row instead, as before (question). Relevance: low; reviewer's confidence: high (recorded).
  • src/SqliteParamSource.cpp#L446-L447: each text or blob value reads the connection's length limit, within benchmark noise (question). Relevance: low; reviewer's confidence: high.

Found here, but also on main:


Generated by Claude Code

…ind check

A string or binary value beyond SQLite's length limit is no longer checked up front:
sqlite3_bind_text64() and sqlite3_bind_blob64() refuse it before they read its data,
also for a 64-bit length,
and the refusal fails through check_bind() with a SqliteBindError,
with the message and the state of dbBind().
The checks of dictionary indices and offsets name the row
from the parameter sets counted over all arrays of the stream, as check_bind() does,
and a test pins that row for an index out of range in a later array.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd8MVXyvU7qoMeruD1R

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Question: should a value beyond SQLite's length limit name its size and the limit, for Arrow and list parameters alike?

Merging #866 up into this pull request (5516cc3) broke #866's test "a value SQLite refuses fails with the message and state of dbBind()": this pull request checked the length of an Arrow string or binary value up front and threw its own plain error, "Can't bind the value of N bytes … beyond SQLite's length limit of L bytes.", while #866, after main's #868 was merged up, sends every refused bind of a stream through the shared check_bind() that dbBind() uses for list parameters. 8e6fe0d removes the up-front check, since sqlite3_bind_text64() and sqlite3_bind_blob64() refuse such a value, also with a 64-bit length, before they read its data (comment). Both paths now fail with the same state and the same message, "Can't bind parameter 2 in row 1: string or blob too big.", which is also what RSQLite 3.54.1 gives for a list parameter. The message no longer says how large the value was or what the limit is, and the five snapshots of this pull request changed with it.

Adding the size and the limit to check_bind() when SQLite returns SQLITE_TOOBIG, for example "… string or blob too big (3000000000 bytes, limit 1000000000).", keeps one code path and gives the detail on both; it costs about ten lines, a size argument to check_bind() from the list and Arrow sources, and new snapshots in test-dbBind.R and here, and it changes 3.54.1's message for list parameters by appending to it. Restoring the up-front check for Arrow only brings the detail back on one path and breaks #866's test that the two paths agree. The question on reading the length limit once per bind is moot with either of the first two options, since no code reads the limit any more.

  • Name the size and the limit in check_bind() on SQLITE_TOOBIG, for list and Arrow parameters alike (recommended: one path, and the detail users need to act)
  • Keep SQLite's message as it is now, the same for both paths
  • Restore this pull request's own up-front check for Arrow values, and relax feat: Bind the rows of an Arrow stream to a statement #866's test to the state only

Kirill decides. If nobody decides, the message stays as it is now, the same for both paths.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

The smoke test on 8e6fe0de fails with FAIL 5 | PASS 12076, all five in tests/testthat/test-dbBind.R (lines 379, 380, 401, 402 and 420): the expectations that #868 added for the state after a failed dbBind(), which disagree with #830's handling two layers down. They fail the same way on every layer from #830 up, since main (3.54.1) was merged up the stack today. The fix waits on the maintainer's answer to the question on that state; nothing in this pull request causes it.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

The clean review of 944a0be found nothing above Low: dictionaries of every index and value type, invalid offsets and lengths, and cycles of up to 200 results behave as described; AddressSanitizer and valgrind are clean on the tests and on reproducers for each; binding a large utf8 stream shows no slowdown beyond noise; devtools::test() and DBItest show only the three known test-httpvfs.R errors. Three of its four Lows are fixed in e8f66d9 (the length limit stated correctly, the index check for null-type dictionary values, and a test for a chain whose first stream has ended). Since then, the branch has only merged its base (d63d63d).

The clean review of 2026-11-29, after main (3.54.1) was merged up the stack, read this pull request at 8e6fe0d and found nothing above Low here; its description is updated, since the merge replaced this pull request's own length check by SQLite's refusal through the shared check_bind() (question on the message), which also makes the item on reading the length limit per value obsolete. From #830 up, five expectations in test-dbBind.R from #868 fail until the question on the state after a failed dbBind() is answered. This copy replaces the copy of 2026-11-13. These remain:

  • src/SqliteParamSource.cpp#L439-L444: offsets are checked against the array's last offset, the only data size the Arrow C data interface carries, so a producer whose last offset points past its real buffer is still read out of bounds (question). Relevance: low; reviewer's confidence: high (recorded).
  • src/DbResult.cpp#L152-L160: the self-binding check follows only RSQLite's own streams, so a cycle through a stream implemented in R fails at the first row instead, as before (question). Relevance: low; reviewer's confidence: high (recorded).
  • src/SqliteParamSource.cpp#L436-L438: a value beyond SQLite's length limit fails with SQLite's "string or blob too big", which names the parameter and the row but neither the size nor the limit (question). Relevance: low.

Generated by Claude Code

@krlmlr
krlmlr marked this pull request as draft November 30, 2026 23:27
krlmlr pushed a commit that referenced this pull request Dec 1, 2026
…nt outside the data

The full validation of each array refuses offsets of a utf8 or binary value
that are negative, decreasing or beyond the data,
with a message that names neither the parameter nor the row
and counts within the array from 0.
When it fails, the rows of the array are now checked for such offsets,
also of the value that a dictionary index points to,
and the first one fails like a value that can't be bound,
with the parameter, its name and the row counted across the stream.
The check runs only after the validation has failed,
so a valid array costs nothing more.

Text is now bound before it is checked for NUL bytes and UTF-8,
so that a value beyond SQLite's length limit fails with SQLITE_TOOBIG
before its data is read, as blobs already did.

Ported from #867.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4

This branch has not been deployed

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

2 participants