@@ -1166,7 +1166,7 @@ static int fts5StructureDecode(
11661166 i += fts5GetVarint32 (& pData [i ], nTotal );
11671167 if ( nTotal < pLvl -> nMerge ) rc = FTS5_CORRUPT ;
11681168 pLvl -> aSeg = (Fts5StructureSegment * )sqlite3Fts5MallocZero (& rc ,
1169- nTotal * sizeof (Fts5StructureSegment )
1169+ ( i64 ) nTotal * sizeof (Fts5StructureSegment )
11701170 );
11711171 nSegment -= nTotal ;
11721172 }
@@ -2122,7 +2122,7 @@ static void fts5SegIterReverseNewPage(Fts5Index *p, Fts5SegIter *pIter){
21222122 while ( p -> rc == SQLITE_OK && pIter -> iLeafPgno > pIter -> iTermLeafPgno ){
21232123 Fts5Data * pNew ;
21242124 pIter -> iLeafPgno -- ;
2125- pNew = fts5DataRead (p , FTS5_SEGMENT_ROWID (
2125+ pNew = fts5LeafRead (p , FTS5_SEGMENT_ROWID (
21262126 pIter -> pSeg -> iSegid , pIter -> iLeafPgno
21272127 ));
21282128 if ( pNew ){
@@ -7990,8 +7990,8 @@ static void fts5IndexTombstoneRebuild(
79907990){
79917991 const int MINSLOT = 32 ;
79927992 int nSlotPerPage = MAX (MINSLOT , (p -> pConfig -> pgsz - 8 ) / szKey );
7993- int nSlot = 0 ; /* Number of slots in each output page */
7994- int nOut = 0 ;
7993+ i64 nSlot = 0 ; /* Number of slots in each output page */
7994+ i64 nOut = 0 ;
79957995
79967996 /* Figure out how many output pages (nOut) and how many slots per
79977997 ** page (nSlot). There are three possibilities:
@@ -8016,23 +8016,26 @@ static void fts5IndexTombstoneRebuild(
80168016 nSlot = MINSLOT ;
80178017 }else if ( pSeg -> nPgTombstone == 1 ){
80188018 /* Case 2. */
8019- int nElem = ( int ) fts5GetU32 (& pData1 -> p [4 ]);
8019+ u32 nElem = fts5GetU32 (& pData1 -> p [4 ]);
80208020 assert ( pData1 && iPg1 == 0 );
8021- nOut = 1 ;
8022- nSlot = MAX (nElem * 4 , MINSLOT );
8023- if ( nSlot > nSlotPerPage ) nOut = 0 ;
8021+ if ( nElem > ((u32 )nSlotPerPage /4 ) ){
8022+ nOut = 0 ;
8023+ }else {
8024+ nOut = 1 ;
8025+ nSlot = MAX ((i64 )nElem * 4 , MINSLOT );
8026+ }
80248027 }
80258028 if ( nOut == 0 ){
80268029 /* Case 3. */
8027- nOut = (pSeg -> nPgTombstone * 2 + 1 );
8030+ nOut = (( i64 ) pSeg -> nPgTombstone * 2 + 1 );
80288031 nSlot = nSlotPerPage ;
80298032 }
80308033
80318034 /* Allocate the required array and output pages */
80328035 while ( 1 ){
80338036 int res = 0 ;
8034- int ii = 0 ;
8035- int szPage = 0 ;
8037+ i64 ii = 0 ;
8038+ i64 szPage = 0 ;
80368039 Fts5Data * * apOut = 0 ;
80378040
80388041 /* Allocate space for the new hash table */
@@ -8537,9 +8540,13 @@ static void fts5IndexIntegrityCheckSegment(
85378540 FTS5_CORRUPT_ROWID (p , iRow );
85388541 }else {
85398542 iOff += fts5GetVarint32 (& pLeaf -> p [iOff ], nTerm );
8540- res = fts5Memcmp (& pLeaf -> p [iOff ], zIdxTerm , MIN (nTerm , nIdxTerm ));
8541- if ( res == 0 ) res = nTerm - nIdxTerm ;
8542- if ( res < 0 ) FTS5_CORRUPT_ROWID (p , iRow );
8543+ if ( iOff + nTerm > pLeaf -> szLeaf ){
8544+ FTS5_CORRUPT_ROWID (p , iRow );
8545+ }else {
8546+ res = fts5Memcmp (& pLeaf -> p [iOff ], zIdxTerm , MIN (nTerm , nIdxTerm ));
8547+ if ( res == 0 ) res = nTerm - nIdxTerm ;
8548+ if ( res < 0 ) FTS5_CORRUPT_ROWID (p , iRow );
8549+ }
85438550 }
85448551
85458552 fts5IntegrityCheckPgidx (p , iRow , pLeaf );
@@ -8570,7 +8577,7 @@ static void fts5IndexIntegrityCheckSegment(
85708577 /* Check any rowid-less pages that occur before the current leaf. */
85718578 for (iPg = iPrevLeaf + 1 ; iPg < fts5DlidxIterPgno (pDlidx ); iPg ++ ){
85728579 iKey = FTS5_SEGMENT_ROWID (iSegid , iPg );
8573- pLeaf = fts5DataRead (p , iKey );
8580+ pLeaf = fts5LeafRead (p , iKey );
85748581 if ( pLeaf ){
85758582 if ( fts5LeafFirstRowidOff (pLeaf )!= 0 ) FTS5_CORRUPT_ROWID (p , iKey );
85768583 fts5DataRelease (pLeaf );
@@ -8581,7 +8588,7 @@ static void fts5IndexIntegrityCheckSegment(
85818588 /* Check that the leaf page indicated by the iterator really does
85828589 ** contain the rowid suggested by the same. */
85838590 iKey = FTS5_SEGMENT_ROWID (iSegid , iPrevLeaf );
8584- pLeaf = fts5DataRead (p , iKey );
8591+ pLeaf = fts5LeafRead (p , iKey );
85858592 if ( pLeaf ){
85868593 i64 iRowid ;
85878594 int iRowidOff = fts5LeafFirstRowidOff (pLeaf );
0 commit comments