diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ddaf7c6..b50636ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 8.20.2 (unreleased) +### Implementation changes and bug fixes +- [PR #1690](https://github.com/rqlite/rqlite/pull/1690): Check for `isTextType` in panic-proof way. + ## 8.20.2 (February 16th 2024) ### Implementation changes and bug fixes - [PR #1685](https://github.com/rqlite/rqlite/pull/1685): Rename a Proto (but not its fields). diff --git a/db/db.go b/db/db.go index 76959ee5..ee65d5f1 100644 --- a/db/db.go +++ b/db/db.go @@ -1430,8 +1430,10 @@ func normalizeRowValues(row []interface{}, types []string) ([]*command.Parameter } case []byte: if isTextType(types[i]) { - values[i].Value = &command.Parameter_S{ - S: string(val), + values[i] = &command.Parameter{ + Value: &command.Parameter_S{ + S: string(val), + }, } } else { values[i] = &command.Parameter{ diff --git a/db/db_common_test.go b/db/db_common_test.go index 5c3662d3..476ce017 100644 --- a/db/db_common_test.go +++ b/db/db_common_test.go @@ -146,6 +146,35 @@ func testSQLiteTimeTypes(t *testing.T, db *DB) { } } +func testSQLiteRandomBlob(t *testing.T, db *DB) { + _, err := db.ExecuteStringStmt("CREATE TABLE large_data (id INTEGER PRIMARY KEY, large_text TEXT)") + if err != nil { + t.Fatalf("failed to create table: %s", err.Error()) + } + _, err = db.ExecuteStringStmt(` + WITH RECURSIVE generate_large_data(id, large_text) AS ( + SELECT 1, randomblob(1) + UNION ALL + SELECT id + 1, randomblob(1) + FROM generate_large_data + WHERE id < 2 + ) + INSERT INTO large_data(id, large_text) + SELECT id, large_text FROM generate_large_data + `) + if err != nil { + t.Fatalf("failed to create table: %s", err.Error()) + } + r, err := db.QueryStringStmt("SELECT * FROM large_data LIMIT 1") + if err != nil { + t.Fatalf("failed to query master table: %s", err.Error()) + } + if !strings.Contains(asJSON(r), "large_text") { + // Just check that it doesn't panic. + t.Fatalf("unexpected results for query, expected large_text, got %s", asJSON(r)) + } +} + func testNotNULLField(t *testing.T, db *DB) { _, err := db.ExecuteStringStmt("CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT)") if err != nil { @@ -1558,6 +1587,7 @@ func Test_DatabaseCommonOperations(t *testing.T) { {"SQLiteMasterTable", testSQLiteMasterTable}, {"SQLiteTimeTypes", testSQLiteTimeTypes}, {"NotNULLField", testNotNULLField}, + {"RandomBlob", testSQLiteRandomBlob}, {"EmptyStatements", testEmptyStatements}, {"SimpleSingleStatements", testSimpleSingleStatements}, {"SimpleStatementsNumeric", testSimpleStatementsNumeric},