Fossil SCM

Update the built-in SQLite to the latest from upstream.

drh 2025-06-24 16:46 trunk
Commit 07a16b79331d8397c68ac73a19d595cb4c52fcae1f4721a84010c0e681073ef4
+1 -1
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -30933,11 +30933,11 @@
3093330933
}
3093430934
appendText(&sSelect, " AND ", 0);
3093530935
sqlite3_free(zQarg);
3093630936
}
3093730937
if( bNoSystemTabs ){
30938
- appendText(&sSelect, "name NOT LIKE 'sqlite__%%' ESCALE '_' AND ", 0);
30938
+ appendText(&sSelect, "name NOT LIKE 'sqlite__%%' ESCAPE '_' AND ", 0);
3093930939
}
3094030940
appendText(&sSelect, "sql IS NOT NULL"
3094130941
" ORDER BY snum, rowid", 0);
3094230942
if( bDebug ){
3094330943
sqlite3_fprintf(p->out, "SQL: %s;\n", sSelect.z);
3094430944
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -30933,11 +30933,11 @@
30933 }
30934 appendText(&sSelect, " AND ", 0);
30935 sqlite3_free(zQarg);
30936 }
30937 if( bNoSystemTabs ){
30938 appendText(&sSelect, "name NOT LIKE 'sqlite__%%' ESCALE '_' AND ", 0);
30939 }
30940 appendText(&sSelect, "sql IS NOT NULL"
30941 " ORDER BY snum, rowid", 0);
30942 if( bDebug ){
30943 sqlite3_fprintf(p->out, "SQL: %s;\n", sSelect.z);
30944
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -30933,11 +30933,11 @@
30933 }
30934 appendText(&sSelect, " AND ", 0);
30935 sqlite3_free(zQarg);
30936 }
30937 if( bNoSystemTabs ){
30938 appendText(&sSelect, "name NOT LIKE 'sqlite__%%' ESCAPE '_' AND ", 0);
30939 }
30940 appendText(&sSelect, "sql IS NOT NULL"
30941 " ORDER BY snum, rowid", 0);
30942 if( bDebug ){
30943 sqlite3_fprintf(p->out, "SQL: %s;\n", sSelect.z);
30944
+102 -54
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** cf61cd359e666c66b6bba4407a653c799f7f with changes in files:
21
+** 6a5701e6c7be25cba93e55438f950966e1da with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466466
** [sqlite_version()] and [sqlite_source_id()].
467467
*/
468468
#define SQLITE_VERSION "3.51.0"
469469
#define SQLITE_VERSION_NUMBER 3051000
470
-#define SQLITE_SOURCE_ID "2025-06-23 16:51:33 cf61cd359e666c66b6bba4407a653c799f7f07e1f5ee6b837ad467029c461a6a"
470
+#define SQLITE_SOURCE_ID "2025-06-24 15:58:32 6a5701e6c7be25cba93e55438f950966e1dacb32eb2b23a8acc8ac53da6f0a85"
471471
472472
/*
473473
** CAPI3REF: Run-Time Library Version Numbers
474474
** KEYWORDS: sqlite3_version sqlite3_sourceid
475475
**
@@ -4479,19 +4479,19 @@
44794479
** The application does not need to worry about freeing the result.
44804480
** However, the error string might be overwritten or deallocated by
44814481
** subsequent calls to other SQLite interface functions.)^
44824482
**
44834483
** ^The sqlite3_errstr(E) interface returns the English-language text
4484
-** that describes the [result code] E, as UTF-8, or NULL if E is not an
4484
+** that describes the [result code] E, as UTF-8, or NULL if E is not a
44854485
** result code for which a text error message is available.
44864486
** ^(Memory to hold the error message string is managed internally
44874487
** and must not be freed by the application)^.
44884488
**
44894489
** ^If the most recent error references a specific token in the input
44904490
** SQL, the sqlite3_error_offset() interface returns the byte offset
44914491
** of the start of that token. ^The byte offset returned by
4492
-** sqlite3_error_offset() assumes that the input SQL is UTF8.
4492
+** sqlite3_error_offset() assumes that the input SQL is UTF-8.
44934493
** ^If the most recent error does not reference a specific token in the input
44944494
** SQL, then the sqlite3_error_offset() function returns -1.
44954495
**
44964496
** When the serialized [threading mode] is in use, it might be the
44974497
** case that a second error occurs on a separate thread in between
@@ -4586,12 +4586,12 @@
45864586
** CAPI3REF: Run-Time Limit Categories
45874587
** KEYWORDS: {limit category} {*limit categories}
45884588
**
45894589
** These constants define various performance limits
45904590
** that can be lowered at run-time using [sqlite3_limit()].
4591
-** The synopsis of the meanings of the various limits is shown below.
4592
-** Additional information is available at [limits | Limits in SQLite].
4591
+** A concise description of these limits follows, and additional information
4592
+** is available at [limits | Limits in SQLite].
45934593
**
45944594
** <dl>
45954595
** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
45964596
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
45974597
**
@@ -4652,11 +4652,11 @@
46524652
#define SQLITE_LIMIT_WORKER_THREADS 11
46534653
46544654
/*
46554655
** CAPI3REF: Prepare Flags
46564656
**
4657
-** These constants define various flags that can be passed into
4657
+** These constants define various flags that can be passed into the
46584658
** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
46594659
** [sqlite3_prepare16_v3()] interfaces.
46604660
**
46614661
** New flags may be added in future releases of SQLite.
46624662
**
@@ -4739,11 +4739,11 @@
47394739
** statement is generated.
47404740
** If the caller knows that the supplied string is nul-terminated, then
47414741
** there is a small performance advantage to passing an nByte parameter that
47424742
** is the number of bytes in the input string <i>including</i>
47434743
** the nul-terminator.
4744
-** Note that nByte measure the length of the input in bytes, not
4744
+** Note that nByte measures the length of the input in bytes, not
47454745
** characters, even for the UTF-16 interfaces.
47464746
**
47474747
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
47484748
** past the end of the first SQL statement in zSql. These routines only
47494749
** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4873,11 +4873,11 @@
48734873
** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
48744874
** will return "SELECT 2345,NULL".)^
48754875
**
48764876
** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
48774877
** is available to hold the result, or if the result would exceed the
4878
-** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4878
+** maximum string length determined by the [SQLITE_LIMIT_LENGTH].
48794879
**
48804880
** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
48814881
** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
48824882
** option causes sqlite3_expanded_sql() to always return NULL.
48834883
**
@@ -5061,11 +5061,11 @@
50615061
/*
50625062
** CAPI3REF: SQL Function Context Object
50635063
**
50645064
** The context in which an SQL function executes is stored in an
50655065
** sqlite3_context object. ^A pointer to an sqlite3_context object
5066
-** is always first parameter to [application-defined SQL functions].
5066
+** is always the first parameter to [application-defined SQL functions].
50675067
** The application-defined SQL function implementation will pass this
50685068
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
50695069
** [sqlite3_aggregate_context()], [sqlite3_user_data()],
50705070
** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
50715071
** and/or [sqlite3_set_auxdata()].
@@ -5798,11 +5798,11 @@
57985798
** CAPI3REF: Destroy A Prepared Statement Object
57995799
** DESTRUCTOR: sqlite3_stmt
58005800
**
58015801
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
58025802
** ^If the most recent evaluation of the statement encountered no errors
5803
-** or if the statement is never been evaluated, then sqlite3_finalize() returns
5803
+** or if the statement has never been evaluated, then sqlite3_finalize() returns
58045804
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
58055805
** sqlite3_finalize(S) returns the appropriate [error code] or
58065806
** [extended error code].
58075807
**
58085808
** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -6030,11 +6030,11 @@
60306030
);
60316031
60326032
/*
60336033
** CAPI3REF: Text Encodings
60346034
**
6035
-** These constant define integer codes that represent the various
6035
+** These constants define integer codes that represent the various
60366036
** text encodings supported by SQLite.
60376037
*/
60386038
#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
60396039
#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
60406040
#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -6122,11 +6122,11 @@
61226122
** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
61236123
** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
61246124
** result.
61256125
** Every function that invokes [sqlite3_result_subtype()] should have this
61266126
** property. If it does not, then the call to [sqlite3_result_subtype()]
6127
-** might become a no-op if the function is used as term in an
6127
+** might become a no-op if the function is used as a term in an
61286128
** [expression index]. On the other hand, SQL functions that never invoke
61296129
** [sqlite3_result_subtype()] should avoid setting this property, as the
61306130
** purpose of this property is to disable certain optimizations that are
61316131
** incompatible with subtypes.
61326132
**
@@ -6249,11 +6249,11 @@
62496249
**
62506250
** ^Within the [xUpdate] method of a [virtual table], the
62516251
** sqlite3_value_nochange(X) interface returns true if and only if
62526252
** the column corresponding to X is unchanged by the UPDATE operation
62536253
** that the xUpdate method call was invoked to implement and if
6254
-** and the prior [xColumn] method call that was invoked to extracted
6254
+** the prior [xColumn] method call that was invoked to extract
62556255
** the value for that column returned without setting a result (probably
62566256
** because it queried [sqlite3_vtab_nochange()] and found that the column
62576257
** was unchanging). ^Within an [xUpdate] method, any value for which
62586258
** sqlite3_value_nochange(X) is true will in all other respects appear
62596259
** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
@@ -93753,10 +93753,13 @@
9375393753
rc = SQLITE_MISUSE_BKPT;
9375493754
goto preupdate_old_out;
9375593755
}
9375693756
if( p->pPk ){
9375793757
iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
93758
+ }else if( iIdx >= p->pTab->nCol ){
93759
+ rc = SQLITE_MISUSE_BKPT;
93760
+ goto preupdate_old_out;
9375893761
}else{
9375993762
iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
9376093763
}
9376193764
if( iStore>=p->pCsr->nField || iStore<0 ){
9376293765
rc = SQLITE_RANGE;
@@ -244933,10 +244936,40 @@
244933244936
Fts5Buffer term; /* Current term */
244934244937
i64 iRowid; /* Current rowid */
244935244938
int nPos; /* Number of bytes in current position list */
244936244939
u8 bDel; /* True if the delete flag is set */
244937244940
};
244941
+
244942
+static int fts5IndexCorruptRowid(Fts5Index *pIdx, i64 iRowid){
244943
+ pIdx->rc = FTS5_CORRUPT;
244944
+ sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
244945
+ "fts5: corruption found reading blob %lld from table \"%s\"",
244946
+ iRowid, pIdx->pConfig->zName
244947
+ );
244948
+ return SQLITE_CORRUPT_VTAB;
244949
+}
244950
+#define FTS5_CORRUPT_ROWID(pIdx, iRowid) fts5IndexCorruptRowid(pIdx, iRowid)
244951
+
244952
+static int fts5IndexCorruptIter(Fts5Index *pIdx, Fts5SegIter *pIter){
244953
+ pIdx->rc = FTS5_CORRUPT;
244954
+ sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
244955
+ "fts5: corruption on page %d, segment %d, table \"%s\"",
244956
+ pIter->iLeafPgno, pIter->pSeg->iSegid, pIdx->pConfig->zName
244957
+ );
244958
+ return SQLITE_CORRUPT_VTAB;
244959
+}
244960
+#define FTS5_CORRUPT_ITER(pIdx, pIter) fts5IndexCorruptIter(pIdx, pIter)
244961
+
244962
+static int fts5IndexCorruptIdx(Fts5Index *pIdx){
244963
+ pIdx->rc = FTS5_CORRUPT;
244964
+ sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
244965
+ "fts5: corruption in table \"%s\"", pIdx->pConfig->zName
244966
+ );
244967
+ return SQLITE_CORRUPT_VTAB;
244968
+}
244969
+#define FTS5_CORRUPT_IDX(pIdx) fts5IndexCorruptIdx(pIdx)
244970
+
244938244971
244939244972
/*
244940244973
** Array of tombstone pages. Reference counted.
244941244974
*/
244942244975
struct Fts5TombstoneArray {
@@ -245223,11 +245256,11 @@
245223245256
/* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
245224245257
** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
245225245258
** All the reasons those functions might return SQLITE_ERROR - missing
245226245259
** table, missing row, non-blob/text in block column - indicate
245227245260
** backing store corruption. */
245228
- if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT;
245261
+ if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT_ROWID(p, iRowid);
245229245262
245230245263
if( rc==SQLITE_OK ){
245231245264
u8 *aOut = 0; /* Read blob data into this buffer */
245232245265
int nByte = sqlite3_blob_bytes(p->pReader);
245233245266
int szData = (sizeof(Fts5Data) + 7) & ~7;
@@ -245273,11 +245306,11 @@
245273245306
245274245307
static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
245275245308
Fts5Data *pRet = fts5DataRead(p, iRowid);
245276245309
if( pRet ){
245277245310
if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){
245278
- p->rc = FTS5_CORRUPT;
245311
+ FTS5_CORRUPT_ROWID(p, iRowid);
245279245312
fts5DataRelease(pRet);
245280245313
pRet = 0;
245281245314
}
245282245315
}
245283245316
return pRet;
@@ -245632,12 +245665,18 @@
245632245665
pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
245633245666
if( p->rc==SQLITE_OK ){
245634245667
/* TODO: Do we need this if the leaf-index is appended? Probably... */
245635245668
memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
245636245669
p->rc = fts5StructureDecode(pData->p, pData->nn, &iCookie, &pRet);
245637
- if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
245638
- p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
245670
+ if( p->rc==SQLITE_OK ){
245671
+ if( (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
245672
+ p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
245673
+ }
245674
+ }else if( p->rc==SQLITE_CORRUPT_VTAB ){
245675
+ sqlite3Fts5ConfigErrmsg(p->pConfig,
245676
+ "fts5: corrupt structure record for table \"%s\"", p->pConfig->zName
245677
+ );
245639245678
}
245640245679
fts5DataRelease(pData);
245641245680
if( p->rc!=SQLITE_OK ){
245642245681
fts5StructureRelease(pRet);
245643245682
pRet = 0;
@@ -246256,11 +246295,11 @@
246256246295
246257246296
ASSERT_SZLEAF_OK(pIter->pLeaf);
246258246297
while( iOff>=pIter->pLeaf->szLeaf ){
246259246298
fts5SegIterNextPage(p, pIter);
246260246299
if( pIter->pLeaf==0 ){
246261
- if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
246300
+ if( p->rc==SQLITE_OK ) FTS5_CORRUPT_ITER(p, pIter);
246262246301
return;
246263246302
}
246264246303
iOff = 4;
246265246304
a = pIter->pLeaf->p;
246266246305
}
@@ -246288,11 +246327,11 @@
246288246327
i64 iOff = pIter->iLeafOffset; /* Offset to read at */
246289246328
int nNew; /* Bytes of new data */
246290246329
246291246330
iOff += fts5GetVarint32(&a[iOff], nNew);
246292246331
if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
246293
- p->rc = FTS5_CORRUPT;
246332
+ FTS5_CORRUPT_ITER(p, pIter);
246294246333
return;
246295246334
}
246296246335
pIter->term.n = nKeep;
246297246336
fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
246298246337
assert( pIter->term.n<=pIter->term.nSpace );
@@ -246483,11 +246522,11 @@
246483246522
}else{
246484246523
int iRowidOff;
246485246524
iRowidOff = fts5LeafFirstRowidOff(pNew);
246486246525
if( iRowidOff ){
246487246526
if( iRowidOff>=pNew->szLeaf ){
246488
- p->rc = FTS5_CORRUPT;
246527
+ FTS5_CORRUPT_ITER(p, pIter);
246489246528
}else{
246490246529
pIter->pLeaf = pNew;
246491246530
pIter->iLeafOffset = iRowidOff;
246492246531
}
246493246532
}
@@ -246717,11 +246756,11 @@
246717246756
pIter->iEndofDoclist = iOff;
246718246757
bNewTerm = 1;
246719246758
}
246720246759
assert_nc( iOff<pLeaf->szLeaf );
246721246760
if( iOff>pLeaf->szLeaf ){
246722
- p->rc = FTS5_CORRUPT;
246761
+ FTS5_CORRUPT_ITER(p, pIter);
246723246762
return;
246724246763
}
246725246764
}
246726246765
}
246727246766
@@ -246827,11 +246866,11 @@
246827246866
fts5DataRelease(pIter->pLeaf);
246828246867
pIter->pLeaf = pLast;
246829246868
pIter->iLeafPgno = pgnoLast;
246830246869
iOff = fts5LeafFirstRowidOff(pLast);
246831246870
if( iOff>pLast->szLeaf ){
246832
- p->rc = FTS5_CORRUPT;
246871
+ FTS5_CORRUPT_ITER(p, pIter);
246833246872
return;
246834246873
}
246835246874
iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
246836246875
pIter->iLeafOffset = iOff;
246837246876
@@ -246906,11 +246945,11 @@
246906246945
246907246946
iPgidx = (u32)pIter->pLeaf->szLeaf;
246908246947
iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
246909246948
iOff = iTermOff;
246910246949
if( iOff>n ){
246911
- p->rc = FTS5_CORRUPT;
246950
+ FTS5_CORRUPT_ITER(p, pIter);
246912246951
return;
246913246952
}
246914246953
246915246954
while( 1 ){
246916246955
@@ -246949,11 +246988,11 @@
246949246988
iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
246950246989
iTermOff += nKeep;
246951246990
iOff = iTermOff;
246952246991
246953246992
if( iOff>=n ){
246954
- p->rc = FTS5_CORRUPT;
246993
+ FTS5_CORRUPT_ITER(p, pIter);
246955246994
return;
246956246995
}
246957246996
246958246997
/* Read the nKeep field of the next term. */
246959246998
fts5FastGetVarint32(a, iOff, nKeep);
@@ -246971,11 +247010,11 @@
246971247010
a = pIter->pLeaf->p;
246972247011
if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
246973247012
iPgidx = (u32)pIter->pLeaf->szLeaf;
246974247013
iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
246975247014
if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
246976
- p->rc = FTS5_CORRUPT;
247015
+ FTS5_CORRUPT_ITER(p, pIter);
246977247016
return;
246978247017
}else{
246979247018
nKeep = 0;
246980247019
iTermOff = iOff;
246981247020
n = (u32)pIter->pLeaf->nn;
@@ -246986,11 +247025,11 @@
246986247025
}while( 1 );
246987247026
}
246988247027
246989247028
search_success:
246990247029
if( (i64)iOff+nNew>n || nNew<1 ){
246991
- p->rc = FTS5_CORRUPT;
247030
+ FTS5_CORRUPT_ITER(p, pIter);
246992247031
return;
246993247032
}
246994247033
pIter->iLeafOffset = iOff + nNew;
246995247034
pIter->iTermLeafOffset = pIter->iLeafOffset;
246996247035
pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -247451,11 +247490,11 @@
247451247490
int iLeafPgno
247452247491
){
247453247492
assert( iLeafPgno>pIter->iLeafPgno );
247454247493
247455247494
if( iLeafPgno>pIter->pSeg->pgnoLast ){
247456
- p->rc = FTS5_CORRUPT;
247495
+ FTS5_CORRUPT_IDX(p);
247457247496
}else{
247458247497
fts5DataRelease(pIter->pNextLeaf);
247459247498
pIter->pNextLeaf = 0;
247460247499
pIter->iLeafPgno = iLeafPgno-1;
247461247500
@@ -247466,11 +247505,11 @@
247466247505
iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
247467247506
if( iOff>0 ){
247468247507
u8 *a = pIter->pLeaf->p;
247469247508
int n = pIter->pLeaf->szLeaf;
247470247509
if( iOff<4 || iOff>=n ){
247471
- p->rc = FTS5_CORRUPT;
247510
+ FTS5_CORRUPT_IDX(p);
247472247511
}else{
247473247512
iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
247474247513
pIter->iLeafOffset = iOff;
247475247514
fts5SegIterLoadNPos(p, pIter);
247476247515
}
@@ -247945,11 +247984,11 @@
247945247984
nRem -= nChunk;
247946247985
fts5DataRelease(pData);
247947247986
if( nRem<=0 ){
247948247987
break;
247949247988
}else if( pSeg->pSeg==0 ){
247950
- p->rc = FTS5_CORRUPT;
247989
+ FTS5_CORRUPT_IDX(p);
247951247990
return;
247952247991
}else{
247953247992
pgno++;
247954247993
pData = fts5LeafRead(p, FTS5_SEGMENT_ROWID(pSeg->pSeg->iSegid, pgno));
247955247994
if( pData==0 ) break;
@@ -249048,11 +249087,11 @@
249048249087
if( iOff>pData->szLeaf ){
249049249088
/* This can occur if the pages that the segments occupy overlap - if
249050249089
** a single page has been assigned to more than one segment. In
249051249090
** this case a prior iteration of this loop may have corrupted the
249052249091
** segment currently being trimmed. */
249053
- p->rc = FTS5_CORRUPT;
249092
+ FTS5_CORRUPT_ROWID(p, iLeafRowid);
249054249093
}else{
249055249094
fts5BufferZero(&buf);
249056249095
fts5BufferGrow(&p->rc, &buf, pData->nn);
249057249096
fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
249058249097
fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
@@ -249515,11 +249554,11 @@
249515249554
fts5DataRelease(pLeaf);
249516249555
pLeaf = 0;
249517249556
}else if( bDetailNone ){
249518249557
break;
249519249558
}else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){
249520
- p->rc = FTS5_CORRUPT;
249559
+ FTS5_CORRUPT_ROWID(p, iRowid);
249521249560
break;
249522249561
}else{
249523249562
int nShift = iNext - 4;
249524249563
int nPg;
249525249564
@@ -249535,11 +249574,11 @@
249535249574
int i1 = pLeaf->szLeaf;
249536249575
int i2 = 0;
249537249576
249538249577
i1 += fts5GetVarint32(&aPg[i1], iFirst);
249539249578
if( iFirst<iNext ){
249540
- p->rc = FTS5_CORRUPT;
249579
+ FTS5_CORRUPT_ROWID(p, iRowid);
249541249580
break;
249542249581
}
249543249582
aIdx = sqlite3Fts5MallocZero(&p->rc, (pLeaf->nn-pLeaf->szLeaf)+2);
249544249583
if( aIdx==0 ) break;
249545249584
i2 = sqlite3Fts5PutVarint(aIdx, iFirst-nShift);
@@ -249758,18 +249797,18 @@
249758249797
249759249798
nPrefix = MIN(nPrefix, nPrefix2);
249760249799
nSuffix = (nPrefix2 + nSuffix2) - nPrefix;
249761249800
249762249801
if( (iKeyOff+nSuffix)>iPgIdx || (iNextOff+nSuffix2)>iPgIdx ){
249763
- p->rc = FTS5_CORRUPT;
249802
+ FTS5_CORRUPT_IDX(p);
249764249803
}else{
249765249804
if( iKey!=1 ){
249766249805
iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
249767249806
}
249768249807
iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
249769249808
if( nPrefix2>pSeg->term.n ){
249770
- p->rc = FTS5_CORRUPT;
249809
+ FTS5_CORRUPT_IDX(p);
249771249810
}else if( nPrefix2>nPrefix ){
249772249811
memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
249773249812
iOff += (nPrefix2-nPrefix);
249774249813
}
249775249814
memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
@@ -250558,11 +250597,11 @@
250558250597
fts5PrefixMergerInsertByPosition(&pHead, pSave);
250559250598
pSave = pNext;
250560250599
}
250561250600
250562250601
if( pHead==0 || pHead->pNext==0 ){
250563
- p->rc = FTS5_CORRUPT;
250602
+ FTS5_CORRUPT_IDX(p);
250564250603
break;
250565250604
}
250566250605
250567250606
/* See the earlier comment in this function for an explanation of why
250568250607
** corrupt input position lists might cause the output to consume
@@ -250595,11 +250634,11 @@
250595250634
250596250635
/* WRITEPOSLISTSIZE */
250597250636
assert_nc( tmp.n+nTail<=nTmp );
250598250637
assert( tmp.n+nTail<=nTmp+nMerge*10 );
250599250638
if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
250600
- if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
250639
+ if( p->rc==SQLITE_OK ) FTS5_CORRUPT_IDX(p);
250601250640
break;
250602250641
}
250603250642
fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2);
250604250643
fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
250605250644
if( nTail>0 ){
@@ -252724,18 +252763,21 @@
252724252763
/* Now check that the iter.nEmpty leaves following the current leaf
252725252764
** (a) exist and (b) contain no terms. */
252726252765
for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
252727252766
Fts5Data *pLeaf = fts5DataRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
252728252767
if( pLeaf ){
252729
- if( !fts5LeafIsTermless(pLeaf) ) p->rc = FTS5_CORRUPT;
252730
- if( i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf) ) p->rc = FTS5_CORRUPT;
252768
+ if( !fts5LeafIsTermless(pLeaf)
252769
+ || (i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf))
252770
+ ){
252771
+ FTS5_CORRUPT_ROWID(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
252772
+ }
252731252773
}
252732252774
fts5DataRelease(pLeaf);
252733252775
}
252734252776
}
252735252777
252736
-static void fts5IntegrityCheckPgidx(Fts5Index *p, Fts5Data *pLeaf){
252778
+static void fts5IntegrityCheckPgidx(Fts5Index *p, i64 iRowid, Fts5Data *pLeaf){
252737252779
i64 iTermOff = 0;
252738252780
int ii;
252739252781
252740252782
Fts5Buffer buf1 = {0,0,0};
252741252783
Fts5Buffer buf2 = {0,0,0};
@@ -252749,33 +252791,33 @@
252749252791
ii += fts5GetVarint32(&pLeaf->p[ii], nIncr);
252750252792
iTermOff += nIncr;
252751252793
iOff = iTermOff;
252752252794
252753252795
if( iOff>=pLeaf->szLeaf ){
252754
- p->rc = FTS5_CORRUPT;
252796
+ FTS5_CORRUPT_ROWID(p, iRowid);
252755252797
}else if( iTermOff==nIncr ){
252756252798
int nByte;
252757252799
iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252758252800
if( (iOff+nByte)>pLeaf->szLeaf ){
252759
- p->rc = FTS5_CORRUPT;
252801
+ FTS5_CORRUPT_ROWID(p, iRowid);
252760252802
}else{
252761252803
fts5BufferSet(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252762252804
}
252763252805
}else{
252764252806
int nKeep, nByte;
252765252807
iOff += fts5GetVarint32(&pLeaf->p[iOff], nKeep);
252766252808
iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252767252809
if( nKeep>buf1.n || (iOff+nByte)>pLeaf->szLeaf ){
252768
- p->rc = FTS5_CORRUPT;
252810
+ FTS5_CORRUPT_ROWID(p, iRowid);
252769252811
}else{
252770252812
buf1.n = nKeep;
252771252813
fts5BufferAppendBlob(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252772252814
}
252773252815
252774252816
if( p->rc==SQLITE_OK ){
252775252817
res = fts5BufferCompare(&buf1, &buf2);
252776
- if( res<=0 ) p->rc = FTS5_CORRUPT;
252818
+ if( res<=0 ) FTS5_CORRUPT_ROWID(p, iRowid);
252777252819
}
252778252820
}
252779252821
fts5BufferSet(&p->rc, &buf2, buf1.n, buf1.p);
252780252822
}
252781252823
@@ -252832,11 +252874,11 @@
252832252874
){
252833252875
/* special case - the very first page in a segment keeps its %_idx
252834252876
** entry even if all the terms are removed from it by secure-delete
252835252877
** operations. */
252836252878
}else{
252837
- p->rc = FTS5_CORRUPT;
252879
+ FTS5_CORRUPT_ROWID(p, iRow);
252838252880
}
252839252881
252840252882
}else{
252841252883
int iOff; /* Offset of first term on leaf */
252842252884
int iRowidOff; /* Offset of first rowid on leaf */
@@ -252844,19 +252886,19 @@
252844252886
int res; /* Comparison of term and split-key */
252845252887
252846252888
iOff = fts5LeafFirstTermOff(pLeaf);
252847252889
iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252848252890
if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
252849
- p->rc = FTS5_CORRUPT;
252891
+ FTS5_CORRUPT_ROWID(p, iRow);
252850252892
}else{
252851252893
iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
252852252894
res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
252853252895
if( res==0 ) res = nTerm - nIdxTerm;
252854
- if( res<0 ) p->rc = FTS5_CORRUPT;
252896
+ if( res<0 ) FTS5_CORRUPT_ROWID(p, iRow);
252855252897
}
252856252898
252857
- fts5IntegrityCheckPgidx(p, pLeaf);
252899
+ fts5IntegrityCheckPgidx(p, iRow, pLeaf);
252858252900
}
252859252901
fts5DataRelease(pLeaf);
252860252902
if( p->rc ) break;
252861252903
252862252904
/* Now check that the iter.nEmpty leaves following the current leaf
@@ -252882,11 +252924,11 @@
252882252924
/* Check any rowid-less pages that occur before the current leaf. */
252883252925
for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){
252884252926
iKey = FTS5_SEGMENT_ROWID(iSegid, iPg);
252885252927
pLeaf = fts5DataRead(p, iKey);
252886252928
if( pLeaf ){
252887
- if( fts5LeafFirstRowidOff(pLeaf)!=0 ) p->rc = FTS5_CORRUPT;
252929
+ if( fts5LeafFirstRowidOff(pLeaf)!=0 ) FTS5_CORRUPT_ROWID(p, iKey);
252888252930
fts5DataRelease(pLeaf);
252889252931
}
252890252932
}
252891252933
iPrevLeaf = fts5DlidxIterPgno(pDlidx);
252892252934
@@ -252897,16 +252939,16 @@
252897252939
if( pLeaf ){
252898252940
i64 iRowid;
252899252941
int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252900252942
ASSERT_SZLEAF_OK(pLeaf);
252901252943
if( iRowidOff>=pLeaf->szLeaf ){
252902
- p->rc = FTS5_CORRUPT;
252944
+ FTS5_CORRUPT_ROWID(p, iKey);
252903252945
}else if( bSecureDelete==0 || iRowidOff>0 ){
252904252946
i64 iDlRowid = fts5DlidxIterRowid(pDlidx);
252905252947
fts5GetVarint(&pLeaf->p[iRowidOff], (u64*)&iRowid);
252906252948
if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
252907
- p->rc = FTS5_CORRUPT;
252949
+ FTS5_CORRUPT_ROWID(p, iKey);
252908252950
}
252909252951
}
252910252952
fts5DataRelease(pLeaf);
252911252953
}
252912252954
}
@@ -253017,11 +253059,16 @@
253017253059
}
253018253060
}
253019253061
fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
253020253062
253021253063
fts5MultiIterFree(pIter);
253022
- if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ) p->rc = FTS5_CORRUPT;
253064
+ if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ){
253065
+ p->rc = FTS5_CORRUPT;
253066
+ sqlite3Fts5ConfigErrmsg(p->pConfig,
253067
+ "fts5: checksum mismatch for table \"%s\"", p->pConfig->zName
253068
+ );
253069
+ }
253023253070
253024253071
fts5StructureRelease(pStruct);
253025253072
#ifdef SQLITE_DEBUG
253026253073
fts5BufferFree(&term);
253027253074
#endif
@@ -257433,11 +257480,11 @@
257433257480
int nArg, /* Number of args */
257434257481
sqlite3_value **apUnused /* Function arguments */
257435257482
){
257436257483
assert( nArg==0 );
257437257484
UNUSED_PARAM2(nArg, apUnused);
257438
- sqlite3_result_text(pCtx, "fts5: 2025-06-23 16:51:33 cf61cd359e666c66b6bba4407a653c799f7f07e1f5ee6b837ad467029c461a6a", -1, SQLITE_TRANSIENT);
257485
+ sqlite3_result_text(pCtx, "fts5: 2025-06-24 15:58:32 6a5701e6c7be25cba93e55438f950966e1dacb32eb2b23a8acc8ac53da6f0a85", -1, SQLITE_TRANSIENT);
257439257486
}
257440257487
257441257488
/*
257442257489
** Implementation of fts5_locale(LOCALE, TEXT) function.
257443257490
**
@@ -257556,12 +257603,13 @@
257556257603
}else{
257557257604
*pzErr = sqlite3_mprintf("unable to validate the inverted index for"
257558257605
" FTS5 table %s.%s: %s",
257559257606
zSchema, zTabname, sqlite3_errstr(rc));
257560257607
}
257608
+ }else if( (rc&0xff)==SQLITE_CORRUPT ){
257609
+ rc = SQLITE_OK;
257561257610
}
257562
-
257563257611
sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
257564257612
pTab->p.pConfig->pzErrmsg = 0;
257565257613
257566257614
return rc;
257567257615
}
257568257616
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** cf61cd359e666c66b6bba4407a653c799f7f with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.51.0"
469 #define SQLITE_VERSION_NUMBER 3051000
470 #define SQLITE_SOURCE_ID "2025-06-23 16:51:33 cf61cd359e666c66b6bba4407a653c799f7f07e1f5ee6b837ad467029c461a6a"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -4479,19 +4479,19 @@
4479 ** The application does not need to worry about freeing the result.
4480 ** However, the error string might be overwritten or deallocated by
4481 ** subsequent calls to other SQLite interface functions.)^
4482 **
4483 ** ^The sqlite3_errstr(E) interface returns the English-language text
4484 ** that describes the [result code] E, as UTF-8, or NULL if E is not an
4485 ** result code for which a text error message is available.
4486 ** ^(Memory to hold the error message string is managed internally
4487 ** and must not be freed by the application)^.
4488 **
4489 ** ^If the most recent error references a specific token in the input
4490 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4491 ** of the start of that token. ^The byte offset returned by
4492 ** sqlite3_error_offset() assumes that the input SQL is UTF8.
4493 ** ^If the most recent error does not reference a specific token in the input
4494 ** SQL, then the sqlite3_error_offset() function returns -1.
4495 **
4496 ** When the serialized [threading mode] is in use, it might be the
4497 ** case that a second error occurs on a separate thread in between
@@ -4586,12 +4586,12 @@
4586 ** CAPI3REF: Run-Time Limit Categories
4587 ** KEYWORDS: {limit category} {*limit categories}
4588 **
4589 ** These constants define various performance limits
4590 ** that can be lowered at run-time using [sqlite3_limit()].
4591 ** The synopsis of the meanings of the various limits is shown below.
4592 ** Additional information is available at [limits | Limits in SQLite].
4593 **
4594 ** <dl>
4595 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4596 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4597 **
@@ -4652,11 +4652,11 @@
4652 #define SQLITE_LIMIT_WORKER_THREADS 11
4653
4654 /*
4655 ** CAPI3REF: Prepare Flags
4656 **
4657 ** These constants define various flags that can be passed into
4658 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4659 ** [sqlite3_prepare16_v3()] interfaces.
4660 **
4661 ** New flags may be added in future releases of SQLite.
4662 **
@@ -4739,11 +4739,11 @@
4739 ** statement is generated.
4740 ** If the caller knows that the supplied string is nul-terminated, then
4741 ** there is a small performance advantage to passing an nByte parameter that
4742 ** is the number of bytes in the input string <i>including</i>
4743 ** the nul-terminator.
4744 ** Note that nByte measure the length of the input in bytes, not
4745 ** characters, even for the UTF-16 interfaces.
4746 **
4747 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4748 ** past the end of the first SQL statement in zSql. These routines only
4749 ** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4873,11 +4873,11 @@
4873 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4874 ** will return "SELECT 2345,NULL".)^
4875 **
4876 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4877 ** is available to hold the result, or if the result would exceed the
4878 ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4879 **
4880 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4881 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
4882 ** option causes sqlite3_expanded_sql() to always return NULL.
4883 **
@@ -5061,11 +5061,11 @@
5061 /*
5062 ** CAPI3REF: SQL Function Context Object
5063 **
5064 ** The context in which an SQL function executes is stored in an
5065 ** sqlite3_context object. ^A pointer to an sqlite3_context object
5066 ** is always first parameter to [application-defined SQL functions].
5067 ** The application-defined SQL function implementation will pass this
5068 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
5069 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
5070 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
5071 ** and/or [sqlite3_set_auxdata()].
@@ -5798,11 +5798,11 @@
5798 ** CAPI3REF: Destroy A Prepared Statement Object
5799 ** DESTRUCTOR: sqlite3_stmt
5800 **
5801 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5802 ** ^If the most recent evaluation of the statement encountered no errors
5803 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
5804 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
5805 ** sqlite3_finalize(S) returns the appropriate [error code] or
5806 ** [extended error code].
5807 **
5808 ** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -6030,11 +6030,11 @@
6030 );
6031
6032 /*
6033 ** CAPI3REF: Text Encodings
6034 **
6035 ** These constant define integer codes that represent the various
6036 ** text encodings supported by SQLite.
6037 */
6038 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
6039 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
6040 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -6122,11 +6122,11 @@
6122 ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
6123 ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
6124 ** result.
6125 ** Every function that invokes [sqlite3_result_subtype()] should have this
6126 ** property. If it does not, then the call to [sqlite3_result_subtype()]
6127 ** might become a no-op if the function is used as term in an
6128 ** [expression index]. On the other hand, SQL functions that never invoke
6129 ** [sqlite3_result_subtype()] should avoid setting this property, as the
6130 ** purpose of this property is to disable certain optimizations that are
6131 ** incompatible with subtypes.
6132 **
@@ -6249,11 +6249,11 @@
6249 **
6250 ** ^Within the [xUpdate] method of a [virtual table], the
6251 ** sqlite3_value_nochange(X) interface returns true if and only if
6252 ** the column corresponding to X is unchanged by the UPDATE operation
6253 ** that the xUpdate method call was invoked to implement and if
6254 ** and the prior [xColumn] method call that was invoked to extracted
6255 ** the value for that column returned without setting a result (probably
6256 ** because it queried [sqlite3_vtab_nochange()] and found that the column
6257 ** was unchanging). ^Within an [xUpdate] method, any value for which
6258 ** sqlite3_value_nochange(X) is true will in all other respects appear
6259 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
@@ -93753,10 +93753,13 @@
93753 rc = SQLITE_MISUSE_BKPT;
93754 goto preupdate_old_out;
93755 }
93756 if( p->pPk ){
93757 iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
 
 
 
93758 }else{
93759 iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
93760 }
93761 if( iStore>=p->pCsr->nField || iStore<0 ){
93762 rc = SQLITE_RANGE;
@@ -244933,10 +244936,40 @@
244933 Fts5Buffer term; /* Current term */
244934 i64 iRowid; /* Current rowid */
244935 int nPos; /* Number of bytes in current position list */
244936 u8 bDel; /* True if the delete flag is set */
244937 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244938
244939 /*
244940 ** Array of tombstone pages. Reference counted.
244941 */
244942 struct Fts5TombstoneArray {
@@ -245223,11 +245256,11 @@
245223 /* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
245224 ** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
245225 ** All the reasons those functions might return SQLITE_ERROR - missing
245226 ** table, missing row, non-blob/text in block column - indicate
245227 ** backing store corruption. */
245228 if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT;
245229
245230 if( rc==SQLITE_OK ){
245231 u8 *aOut = 0; /* Read blob data into this buffer */
245232 int nByte = sqlite3_blob_bytes(p->pReader);
245233 int szData = (sizeof(Fts5Data) + 7) & ~7;
@@ -245273,11 +245306,11 @@
245273
245274 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
245275 Fts5Data *pRet = fts5DataRead(p, iRowid);
245276 if( pRet ){
245277 if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){
245278 p->rc = FTS5_CORRUPT;
245279 fts5DataRelease(pRet);
245280 pRet = 0;
245281 }
245282 }
245283 return pRet;
@@ -245632,12 +245665,18 @@
245632 pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
245633 if( p->rc==SQLITE_OK ){
245634 /* TODO: Do we need this if the leaf-index is appended? Probably... */
245635 memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
245636 p->rc = fts5StructureDecode(pData->p, pData->nn, &iCookie, &pRet);
245637 if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
245638 p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
 
 
 
 
 
 
245639 }
245640 fts5DataRelease(pData);
245641 if( p->rc!=SQLITE_OK ){
245642 fts5StructureRelease(pRet);
245643 pRet = 0;
@@ -246256,11 +246295,11 @@
246256
246257 ASSERT_SZLEAF_OK(pIter->pLeaf);
246258 while( iOff>=pIter->pLeaf->szLeaf ){
246259 fts5SegIterNextPage(p, pIter);
246260 if( pIter->pLeaf==0 ){
246261 if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
246262 return;
246263 }
246264 iOff = 4;
246265 a = pIter->pLeaf->p;
246266 }
@@ -246288,11 +246327,11 @@
246288 i64 iOff = pIter->iLeafOffset; /* Offset to read at */
246289 int nNew; /* Bytes of new data */
246290
246291 iOff += fts5GetVarint32(&a[iOff], nNew);
246292 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
246293 p->rc = FTS5_CORRUPT;
246294 return;
246295 }
246296 pIter->term.n = nKeep;
246297 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
246298 assert( pIter->term.n<=pIter->term.nSpace );
@@ -246483,11 +246522,11 @@
246483 }else{
246484 int iRowidOff;
246485 iRowidOff = fts5LeafFirstRowidOff(pNew);
246486 if( iRowidOff ){
246487 if( iRowidOff>=pNew->szLeaf ){
246488 p->rc = FTS5_CORRUPT;
246489 }else{
246490 pIter->pLeaf = pNew;
246491 pIter->iLeafOffset = iRowidOff;
246492 }
246493 }
@@ -246717,11 +246756,11 @@
246717 pIter->iEndofDoclist = iOff;
246718 bNewTerm = 1;
246719 }
246720 assert_nc( iOff<pLeaf->szLeaf );
246721 if( iOff>pLeaf->szLeaf ){
246722 p->rc = FTS5_CORRUPT;
246723 return;
246724 }
246725 }
246726 }
246727
@@ -246827,11 +246866,11 @@
246827 fts5DataRelease(pIter->pLeaf);
246828 pIter->pLeaf = pLast;
246829 pIter->iLeafPgno = pgnoLast;
246830 iOff = fts5LeafFirstRowidOff(pLast);
246831 if( iOff>pLast->szLeaf ){
246832 p->rc = FTS5_CORRUPT;
246833 return;
246834 }
246835 iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
246836 pIter->iLeafOffset = iOff;
246837
@@ -246906,11 +246945,11 @@
246906
246907 iPgidx = (u32)pIter->pLeaf->szLeaf;
246908 iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
246909 iOff = iTermOff;
246910 if( iOff>n ){
246911 p->rc = FTS5_CORRUPT;
246912 return;
246913 }
246914
246915 while( 1 ){
246916
@@ -246949,11 +246988,11 @@
246949 iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
246950 iTermOff += nKeep;
246951 iOff = iTermOff;
246952
246953 if( iOff>=n ){
246954 p->rc = FTS5_CORRUPT;
246955 return;
246956 }
246957
246958 /* Read the nKeep field of the next term. */
246959 fts5FastGetVarint32(a, iOff, nKeep);
@@ -246971,11 +247010,11 @@
246971 a = pIter->pLeaf->p;
246972 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
246973 iPgidx = (u32)pIter->pLeaf->szLeaf;
246974 iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
246975 if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
246976 p->rc = FTS5_CORRUPT;
246977 return;
246978 }else{
246979 nKeep = 0;
246980 iTermOff = iOff;
246981 n = (u32)pIter->pLeaf->nn;
@@ -246986,11 +247025,11 @@
246986 }while( 1 );
246987 }
246988
246989 search_success:
246990 if( (i64)iOff+nNew>n || nNew<1 ){
246991 p->rc = FTS5_CORRUPT;
246992 return;
246993 }
246994 pIter->iLeafOffset = iOff + nNew;
246995 pIter->iTermLeafOffset = pIter->iLeafOffset;
246996 pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -247451,11 +247490,11 @@
247451 int iLeafPgno
247452 ){
247453 assert( iLeafPgno>pIter->iLeafPgno );
247454
247455 if( iLeafPgno>pIter->pSeg->pgnoLast ){
247456 p->rc = FTS5_CORRUPT;
247457 }else{
247458 fts5DataRelease(pIter->pNextLeaf);
247459 pIter->pNextLeaf = 0;
247460 pIter->iLeafPgno = iLeafPgno-1;
247461
@@ -247466,11 +247505,11 @@
247466 iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
247467 if( iOff>0 ){
247468 u8 *a = pIter->pLeaf->p;
247469 int n = pIter->pLeaf->szLeaf;
247470 if( iOff<4 || iOff>=n ){
247471 p->rc = FTS5_CORRUPT;
247472 }else{
247473 iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
247474 pIter->iLeafOffset = iOff;
247475 fts5SegIterLoadNPos(p, pIter);
247476 }
@@ -247945,11 +247984,11 @@
247945 nRem -= nChunk;
247946 fts5DataRelease(pData);
247947 if( nRem<=0 ){
247948 break;
247949 }else if( pSeg->pSeg==0 ){
247950 p->rc = FTS5_CORRUPT;
247951 return;
247952 }else{
247953 pgno++;
247954 pData = fts5LeafRead(p, FTS5_SEGMENT_ROWID(pSeg->pSeg->iSegid, pgno));
247955 if( pData==0 ) break;
@@ -249048,11 +249087,11 @@
249048 if( iOff>pData->szLeaf ){
249049 /* This can occur if the pages that the segments occupy overlap - if
249050 ** a single page has been assigned to more than one segment. In
249051 ** this case a prior iteration of this loop may have corrupted the
249052 ** segment currently being trimmed. */
249053 p->rc = FTS5_CORRUPT;
249054 }else{
249055 fts5BufferZero(&buf);
249056 fts5BufferGrow(&p->rc, &buf, pData->nn);
249057 fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
249058 fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
@@ -249515,11 +249554,11 @@
249515 fts5DataRelease(pLeaf);
249516 pLeaf = 0;
249517 }else if( bDetailNone ){
249518 break;
249519 }else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){
249520 p->rc = FTS5_CORRUPT;
249521 break;
249522 }else{
249523 int nShift = iNext - 4;
249524 int nPg;
249525
@@ -249535,11 +249574,11 @@
249535 int i1 = pLeaf->szLeaf;
249536 int i2 = 0;
249537
249538 i1 += fts5GetVarint32(&aPg[i1], iFirst);
249539 if( iFirst<iNext ){
249540 p->rc = FTS5_CORRUPT;
249541 break;
249542 }
249543 aIdx = sqlite3Fts5MallocZero(&p->rc, (pLeaf->nn-pLeaf->szLeaf)+2);
249544 if( aIdx==0 ) break;
249545 i2 = sqlite3Fts5PutVarint(aIdx, iFirst-nShift);
@@ -249758,18 +249797,18 @@
249758
249759 nPrefix = MIN(nPrefix, nPrefix2);
249760 nSuffix = (nPrefix2 + nSuffix2) - nPrefix;
249761
249762 if( (iKeyOff+nSuffix)>iPgIdx || (iNextOff+nSuffix2)>iPgIdx ){
249763 p->rc = FTS5_CORRUPT;
249764 }else{
249765 if( iKey!=1 ){
249766 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
249767 }
249768 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
249769 if( nPrefix2>pSeg->term.n ){
249770 p->rc = FTS5_CORRUPT;
249771 }else if( nPrefix2>nPrefix ){
249772 memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
249773 iOff += (nPrefix2-nPrefix);
249774 }
249775 memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
@@ -250558,11 +250597,11 @@
250558 fts5PrefixMergerInsertByPosition(&pHead, pSave);
250559 pSave = pNext;
250560 }
250561
250562 if( pHead==0 || pHead->pNext==0 ){
250563 p->rc = FTS5_CORRUPT;
250564 break;
250565 }
250566
250567 /* See the earlier comment in this function for an explanation of why
250568 ** corrupt input position lists might cause the output to consume
@@ -250595,11 +250634,11 @@
250595
250596 /* WRITEPOSLISTSIZE */
250597 assert_nc( tmp.n+nTail<=nTmp );
250598 assert( tmp.n+nTail<=nTmp+nMerge*10 );
250599 if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
250600 if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
250601 break;
250602 }
250603 fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2);
250604 fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
250605 if( nTail>0 ){
@@ -252724,18 +252763,21 @@
252724 /* Now check that the iter.nEmpty leaves following the current leaf
252725 ** (a) exist and (b) contain no terms. */
252726 for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
252727 Fts5Data *pLeaf = fts5DataRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
252728 if( pLeaf ){
252729 if( !fts5LeafIsTermless(pLeaf) ) p->rc = FTS5_CORRUPT;
252730 if( i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf) ) p->rc = FTS5_CORRUPT;
 
 
 
252731 }
252732 fts5DataRelease(pLeaf);
252733 }
252734 }
252735
252736 static void fts5IntegrityCheckPgidx(Fts5Index *p, Fts5Data *pLeaf){
252737 i64 iTermOff = 0;
252738 int ii;
252739
252740 Fts5Buffer buf1 = {0,0,0};
252741 Fts5Buffer buf2 = {0,0,0};
@@ -252749,33 +252791,33 @@
252749 ii += fts5GetVarint32(&pLeaf->p[ii], nIncr);
252750 iTermOff += nIncr;
252751 iOff = iTermOff;
252752
252753 if( iOff>=pLeaf->szLeaf ){
252754 p->rc = FTS5_CORRUPT;
252755 }else if( iTermOff==nIncr ){
252756 int nByte;
252757 iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252758 if( (iOff+nByte)>pLeaf->szLeaf ){
252759 p->rc = FTS5_CORRUPT;
252760 }else{
252761 fts5BufferSet(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252762 }
252763 }else{
252764 int nKeep, nByte;
252765 iOff += fts5GetVarint32(&pLeaf->p[iOff], nKeep);
252766 iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252767 if( nKeep>buf1.n || (iOff+nByte)>pLeaf->szLeaf ){
252768 p->rc = FTS5_CORRUPT;
252769 }else{
252770 buf1.n = nKeep;
252771 fts5BufferAppendBlob(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252772 }
252773
252774 if( p->rc==SQLITE_OK ){
252775 res = fts5BufferCompare(&buf1, &buf2);
252776 if( res<=0 ) p->rc = FTS5_CORRUPT;
252777 }
252778 }
252779 fts5BufferSet(&p->rc, &buf2, buf1.n, buf1.p);
252780 }
252781
@@ -252832,11 +252874,11 @@
252832 ){
252833 /* special case - the very first page in a segment keeps its %_idx
252834 ** entry even if all the terms are removed from it by secure-delete
252835 ** operations. */
252836 }else{
252837 p->rc = FTS5_CORRUPT;
252838 }
252839
252840 }else{
252841 int iOff; /* Offset of first term on leaf */
252842 int iRowidOff; /* Offset of first rowid on leaf */
@@ -252844,19 +252886,19 @@
252844 int res; /* Comparison of term and split-key */
252845
252846 iOff = fts5LeafFirstTermOff(pLeaf);
252847 iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252848 if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
252849 p->rc = FTS5_CORRUPT;
252850 }else{
252851 iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
252852 res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
252853 if( res==0 ) res = nTerm - nIdxTerm;
252854 if( res<0 ) p->rc = FTS5_CORRUPT;
252855 }
252856
252857 fts5IntegrityCheckPgidx(p, pLeaf);
252858 }
252859 fts5DataRelease(pLeaf);
252860 if( p->rc ) break;
252861
252862 /* Now check that the iter.nEmpty leaves following the current leaf
@@ -252882,11 +252924,11 @@
252882 /* Check any rowid-less pages that occur before the current leaf. */
252883 for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){
252884 iKey = FTS5_SEGMENT_ROWID(iSegid, iPg);
252885 pLeaf = fts5DataRead(p, iKey);
252886 if( pLeaf ){
252887 if( fts5LeafFirstRowidOff(pLeaf)!=0 ) p->rc = FTS5_CORRUPT;
252888 fts5DataRelease(pLeaf);
252889 }
252890 }
252891 iPrevLeaf = fts5DlidxIterPgno(pDlidx);
252892
@@ -252897,16 +252939,16 @@
252897 if( pLeaf ){
252898 i64 iRowid;
252899 int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252900 ASSERT_SZLEAF_OK(pLeaf);
252901 if( iRowidOff>=pLeaf->szLeaf ){
252902 p->rc = FTS5_CORRUPT;
252903 }else if( bSecureDelete==0 || iRowidOff>0 ){
252904 i64 iDlRowid = fts5DlidxIterRowid(pDlidx);
252905 fts5GetVarint(&pLeaf->p[iRowidOff], (u64*)&iRowid);
252906 if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
252907 p->rc = FTS5_CORRUPT;
252908 }
252909 }
252910 fts5DataRelease(pLeaf);
252911 }
252912 }
@@ -253017,11 +253059,16 @@
253017 }
253018 }
253019 fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
253020
253021 fts5MultiIterFree(pIter);
253022 if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ) p->rc = FTS5_CORRUPT;
 
 
 
 
 
253023
253024 fts5StructureRelease(pStruct);
253025 #ifdef SQLITE_DEBUG
253026 fts5BufferFree(&term);
253027 #endif
@@ -257433,11 +257480,11 @@
257433 int nArg, /* Number of args */
257434 sqlite3_value **apUnused /* Function arguments */
257435 ){
257436 assert( nArg==0 );
257437 UNUSED_PARAM2(nArg, apUnused);
257438 sqlite3_result_text(pCtx, "fts5: 2025-06-23 16:51:33 cf61cd359e666c66b6bba4407a653c799f7f07e1f5ee6b837ad467029c461a6a", -1, SQLITE_TRANSIENT);
257439 }
257440
257441 /*
257442 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257443 **
@@ -257556,12 +257603,13 @@
257556 }else{
257557 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
257558 " FTS5 table %s.%s: %s",
257559 zSchema, zTabname, sqlite3_errstr(rc));
257560 }
 
 
257561 }
257562
257563 sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
257564 pTab->p.pConfig->pzErrmsg = 0;
257565
257566 return rc;
257567 }
257568
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 6a5701e6c7be25cba93e55438f950966e1da with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.51.0"
469 #define SQLITE_VERSION_NUMBER 3051000
470 #define SQLITE_SOURCE_ID "2025-06-24 15:58:32 6a5701e6c7be25cba93e55438f950966e1dacb32eb2b23a8acc8ac53da6f0a85"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -4479,19 +4479,19 @@
4479 ** The application does not need to worry about freeing the result.
4480 ** However, the error string might be overwritten or deallocated by
4481 ** subsequent calls to other SQLite interface functions.)^
4482 **
4483 ** ^The sqlite3_errstr(E) interface returns the English-language text
4484 ** that describes the [result code] E, as UTF-8, or NULL if E is not a
4485 ** result code for which a text error message is available.
4486 ** ^(Memory to hold the error message string is managed internally
4487 ** and must not be freed by the application)^.
4488 **
4489 ** ^If the most recent error references a specific token in the input
4490 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4491 ** of the start of that token. ^The byte offset returned by
4492 ** sqlite3_error_offset() assumes that the input SQL is UTF-8.
4493 ** ^If the most recent error does not reference a specific token in the input
4494 ** SQL, then the sqlite3_error_offset() function returns -1.
4495 **
4496 ** When the serialized [threading mode] is in use, it might be the
4497 ** case that a second error occurs on a separate thread in between
@@ -4586,12 +4586,12 @@
4586 ** CAPI3REF: Run-Time Limit Categories
4587 ** KEYWORDS: {limit category} {*limit categories}
4588 **
4589 ** These constants define various performance limits
4590 ** that can be lowered at run-time using [sqlite3_limit()].
4591 ** A concise description of these limits follows, and additional information
4592 ** is available at [limits | Limits in SQLite].
4593 **
4594 ** <dl>
4595 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4596 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4597 **
@@ -4652,11 +4652,11 @@
4652 #define SQLITE_LIMIT_WORKER_THREADS 11
4653
4654 /*
4655 ** CAPI3REF: Prepare Flags
4656 **
4657 ** These constants define various flags that can be passed into the
4658 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4659 ** [sqlite3_prepare16_v3()] interfaces.
4660 **
4661 ** New flags may be added in future releases of SQLite.
4662 **
@@ -4739,11 +4739,11 @@
4739 ** statement is generated.
4740 ** If the caller knows that the supplied string is nul-terminated, then
4741 ** there is a small performance advantage to passing an nByte parameter that
4742 ** is the number of bytes in the input string <i>including</i>
4743 ** the nul-terminator.
4744 ** Note that nByte measures the length of the input in bytes, not
4745 ** characters, even for the UTF-16 interfaces.
4746 **
4747 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4748 ** past the end of the first SQL statement in zSql. These routines only
4749 ** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4873,11 +4873,11 @@
4873 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4874 ** will return "SELECT 2345,NULL".)^
4875 **
4876 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4877 ** is available to hold the result, or if the result would exceed the
4878 ** maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4879 **
4880 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4881 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
4882 ** option causes sqlite3_expanded_sql() to always return NULL.
4883 **
@@ -5061,11 +5061,11 @@
5061 /*
5062 ** CAPI3REF: SQL Function Context Object
5063 **
5064 ** The context in which an SQL function executes is stored in an
5065 ** sqlite3_context object. ^A pointer to an sqlite3_context object
5066 ** is always the first parameter to [application-defined SQL functions].
5067 ** The application-defined SQL function implementation will pass this
5068 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
5069 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
5070 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
5071 ** and/or [sqlite3_set_auxdata()].
@@ -5798,11 +5798,11 @@
5798 ** CAPI3REF: Destroy A Prepared Statement Object
5799 ** DESTRUCTOR: sqlite3_stmt
5800 **
5801 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5802 ** ^If the most recent evaluation of the statement encountered no errors
5803 ** or if the statement has never been evaluated, then sqlite3_finalize() returns
5804 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
5805 ** sqlite3_finalize(S) returns the appropriate [error code] or
5806 ** [extended error code].
5807 **
5808 ** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -6030,11 +6030,11 @@
6030 );
6031
6032 /*
6033 ** CAPI3REF: Text Encodings
6034 **
6035 ** These constants define integer codes that represent the various
6036 ** text encodings supported by SQLite.
6037 */
6038 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
6039 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
6040 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -6122,11 +6122,11 @@
6122 ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
6123 ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
6124 ** result.
6125 ** Every function that invokes [sqlite3_result_subtype()] should have this
6126 ** property. If it does not, then the call to [sqlite3_result_subtype()]
6127 ** might become a no-op if the function is used as a term in an
6128 ** [expression index]. On the other hand, SQL functions that never invoke
6129 ** [sqlite3_result_subtype()] should avoid setting this property, as the
6130 ** purpose of this property is to disable certain optimizations that are
6131 ** incompatible with subtypes.
6132 **
@@ -6249,11 +6249,11 @@
6249 **
6250 ** ^Within the [xUpdate] method of a [virtual table], the
6251 ** sqlite3_value_nochange(X) interface returns true if and only if
6252 ** the column corresponding to X is unchanged by the UPDATE operation
6253 ** that the xUpdate method call was invoked to implement and if
6254 ** the prior [xColumn] method call that was invoked to extract
6255 ** the value for that column returned without setting a result (probably
6256 ** because it queried [sqlite3_vtab_nochange()] and found that the column
6257 ** was unchanging). ^Within an [xUpdate] method, any value for which
6258 ** sqlite3_value_nochange(X) is true will in all other respects appear
6259 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
@@ -93753,10 +93753,13 @@
93753 rc = SQLITE_MISUSE_BKPT;
93754 goto preupdate_old_out;
93755 }
93756 if( p->pPk ){
93757 iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
93758 }else if( iIdx >= p->pTab->nCol ){
93759 rc = SQLITE_MISUSE_BKPT;
93760 goto preupdate_old_out;
93761 }else{
93762 iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
93763 }
93764 if( iStore>=p->pCsr->nField || iStore<0 ){
93765 rc = SQLITE_RANGE;
@@ -244933,10 +244936,40 @@
244936 Fts5Buffer term; /* Current term */
244937 i64 iRowid; /* Current rowid */
244938 int nPos; /* Number of bytes in current position list */
244939 u8 bDel; /* True if the delete flag is set */
244940 };
244941
244942 static int fts5IndexCorruptRowid(Fts5Index *pIdx, i64 iRowid){
244943 pIdx->rc = FTS5_CORRUPT;
244944 sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
244945 "fts5: corruption found reading blob %lld from table \"%s\"",
244946 iRowid, pIdx->pConfig->zName
244947 );
244948 return SQLITE_CORRUPT_VTAB;
244949 }
244950 #define FTS5_CORRUPT_ROWID(pIdx, iRowid) fts5IndexCorruptRowid(pIdx, iRowid)
244951
244952 static int fts5IndexCorruptIter(Fts5Index *pIdx, Fts5SegIter *pIter){
244953 pIdx->rc = FTS5_CORRUPT;
244954 sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
244955 "fts5: corruption on page %d, segment %d, table \"%s\"",
244956 pIter->iLeafPgno, pIter->pSeg->iSegid, pIdx->pConfig->zName
244957 );
244958 return SQLITE_CORRUPT_VTAB;
244959 }
244960 #define FTS5_CORRUPT_ITER(pIdx, pIter) fts5IndexCorruptIter(pIdx, pIter)
244961
244962 static int fts5IndexCorruptIdx(Fts5Index *pIdx){
244963 pIdx->rc = FTS5_CORRUPT;
244964 sqlite3Fts5ConfigErrmsg(pIdx->pConfig,
244965 "fts5: corruption in table \"%s\"", pIdx->pConfig->zName
244966 );
244967 return SQLITE_CORRUPT_VTAB;
244968 }
244969 #define FTS5_CORRUPT_IDX(pIdx) fts5IndexCorruptIdx(pIdx)
244970
244971
244972 /*
244973 ** Array of tombstone pages. Reference counted.
244974 */
244975 struct Fts5TombstoneArray {
@@ -245223,11 +245256,11 @@
245256 /* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
245257 ** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
245258 ** All the reasons those functions might return SQLITE_ERROR - missing
245259 ** table, missing row, non-blob/text in block column - indicate
245260 ** backing store corruption. */
245261 if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT_ROWID(p, iRowid);
245262
245263 if( rc==SQLITE_OK ){
245264 u8 *aOut = 0; /* Read blob data into this buffer */
245265 int nByte = sqlite3_blob_bytes(p->pReader);
245266 int szData = (sizeof(Fts5Data) + 7) & ~7;
@@ -245273,11 +245306,11 @@
245306
245307 static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){
245308 Fts5Data *pRet = fts5DataRead(p, iRowid);
245309 if( pRet ){
245310 if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){
245311 FTS5_CORRUPT_ROWID(p, iRowid);
245312 fts5DataRelease(pRet);
245313 pRet = 0;
245314 }
245315 }
245316 return pRet;
@@ -245632,12 +245665,18 @@
245665 pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
245666 if( p->rc==SQLITE_OK ){
245667 /* TODO: Do we need this if the leaf-index is appended? Probably... */
245668 memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING);
245669 p->rc = fts5StructureDecode(pData->p, pData->nn, &iCookie, &pRet);
245670 if( p->rc==SQLITE_OK ){
245671 if( (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){
245672 p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
245673 }
245674 }else if( p->rc==SQLITE_CORRUPT_VTAB ){
245675 sqlite3Fts5ConfigErrmsg(p->pConfig,
245676 "fts5: corrupt structure record for table \"%s\"", p->pConfig->zName
245677 );
245678 }
245679 fts5DataRelease(pData);
245680 if( p->rc!=SQLITE_OK ){
245681 fts5StructureRelease(pRet);
245682 pRet = 0;
@@ -246256,11 +246295,11 @@
246295
246296 ASSERT_SZLEAF_OK(pIter->pLeaf);
246297 while( iOff>=pIter->pLeaf->szLeaf ){
246298 fts5SegIterNextPage(p, pIter);
246299 if( pIter->pLeaf==0 ){
246300 if( p->rc==SQLITE_OK ) FTS5_CORRUPT_ITER(p, pIter);
246301 return;
246302 }
246303 iOff = 4;
246304 a = pIter->pLeaf->p;
246305 }
@@ -246288,11 +246327,11 @@
246327 i64 iOff = pIter->iLeafOffset; /* Offset to read at */
246328 int nNew; /* Bytes of new data */
246329
246330 iOff += fts5GetVarint32(&a[iOff], nNew);
246331 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
246332 FTS5_CORRUPT_ITER(p, pIter);
246333 return;
246334 }
246335 pIter->term.n = nKeep;
246336 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
246337 assert( pIter->term.n<=pIter->term.nSpace );
@@ -246483,11 +246522,11 @@
246522 }else{
246523 int iRowidOff;
246524 iRowidOff = fts5LeafFirstRowidOff(pNew);
246525 if( iRowidOff ){
246526 if( iRowidOff>=pNew->szLeaf ){
246527 FTS5_CORRUPT_ITER(p, pIter);
246528 }else{
246529 pIter->pLeaf = pNew;
246530 pIter->iLeafOffset = iRowidOff;
246531 }
246532 }
@@ -246717,11 +246756,11 @@
246756 pIter->iEndofDoclist = iOff;
246757 bNewTerm = 1;
246758 }
246759 assert_nc( iOff<pLeaf->szLeaf );
246760 if( iOff>pLeaf->szLeaf ){
246761 FTS5_CORRUPT_ITER(p, pIter);
246762 return;
246763 }
246764 }
246765 }
246766
@@ -246827,11 +246866,11 @@
246866 fts5DataRelease(pIter->pLeaf);
246867 pIter->pLeaf = pLast;
246868 pIter->iLeafPgno = pgnoLast;
246869 iOff = fts5LeafFirstRowidOff(pLast);
246870 if( iOff>pLast->szLeaf ){
246871 FTS5_CORRUPT_ITER(p, pIter);
246872 return;
246873 }
246874 iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
246875 pIter->iLeafOffset = iOff;
246876
@@ -246906,11 +246945,11 @@
246945
246946 iPgidx = (u32)pIter->pLeaf->szLeaf;
246947 iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
246948 iOff = iTermOff;
246949 if( iOff>n ){
246950 FTS5_CORRUPT_ITER(p, pIter);
246951 return;
246952 }
246953
246954 while( 1 ){
246955
@@ -246949,11 +246988,11 @@
246988 iPgidx += fts5GetVarint32(&a[iPgidx], nKeep);
246989 iTermOff += nKeep;
246990 iOff = iTermOff;
246991
246992 if( iOff>=n ){
246993 FTS5_CORRUPT_ITER(p, pIter);
246994 return;
246995 }
246996
246997 /* Read the nKeep field of the next term. */
246998 fts5FastGetVarint32(a, iOff, nKeep);
@@ -246971,11 +247010,11 @@
247010 a = pIter->pLeaf->p;
247011 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
247012 iPgidx = (u32)pIter->pLeaf->szLeaf;
247013 iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
247014 if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
247015 FTS5_CORRUPT_ITER(p, pIter);
247016 return;
247017 }else{
247018 nKeep = 0;
247019 iTermOff = iOff;
247020 n = (u32)pIter->pLeaf->nn;
@@ -246986,11 +247025,11 @@
247025 }while( 1 );
247026 }
247027
247028 search_success:
247029 if( (i64)iOff+nNew>n || nNew<1 ){
247030 FTS5_CORRUPT_ITER(p, pIter);
247031 return;
247032 }
247033 pIter->iLeafOffset = iOff + nNew;
247034 pIter->iTermLeafOffset = pIter->iLeafOffset;
247035 pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -247451,11 +247490,11 @@
247490 int iLeafPgno
247491 ){
247492 assert( iLeafPgno>pIter->iLeafPgno );
247493
247494 if( iLeafPgno>pIter->pSeg->pgnoLast ){
247495 FTS5_CORRUPT_IDX(p);
247496 }else{
247497 fts5DataRelease(pIter->pNextLeaf);
247498 pIter->pNextLeaf = 0;
247499 pIter->iLeafPgno = iLeafPgno-1;
247500
@@ -247466,11 +247505,11 @@
247505 iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
247506 if( iOff>0 ){
247507 u8 *a = pIter->pLeaf->p;
247508 int n = pIter->pLeaf->szLeaf;
247509 if( iOff<4 || iOff>=n ){
247510 FTS5_CORRUPT_IDX(p);
247511 }else{
247512 iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
247513 pIter->iLeafOffset = iOff;
247514 fts5SegIterLoadNPos(p, pIter);
247515 }
@@ -247945,11 +247984,11 @@
247984 nRem -= nChunk;
247985 fts5DataRelease(pData);
247986 if( nRem<=0 ){
247987 break;
247988 }else if( pSeg->pSeg==0 ){
247989 FTS5_CORRUPT_IDX(p);
247990 return;
247991 }else{
247992 pgno++;
247993 pData = fts5LeafRead(p, FTS5_SEGMENT_ROWID(pSeg->pSeg->iSegid, pgno));
247994 if( pData==0 ) break;
@@ -249048,11 +249087,11 @@
249087 if( iOff>pData->szLeaf ){
249088 /* This can occur if the pages that the segments occupy overlap - if
249089 ** a single page has been assigned to more than one segment. In
249090 ** this case a prior iteration of this loop may have corrupted the
249091 ** segment currently being trimmed. */
249092 FTS5_CORRUPT_ROWID(p, iLeafRowid);
249093 }else{
249094 fts5BufferZero(&buf);
249095 fts5BufferGrow(&p->rc, &buf, pData->nn);
249096 fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
249097 fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
@@ -249515,11 +249554,11 @@
249554 fts5DataRelease(pLeaf);
249555 pLeaf = 0;
249556 }else if( bDetailNone ){
249557 break;
249558 }else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){
249559 FTS5_CORRUPT_ROWID(p, iRowid);
249560 break;
249561 }else{
249562 int nShift = iNext - 4;
249563 int nPg;
249564
@@ -249535,11 +249574,11 @@
249574 int i1 = pLeaf->szLeaf;
249575 int i2 = 0;
249576
249577 i1 += fts5GetVarint32(&aPg[i1], iFirst);
249578 if( iFirst<iNext ){
249579 FTS5_CORRUPT_ROWID(p, iRowid);
249580 break;
249581 }
249582 aIdx = sqlite3Fts5MallocZero(&p->rc, (pLeaf->nn-pLeaf->szLeaf)+2);
249583 if( aIdx==0 ) break;
249584 i2 = sqlite3Fts5PutVarint(aIdx, iFirst-nShift);
@@ -249758,18 +249797,18 @@
249797
249798 nPrefix = MIN(nPrefix, nPrefix2);
249799 nSuffix = (nPrefix2 + nSuffix2) - nPrefix;
249800
249801 if( (iKeyOff+nSuffix)>iPgIdx || (iNextOff+nSuffix2)>iPgIdx ){
249802 FTS5_CORRUPT_IDX(p);
249803 }else{
249804 if( iKey!=1 ){
249805 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
249806 }
249807 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
249808 if( nPrefix2>pSeg->term.n ){
249809 FTS5_CORRUPT_IDX(p);
249810 }else if( nPrefix2>nPrefix ){
249811 memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
249812 iOff += (nPrefix2-nPrefix);
249813 }
249814 memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
@@ -250558,11 +250597,11 @@
250597 fts5PrefixMergerInsertByPosition(&pHead, pSave);
250598 pSave = pNext;
250599 }
250600
250601 if( pHead==0 || pHead->pNext==0 ){
250602 FTS5_CORRUPT_IDX(p);
250603 break;
250604 }
250605
250606 /* See the earlier comment in this function for an explanation of why
250607 ** corrupt input position lists might cause the output to consume
@@ -250595,11 +250634,11 @@
250634
250635 /* WRITEPOSLISTSIZE */
250636 assert_nc( tmp.n+nTail<=nTmp );
250637 assert( tmp.n+nTail<=nTmp+nMerge*10 );
250638 if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
250639 if( p->rc==SQLITE_OK ) FTS5_CORRUPT_IDX(p);
250640 break;
250641 }
250642 fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2);
250643 fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
250644 if( nTail>0 ){
@@ -252724,18 +252763,21 @@
252763 /* Now check that the iter.nEmpty leaves following the current leaf
252764 ** (a) exist and (b) contain no terms. */
252765 for(i=iFirst; p->rc==SQLITE_OK && i<=iLast; i++){
252766 Fts5Data *pLeaf = fts5DataRead(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
252767 if( pLeaf ){
252768 if( !fts5LeafIsTermless(pLeaf)
252769 || (i>=iNoRowid && 0!=fts5LeafFirstRowidOff(pLeaf))
252770 ){
252771 FTS5_CORRUPT_ROWID(p, FTS5_SEGMENT_ROWID(pSeg->iSegid, i));
252772 }
252773 }
252774 fts5DataRelease(pLeaf);
252775 }
252776 }
252777
252778 static void fts5IntegrityCheckPgidx(Fts5Index *p, i64 iRowid, Fts5Data *pLeaf){
252779 i64 iTermOff = 0;
252780 int ii;
252781
252782 Fts5Buffer buf1 = {0,0,0};
252783 Fts5Buffer buf2 = {0,0,0};
@@ -252749,33 +252791,33 @@
252791 ii += fts5GetVarint32(&pLeaf->p[ii], nIncr);
252792 iTermOff += nIncr;
252793 iOff = iTermOff;
252794
252795 if( iOff>=pLeaf->szLeaf ){
252796 FTS5_CORRUPT_ROWID(p, iRowid);
252797 }else if( iTermOff==nIncr ){
252798 int nByte;
252799 iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252800 if( (iOff+nByte)>pLeaf->szLeaf ){
252801 FTS5_CORRUPT_ROWID(p, iRowid);
252802 }else{
252803 fts5BufferSet(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252804 }
252805 }else{
252806 int nKeep, nByte;
252807 iOff += fts5GetVarint32(&pLeaf->p[iOff], nKeep);
252808 iOff += fts5GetVarint32(&pLeaf->p[iOff], nByte);
252809 if( nKeep>buf1.n || (iOff+nByte)>pLeaf->szLeaf ){
252810 FTS5_CORRUPT_ROWID(p, iRowid);
252811 }else{
252812 buf1.n = nKeep;
252813 fts5BufferAppendBlob(&p->rc, &buf1, nByte, &pLeaf->p[iOff]);
252814 }
252815
252816 if( p->rc==SQLITE_OK ){
252817 res = fts5BufferCompare(&buf1, &buf2);
252818 if( res<=0 ) FTS5_CORRUPT_ROWID(p, iRowid);
252819 }
252820 }
252821 fts5BufferSet(&p->rc, &buf2, buf1.n, buf1.p);
252822 }
252823
@@ -252832,11 +252874,11 @@
252874 ){
252875 /* special case - the very first page in a segment keeps its %_idx
252876 ** entry even if all the terms are removed from it by secure-delete
252877 ** operations. */
252878 }else{
252879 FTS5_CORRUPT_ROWID(p, iRow);
252880 }
252881
252882 }else{
252883 int iOff; /* Offset of first term on leaf */
252884 int iRowidOff; /* Offset of first rowid on leaf */
@@ -252844,19 +252886,19 @@
252886 int res; /* Comparison of term and split-key */
252887
252888 iOff = fts5LeafFirstTermOff(pLeaf);
252889 iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252890 if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
252891 FTS5_CORRUPT_ROWID(p, iRow);
252892 }else{
252893 iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
252894 res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
252895 if( res==0 ) res = nTerm - nIdxTerm;
252896 if( res<0 ) FTS5_CORRUPT_ROWID(p, iRow);
252897 }
252898
252899 fts5IntegrityCheckPgidx(p, iRow, pLeaf);
252900 }
252901 fts5DataRelease(pLeaf);
252902 if( p->rc ) break;
252903
252904 /* Now check that the iter.nEmpty leaves following the current leaf
@@ -252882,11 +252924,11 @@
252924 /* Check any rowid-less pages that occur before the current leaf. */
252925 for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){
252926 iKey = FTS5_SEGMENT_ROWID(iSegid, iPg);
252927 pLeaf = fts5DataRead(p, iKey);
252928 if( pLeaf ){
252929 if( fts5LeafFirstRowidOff(pLeaf)!=0 ) FTS5_CORRUPT_ROWID(p, iKey);
252930 fts5DataRelease(pLeaf);
252931 }
252932 }
252933 iPrevLeaf = fts5DlidxIterPgno(pDlidx);
252934
@@ -252897,16 +252939,16 @@
252939 if( pLeaf ){
252940 i64 iRowid;
252941 int iRowidOff = fts5LeafFirstRowidOff(pLeaf);
252942 ASSERT_SZLEAF_OK(pLeaf);
252943 if( iRowidOff>=pLeaf->szLeaf ){
252944 FTS5_CORRUPT_ROWID(p, iKey);
252945 }else if( bSecureDelete==0 || iRowidOff>0 ){
252946 i64 iDlRowid = fts5DlidxIterRowid(pDlidx);
252947 fts5GetVarint(&pLeaf->p[iRowidOff], (u64*)&iRowid);
252948 if( iRowid<iDlRowid || (bSecureDelete==0 && iRowid!=iDlRowid) ){
252949 FTS5_CORRUPT_ROWID(p, iKey);
252950 }
252951 }
252952 fts5DataRelease(pLeaf);
252953 }
252954 }
@@ -253017,11 +253059,16 @@
253059 }
253060 }
253061 fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
253062
253063 fts5MultiIterFree(pIter);
253064 if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ){
253065 p->rc = FTS5_CORRUPT;
253066 sqlite3Fts5ConfigErrmsg(p->pConfig,
253067 "fts5: checksum mismatch for table \"%s\"", p->pConfig->zName
253068 );
253069 }
253070
253071 fts5StructureRelease(pStruct);
253072 #ifdef SQLITE_DEBUG
253073 fts5BufferFree(&term);
253074 #endif
@@ -257433,11 +257480,11 @@
257480 int nArg, /* Number of args */
257481 sqlite3_value **apUnused /* Function arguments */
257482 ){
257483 assert( nArg==0 );
257484 UNUSED_PARAM2(nArg, apUnused);
257485 sqlite3_result_text(pCtx, "fts5: 2025-06-24 15:58:32 6a5701e6c7be25cba93e55438f950966e1dacb32eb2b23a8acc8ac53da6f0a85", -1, SQLITE_TRANSIENT);
257486 }
257487
257488 /*
257489 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257490 **
@@ -257556,12 +257603,13 @@
257603 }else{
257604 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
257605 " FTS5 table %s.%s: %s",
257606 zSchema, zTabname, sqlite3_errstr(rc));
257607 }
257608 }else if( (rc&0xff)==SQLITE_CORRUPT ){
257609 rc = SQLITE_OK;
257610 }
 
257611 sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
257612 pTab->p.pConfig->pzErrmsg = 0;
257613
257614 return rc;
257615 }
257616
+13 -13
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.51.0"
150150
#define SQLITE_VERSION_NUMBER 3051000
151
-#define SQLITE_SOURCE_ID "2025-06-23 16:51:33 cf61cd359e666c66b6bba4407a653c799f7f07e1f5ee6b837ad467029c461a6a"
151
+#define SQLITE_SOURCE_ID "2025-06-24 15:58:32 6a5701e6c7be25cba93e55438f950966e1dacb32eb2b23a8acc8ac53da6f0a85"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -4160,19 +4160,19 @@
41604160
** The application does not need to worry about freeing the result.
41614161
** However, the error string might be overwritten or deallocated by
41624162
** subsequent calls to other SQLite interface functions.)^
41634163
**
41644164
** ^The sqlite3_errstr(E) interface returns the English-language text
4165
-** that describes the [result code] E, as UTF-8, or NULL if E is not an
4165
+** that describes the [result code] E, as UTF-8, or NULL if E is not a
41664166
** result code for which a text error message is available.
41674167
** ^(Memory to hold the error message string is managed internally
41684168
** and must not be freed by the application)^.
41694169
**
41704170
** ^If the most recent error references a specific token in the input
41714171
** SQL, the sqlite3_error_offset() interface returns the byte offset
41724172
** of the start of that token. ^The byte offset returned by
4173
-** sqlite3_error_offset() assumes that the input SQL is UTF8.
4173
+** sqlite3_error_offset() assumes that the input SQL is UTF-8.
41744174
** ^If the most recent error does not reference a specific token in the input
41754175
** SQL, then the sqlite3_error_offset() function returns -1.
41764176
**
41774177
** When the serialized [threading mode] is in use, it might be the
41784178
** case that a second error occurs on a separate thread in between
@@ -4267,12 +4267,12 @@
42674267
** CAPI3REF: Run-Time Limit Categories
42684268
** KEYWORDS: {limit category} {*limit categories}
42694269
**
42704270
** These constants define various performance limits
42714271
** that can be lowered at run-time using [sqlite3_limit()].
4272
-** The synopsis of the meanings of the various limits is shown below.
4273
-** Additional information is available at [limits | Limits in SQLite].
4272
+** A concise description of these limits follows, and additional information
4273
+** is available at [limits | Limits in SQLite].
42744274
**
42754275
** <dl>
42764276
** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
42774277
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
42784278
**
@@ -4333,11 +4333,11 @@
43334333
#define SQLITE_LIMIT_WORKER_THREADS 11
43344334
43354335
/*
43364336
** CAPI3REF: Prepare Flags
43374337
**
4338
-** These constants define various flags that can be passed into
4338
+** These constants define various flags that can be passed into the
43394339
** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
43404340
** [sqlite3_prepare16_v3()] interfaces.
43414341
**
43424342
** New flags may be added in future releases of SQLite.
43434343
**
@@ -4420,11 +4420,11 @@
44204420
** statement is generated.
44214421
** If the caller knows that the supplied string is nul-terminated, then
44224422
** there is a small performance advantage to passing an nByte parameter that
44234423
** is the number of bytes in the input string <i>including</i>
44244424
** the nul-terminator.
4425
-** Note that nByte measure the length of the input in bytes, not
4425
+** Note that nByte measures the length of the input in bytes, not
44264426
** characters, even for the UTF-16 interfaces.
44274427
**
44284428
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
44294429
** past the end of the first SQL statement in zSql. These routines only
44304430
** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4554,11 +4554,11 @@
45544554
** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
45554555
** will return "SELECT 2345,NULL".)^
45564556
**
45574557
** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
45584558
** is available to hold the result, or if the result would exceed the
4559
-** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4559
+** maximum string length determined by the [SQLITE_LIMIT_LENGTH].
45604560
**
45614561
** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
45624562
** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
45634563
** option causes sqlite3_expanded_sql() to always return NULL.
45644564
**
@@ -4742,11 +4742,11 @@
47424742
/*
47434743
** CAPI3REF: SQL Function Context Object
47444744
**
47454745
** The context in which an SQL function executes is stored in an
47464746
** sqlite3_context object. ^A pointer to an sqlite3_context object
4747
-** is always first parameter to [application-defined SQL functions].
4747
+** is always the first parameter to [application-defined SQL functions].
47484748
** The application-defined SQL function implementation will pass this
47494749
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
47504750
** [sqlite3_aggregate_context()], [sqlite3_user_data()],
47514751
** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
47524752
** and/or [sqlite3_set_auxdata()].
@@ -5479,11 +5479,11 @@
54795479
** CAPI3REF: Destroy A Prepared Statement Object
54805480
** DESTRUCTOR: sqlite3_stmt
54815481
**
54825482
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
54835483
** ^If the most recent evaluation of the statement encountered no errors
5484
-** or if the statement is never been evaluated, then sqlite3_finalize() returns
5484
+** or if the statement has never been evaluated, then sqlite3_finalize() returns
54855485
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
54865486
** sqlite3_finalize(S) returns the appropriate [error code] or
54875487
** [extended error code].
54885488
**
54895489
** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -5711,11 +5711,11 @@
57115711
);
57125712
57135713
/*
57145714
** CAPI3REF: Text Encodings
57155715
**
5716
-** These constant define integer codes that represent the various
5716
+** These constants define integer codes that represent the various
57175717
** text encodings supported by SQLite.
57185718
*/
57195719
#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
57205720
#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
57215721
#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -5803,11 +5803,11 @@
58035803
** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
58045804
** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
58055805
** result.
58065806
** Every function that invokes [sqlite3_result_subtype()] should have this
58075807
** property. If it does not, then the call to [sqlite3_result_subtype()]
5808
-** might become a no-op if the function is used as term in an
5808
+** might become a no-op if the function is used as a term in an
58095809
** [expression index]. On the other hand, SQL functions that never invoke
58105810
** [sqlite3_result_subtype()] should avoid setting this property, as the
58115811
** purpose of this property is to disable certain optimizations that are
58125812
** incompatible with subtypes.
58135813
**
@@ -5930,11 +5930,11 @@
59305930
**
59315931
** ^Within the [xUpdate] method of a [virtual table], the
59325932
** sqlite3_value_nochange(X) interface returns true if and only if
59335933
** the column corresponding to X is unchanged by the UPDATE operation
59345934
** that the xUpdate method call was invoked to implement and if
5935
-** and the prior [xColumn] method call that was invoked to extracted
5935
+** the prior [xColumn] method call that was invoked to extract
59365936
** the value for that column returned without setting a result (probably
59375937
** because it queried [sqlite3_vtab_nochange()] and found that the column
59385938
** was unchanging). ^Within an [xUpdate] method, any value for which
59395939
** sqlite3_value_nochange(X) is true will in all other respects appear
59405940
** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
59415941
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-06-23 16:51:33 cf61cd359e666c66b6bba4407a653c799f7f07e1f5ee6b837ad467029c461a6a"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -4160,19 +4160,19 @@
4160 ** The application does not need to worry about freeing the result.
4161 ** However, the error string might be overwritten or deallocated by
4162 ** subsequent calls to other SQLite interface functions.)^
4163 **
4164 ** ^The sqlite3_errstr(E) interface returns the English-language text
4165 ** that describes the [result code] E, as UTF-8, or NULL if E is not an
4166 ** result code for which a text error message is available.
4167 ** ^(Memory to hold the error message string is managed internally
4168 ** and must not be freed by the application)^.
4169 **
4170 ** ^If the most recent error references a specific token in the input
4171 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4172 ** of the start of that token. ^The byte offset returned by
4173 ** sqlite3_error_offset() assumes that the input SQL is UTF8.
4174 ** ^If the most recent error does not reference a specific token in the input
4175 ** SQL, then the sqlite3_error_offset() function returns -1.
4176 **
4177 ** When the serialized [threading mode] is in use, it might be the
4178 ** case that a second error occurs on a separate thread in between
@@ -4267,12 +4267,12 @@
4267 ** CAPI3REF: Run-Time Limit Categories
4268 ** KEYWORDS: {limit category} {*limit categories}
4269 **
4270 ** These constants define various performance limits
4271 ** that can be lowered at run-time using [sqlite3_limit()].
4272 ** The synopsis of the meanings of the various limits is shown below.
4273 ** Additional information is available at [limits | Limits in SQLite].
4274 **
4275 ** <dl>
4276 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4277 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4278 **
@@ -4333,11 +4333,11 @@
4333 #define SQLITE_LIMIT_WORKER_THREADS 11
4334
4335 /*
4336 ** CAPI3REF: Prepare Flags
4337 **
4338 ** These constants define various flags that can be passed into
4339 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4340 ** [sqlite3_prepare16_v3()] interfaces.
4341 **
4342 ** New flags may be added in future releases of SQLite.
4343 **
@@ -4420,11 +4420,11 @@
4420 ** statement is generated.
4421 ** If the caller knows that the supplied string is nul-terminated, then
4422 ** there is a small performance advantage to passing an nByte parameter that
4423 ** is the number of bytes in the input string <i>including</i>
4424 ** the nul-terminator.
4425 ** Note that nByte measure the length of the input in bytes, not
4426 ** characters, even for the UTF-16 interfaces.
4427 **
4428 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4429 ** past the end of the first SQL statement in zSql. These routines only
4430 ** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4554,11 +4554,11 @@
4554 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4555 ** will return "SELECT 2345,NULL".)^
4556 **
4557 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4558 ** is available to hold the result, or if the result would exceed the
4559 ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4560 **
4561 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4562 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
4563 ** option causes sqlite3_expanded_sql() to always return NULL.
4564 **
@@ -4742,11 +4742,11 @@
4742 /*
4743 ** CAPI3REF: SQL Function Context Object
4744 **
4745 ** The context in which an SQL function executes is stored in an
4746 ** sqlite3_context object. ^A pointer to an sqlite3_context object
4747 ** is always first parameter to [application-defined SQL functions].
4748 ** The application-defined SQL function implementation will pass this
4749 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
4750 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
4751 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
4752 ** and/or [sqlite3_set_auxdata()].
@@ -5479,11 +5479,11 @@
5479 ** CAPI3REF: Destroy A Prepared Statement Object
5480 ** DESTRUCTOR: sqlite3_stmt
5481 **
5482 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5483 ** ^If the most recent evaluation of the statement encountered no errors
5484 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
5485 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
5486 ** sqlite3_finalize(S) returns the appropriate [error code] or
5487 ** [extended error code].
5488 **
5489 ** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -5711,11 +5711,11 @@
5711 );
5712
5713 /*
5714 ** CAPI3REF: Text Encodings
5715 **
5716 ** These constant define integer codes that represent the various
5717 ** text encodings supported by SQLite.
5718 */
5719 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
5720 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
5721 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -5803,11 +5803,11 @@
5803 ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
5804 ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
5805 ** result.
5806 ** Every function that invokes [sqlite3_result_subtype()] should have this
5807 ** property. If it does not, then the call to [sqlite3_result_subtype()]
5808 ** might become a no-op if the function is used as term in an
5809 ** [expression index]. On the other hand, SQL functions that never invoke
5810 ** [sqlite3_result_subtype()] should avoid setting this property, as the
5811 ** purpose of this property is to disable certain optimizations that are
5812 ** incompatible with subtypes.
5813 **
@@ -5930,11 +5930,11 @@
5930 **
5931 ** ^Within the [xUpdate] method of a [virtual table], the
5932 ** sqlite3_value_nochange(X) interface returns true if and only if
5933 ** the column corresponding to X is unchanged by the UPDATE operation
5934 ** that the xUpdate method call was invoked to implement and if
5935 ** and the prior [xColumn] method call that was invoked to extracted
5936 ** the value for that column returned without setting a result (probably
5937 ** because it queried [sqlite3_vtab_nochange()] and found that the column
5938 ** was unchanging). ^Within an [xUpdate] method, any value for which
5939 ** sqlite3_value_nochange(X) is true will in all other respects appear
5940 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
5941
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-06-24 15:58:32 6a5701e6c7be25cba93e55438f950966e1dacb32eb2b23a8acc8ac53da6f0a85"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -4160,19 +4160,19 @@
4160 ** The application does not need to worry about freeing the result.
4161 ** However, the error string might be overwritten or deallocated by
4162 ** subsequent calls to other SQLite interface functions.)^
4163 **
4164 ** ^The sqlite3_errstr(E) interface returns the English-language text
4165 ** that describes the [result code] E, as UTF-8, or NULL if E is not a
4166 ** result code for which a text error message is available.
4167 ** ^(Memory to hold the error message string is managed internally
4168 ** and must not be freed by the application)^.
4169 **
4170 ** ^If the most recent error references a specific token in the input
4171 ** SQL, the sqlite3_error_offset() interface returns the byte offset
4172 ** of the start of that token. ^The byte offset returned by
4173 ** sqlite3_error_offset() assumes that the input SQL is UTF-8.
4174 ** ^If the most recent error does not reference a specific token in the input
4175 ** SQL, then the sqlite3_error_offset() function returns -1.
4176 **
4177 ** When the serialized [threading mode] is in use, it might be the
4178 ** case that a second error occurs on a separate thread in between
@@ -4267,12 +4267,12 @@
4267 ** CAPI3REF: Run-Time Limit Categories
4268 ** KEYWORDS: {limit category} {*limit categories}
4269 **
4270 ** These constants define various performance limits
4271 ** that can be lowered at run-time using [sqlite3_limit()].
4272 ** A concise description of these limits follows, and additional information
4273 ** is available at [limits | Limits in SQLite].
4274 **
4275 ** <dl>
4276 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4277 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4278 **
@@ -4333,11 +4333,11 @@
4333 #define SQLITE_LIMIT_WORKER_THREADS 11
4334
4335 /*
4336 ** CAPI3REF: Prepare Flags
4337 **
4338 ** These constants define various flags that can be passed into the
4339 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4340 ** [sqlite3_prepare16_v3()] interfaces.
4341 **
4342 ** New flags may be added in future releases of SQLite.
4343 **
@@ -4420,11 +4420,11 @@
4420 ** statement is generated.
4421 ** If the caller knows that the supplied string is nul-terminated, then
4422 ** there is a small performance advantage to passing an nByte parameter that
4423 ** is the number of bytes in the input string <i>including</i>
4424 ** the nul-terminator.
4425 ** Note that nByte measures the length of the input in bytes, not
4426 ** characters, even for the UTF-16 interfaces.
4427 **
4428 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4429 ** past the end of the first SQL statement in zSql. These routines only
4430 ** compile the first statement in zSql, so *pzTail is left pointing to
@@ -4554,11 +4554,11 @@
4554 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4555 ** will return "SELECT 2345,NULL".)^
4556 **
4557 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4558 ** is available to hold the result, or if the result would exceed the
4559 ** maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4560 **
4561 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4562 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
4563 ** option causes sqlite3_expanded_sql() to always return NULL.
4564 **
@@ -4742,11 +4742,11 @@
4742 /*
4743 ** CAPI3REF: SQL Function Context Object
4744 **
4745 ** The context in which an SQL function executes is stored in an
4746 ** sqlite3_context object. ^A pointer to an sqlite3_context object
4747 ** is always the first parameter to [application-defined SQL functions].
4748 ** The application-defined SQL function implementation will pass this
4749 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
4750 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
4751 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
4752 ** and/or [sqlite3_set_auxdata()].
@@ -5479,11 +5479,11 @@
5479 ** CAPI3REF: Destroy A Prepared Statement Object
5480 ** DESTRUCTOR: sqlite3_stmt
5481 **
5482 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5483 ** ^If the most recent evaluation of the statement encountered no errors
5484 ** or if the statement has never been evaluated, then sqlite3_finalize() returns
5485 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
5486 ** sqlite3_finalize(S) returns the appropriate [error code] or
5487 ** [extended error code].
5488 **
5489 ** ^The sqlite3_finalize(S) routine can be called at any point during
@@ -5711,11 +5711,11 @@
5711 );
5712
5713 /*
5714 ** CAPI3REF: Text Encodings
5715 **
5716 ** These constants define integer codes that represent the various
5717 ** text encodings supported by SQLite.
5718 */
5719 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
5720 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
5721 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
@@ -5803,11 +5803,11 @@
5803 ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
5804 ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
5805 ** result.
5806 ** Every function that invokes [sqlite3_result_subtype()] should have this
5807 ** property. If it does not, then the call to [sqlite3_result_subtype()]
5808 ** might become a no-op if the function is used as a term in an
5809 ** [expression index]. On the other hand, SQL functions that never invoke
5810 ** [sqlite3_result_subtype()] should avoid setting this property, as the
5811 ** purpose of this property is to disable certain optimizations that are
5812 ** incompatible with subtypes.
5813 **
@@ -5930,11 +5930,11 @@
5930 **
5931 ** ^Within the [xUpdate] method of a [virtual table], the
5932 ** sqlite3_value_nochange(X) interface returns true if and only if
5933 ** the column corresponding to X is unchanged by the UPDATE operation
5934 ** that the xUpdate method call was invoked to implement and if
5935 ** the prior [xColumn] method call that was invoked to extract
5936 ** the value for that column returned without setting a result (probably
5937 ** because it queried [sqlite3_vtab_nochange()] and found that the column
5938 ** was unchanging). ^Within an [xUpdate] method, any value for which
5939 ** sqlite3_value_nochange(X) is true will in all other respects appear
5940 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
5941

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button