Files
sqlite/ext/session/sessioncorrupt.test
dan 9902ebadb8 Improve detection of corrupt changesets in session module function sqlite3changeset_next().
FossilOrigin-Name: 75cb77338bd7ed2d347c326b9fb4410543eeed59fc3c6cbed08316b0443fcddd
2026-10-26 08:23:03 +00:00

82 lines
2.4 KiB
Plaintext
Executable File

# 2026 August 17
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source [file join [file dirname [info script]] session_common.tcl]
source $testdir/tester.tcl
ifcapable !session {finish_test; return}
set testprefix sessioncorrupt
set C [db one {SELECT unhex('
5402 0100 7400 1700 0100 0000 0000 0000
0103 036f 6c64 0003 036e 6577 5440 0100
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 7400
1700 0100 0000 0000 0000 0100 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0001 0000 0000 0000
0002
', char(0x20,0x0a,0x0d))}]
do_test 1.0 { string length $C } 242
do_execsql_test 1.1 {
CREATE TABLE t(id INTEGER PRIMARY KEY, v TEXT);
INSERT INTO t VALUES(1, 'old');
}
proc xConflict {args} { return "OMIT" }
do_test 1.2 {
sqlite3changeset_apply db $C xConflict
} {}
#-------------------------------------------------------------------------
# An UPDATE change with an undefined old.* PK value is corrupt. Even if
# it follows an UPDATE that uses the same cached UPDATE statement.
#
reset_db
do_execsql_test 2.0 {
CREATE TABLE x(a INTEGER PRIMARY KEY, b TEXT, c TEXT);
INSERT INTO x VALUES(1, 'same', 'one'), (2, 'same', 'two');
}
set C [db one {SELECT unhex(
'5403010000' || hex('x') || '00' ||
'1700' || '010000000000000002' || '0304' || hex('same') || '00' ||
'00' || '0304' || hex('same') || '00' ||
'1700' || '00' || '0304' || hex('same') || '00' ||
'00' || '0309' || hex('second-ok') || '00'
)}]
do_test 2.1 {
list [catch { sqlite3changeset_apply db $C xConflict } msg] $msg
} {1 SQLITE_CORRUPT}
do_execsql_test 2.2 {
SELECT * FROM x
} {1 same one 2 same two}
finish_test