Repository navigation
fix(sof): cap SQLite value size for SQL Queries at 128 MiB - #3296
Open
angela-helios wants to merge 2 commits into
Open
angela-helios wants to merge 2 commits into
angela-helios wants to merge 2 commits into
Conversation
The SQLite connections that run caller SQL kept the default SQLITE_LIMIT_LENGTH of 1,000,000,000 bytes, so zeroblob, randomblob or printf could build a value of close to 1 GB from a small $sql-run request. The in-memory engine now sets the limit when it opens its database. The primary SQLite path lowers it for the statement and restores the pooled connection's previous value with the other per-statement hooks. A value past the limit fails with "string or blob too big", reported as 422. Closes #3186
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This branch has not been deployed
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.
Closes #3186
Behaviour change to review
$sql-run, SQL Views) on the SQLite, MongoDB and S3 backends that builds or reads a single string, BLOB or row larger than 128 MiB now fails with 422SQLite error: string or blob too big. Before, SQLite's default of 1,000,000,000 bytes applied.helios_sof::sqlquery::MAX_SQL_VALUE_BYTES), not a setting. 128 MiB matches the default request body limit, so a resource the server accepts by default can still be read by a SQL Query. A deployment that raised the body limit and stored a resource larger than 128 MiB will see SQL Queries over that row fail on SQLite.Summary
The SQLite connections that run caller SQL kept SQLite's default
SQLITE_LIMIT_LENGTH, sozeroblob,randombloborprintfcould build a value of close to 1 GB from a small request.SQLITE_LIMIT_LENGTHto 128 MiB when it opens its per-request database.limitsfeature is enabled inhelios-sofandhelios-persistence.SqlQueryError::Sqlitemapping (422).Not in this change:
SQLITE_LIMIT_SQL_LENGTH,SQLITE_LIMIT_EXPR_DEPTH,SQLITE_LIMIT_LIKE_PATTERN_LENGTH, and PostgreSQL.Tests
crates/sof/src/sqlquery/engine.rs:zeroblob(900000000),randomblob(200000000),printf('%.*c', 900000000, 'x')and values one byte past the limit fail with SQLite'sTooBig; 1 MB values are still returned.crates/persistence/src/sof/sqlite_native.rs: the same on a pooled connection, and the connection has its original limit back after a successful statement, a too-big statement and a refused statement.Results:
cargo test -p helios-sof --lib: 420 passed.cargo test -p helios-persistence --lib: 2081 passed.cargo test -p helios-persistence --test sof_sqlite_runner native_sql_query: 1 passed.These ran on a branch that also carried fourteen other pending fixes, so the suites were verified in combination, not on this branch alone.