mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Reformat WAL code for clearer presentation. Update comments for correctness.
Add checks to ensure that corruption in shared-memory does not result in an infinite loop. FossilOrigin-Name: 40eaada7ec45e70bdf64d060051f24c5c5e3faf3
This commit is contained in:
18
manifest
18
manifest
@@ -1,8 +1,8 @@
|
|||||||
-----BEGIN PGP SIGNED MESSAGE-----
|
-----BEGIN PGP SIGNED MESSAGE-----
|
||||||
Hash: SHA1
|
Hash: SHA1
|
||||||
|
|
||||||
C Add\sa\stest\scase\sto\scover\scode\sthat\swas\sleft\suntested\sby\sthe\sjournal_mode\nsimplification.
|
C Reformat\sWAL\scode\sfor\sclearer\spresentation.\s\sUpdate\scomments\sfor\scorrectness.\nAdd\schecks\sto\sensure\sthat\scorruption\sin\sshared-memory\sdoes\snot\sresult\sin\nan\sinfinite\sloop.
|
||||||
D 2010-07-08T19:19:51
|
D 2010-07-09T03:19:07
|
||||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||||
F Makefile.in c4270a1cd7cd70a263b7e96a258aa90e9c3618eb
|
F Makefile.in c4270a1cd7cd70a263b7e96a258aa90e9c3618eb
|
||||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||||
@@ -229,7 +229,7 @@ F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256
|
|||||||
F src/vdbemem.c 5e579abf6532001dfbee0e640dc34eae897a9807
|
F src/vdbemem.c 5e579abf6532001dfbee0e640dc34eae897a9807
|
||||||
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
|
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
|
||||||
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
|
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
|
||||||
F src/wal.c 5a58352aee4fb0546f4b94f8527a06300531bae9
|
F src/wal.c 0cd5cd46df9237671def76abaf8152af4bd4128e
|
||||||
F src/wal.h 906c85760598b18584921fe08008435aa4eeeeb2
|
F src/wal.h 906c85760598b18584921fe08008435aa4eeeeb2
|
||||||
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
|
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
|
||||||
F src/where.c 926c83c6394e132a1c62b6b12ceeba7d55a34c19
|
F src/where.c 926c83c6394e132a1c62b6b12ceeba7d55a34c19
|
||||||
@@ -835,14 +835,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
|||||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||||
P aef26438523bccf1ea2c19205cd05799e4c69a1f
|
P bcdddba4f011cf008d29918bcac59131007a8138
|
||||||
R 95f7318feaa66a8b78205d887e6d1438
|
R 5e19b5fcbb0a4bb30775e5e30106627d
|
||||||
U drh
|
U drh
|
||||||
Z 04e790b790d53c3d8a934d95e1981b36
|
Z 4cec72d41693a1e955d49c74ad6f997b
|
||||||
-----BEGIN PGP SIGNATURE-----
|
-----BEGIN PGP SIGNATURE-----
|
||||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
Version: GnuPG v1.4.6 (GNU/Linux)
|
||||||
|
|
||||||
iD8DBQFMNiTboxKgR168RlERAkDBAJ0RhukLRTBMs1DtkngKJab4oKQ5ywCgg48P
|
iD8DBQFMNpUuoxKgR168RlERAq/pAJ97NzUyxw7J6MN7JJON213vZ349xQCeOtGo
|
||||||
LJSpxRhRYLMurIbiJuDHwuo=
|
gYdze9fjpunjGvwfhDWNebg=
|
||||||
=eiHk
|
=jEhp
|
||||||
-----END PGP SIGNATURE-----
|
-----END PGP SIGNATURE-----
|
||||||
|
@@ -1 +1 @@
|
|||||||
bcdddba4f011cf008d29918bcac59131007a8138
|
40eaada7ec45e70bdf64d060051f24c5c5e3faf3
|
28
src/wal.c
28
src/wal.c
@@ -502,7 +502,8 @@ static int walIndexPage(Wal *pWal, int iPage, volatile u32 **ppPage){
|
|||||||
*ppPage = 0;
|
*ppPage = 0;
|
||||||
return SQLITE_NOMEM;
|
return SQLITE_NOMEM;
|
||||||
}
|
}
|
||||||
memset((void *)&apNew[pWal->nWiData], 0, sizeof(u32 *)*(iPage+1-pWal->nWiData));
|
memset((void*)&apNew[pWal->nWiData], 0,
|
||||||
|
sizeof(u32*)*(iPage+1-pWal->nWiData));
|
||||||
pWal->apWiData = apNew;
|
pWal->apWiData = apNew;
|
||||||
pWal->nWiData = iPage+1;
|
pWal->nWiData = iPage+1;
|
||||||
}
|
}
|
||||||
@@ -678,9 +679,10 @@ static int walDecodeFrame(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A frame is only valid if a checksum of the first 16 bytes
|
/* A frame is only valid if a checksum of the WAL header,
|
||||||
** of the frame-header, and the frame-data matches
|
** all prior frams, the first 16 bytes of this frame-header,
|
||||||
** the checksum in the last 8 bytes of the frame-header.
|
** and the frame-data matches the checksum in the last 8
|
||||||
|
** bytes of this frame-header.
|
||||||
*/
|
*/
|
||||||
nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN);
|
nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN);
|
||||||
walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum);
|
walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum);
|
||||||
@@ -940,7 +942,7 @@ static int walIndexAppend(Wal *pWal, u32 iFrame, u32 iPage){
|
|||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
int iKey; /* Hash table key */
|
int iKey; /* Hash table key */
|
||||||
int idx; /* Value to write to hash-table slot */
|
int idx; /* Value to write to hash-table slot */
|
||||||
TESTONLY( int nCollide = 0; /* Number of hash collisions */ )
|
int nCollide; /* Number of hash collisions */
|
||||||
|
|
||||||
idx = iFrame - iZero;
|
idx = iFrame - iZero;
|
||||||
assert( idx <= HASHTABLE_NSLOT/2 + 1 );
|
assert( idx <= HASHTABLE_NSLOT/2 + 1 );
|
||||||
@@ -965,8 +967,9 @@ static int walIndexAppend(Wal *pWal, u32 iFrame, u32 iPage){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write the aPgno[] array entry and the hash-table slot. */
|
/* Write the aPgno[] array entry and the hash-table slot. */
|
||||||
|
nCollide = idx;
|
||||||
for(iKey=walHash(iPage); aHash[iKey]; iKey=walNextHash(iKey)){
|
for(iKey=walHash(iPage); aHash[iKey]; iKey=walNextHash(iKey)){
|
||||||
assert( nCollide++ < idx );
|
if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT;
|
||||||
}
|
}
|
||||||
aPgno[idx] = iPage;
|
aPgno[idx] = iPage;
|
||||||
aHash[iKey] = (ht_slot)idx;
|
aHash[iKey] = (ht_slot)idx;
|
||||||
@@ -1452,7 +1455,11 @@ static int walIteratorInit(Wal *pWal, WalIterator **pp){
|
|||||||
ht_slot *aIndex; /* Sorted index for this segment */
|
ht_slot *aIndex; /* Sorted index for this segment */
|
||||||
|
|
||||||
aPgno++;
|
aPgno++;
|
||||||
nEntry = (int)(((i+1)==nSegment)?(int)(iLast-iZero):(u32 *)aHash-(u32 *)aPgno);
|
if( (i+1)==nSegment ){
|
||||||
|
nEntry = (int)(iLast - iZero);
|
||||||
|
}else{
|
||||||
|
nEntry = (u32*)aHash - (u32*)aPgno;
|
||||||
|
}
|
||||||
aIndex = &((ht_slot *)&p->aSegment[p->nSegment])[iZero];
|
aIndex = &((ht_slot *)&p->aSegment[p->nSegment])[iZero];
|
||||||
iZero++;
|
iZero++;
|
||||||
|
|
||||||
@@ -2089,18 +2096,23 @@ int sqlite3WalRead(
|
|||||||
volatile u32 *aPgno; /* Pointer to array of page numbers */
|
volatile u32 *aPgno; /* Pointer to array of page numbers */
|
||||||
u32 iZero; /* Frame number corresponding to aPgno[0] */
|
u32 iZero; /* Frame number corresponding to aPgno[0] */
|
||||||
int iKey; /* Hash slot index */
|
int iKey; /* Hash slot index */
|
||||||
int rc;
|
int nCollide; /* Number of hash collisions remaining */
|
||||||
|
int rc; /* Error code */
|
||||||
|
|
||||||
rc = walHashGet(pWal, iHash, &aHash, &aPgno, &iZero);
|
rc = walHashGet(pWal, iHash, &aHash, &aPgno, &iZero);
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
nCollide = HASHTABLE_NSLOT;
|
||||||
for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
|
for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
|
||||||
u32 iFrame = aHash[iKey] + iZero;
|
u32 iFrame = aHash[iKey] + iZero;
|
||||||
if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
|
if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
|
||||||
assert( iFrame>iRead );
|
assert( iFrame>iRead );
|
||||||
iRead = iFrame;
|
iRead = iFrame;
|
||||||
}
|
}
|
||||||
|
if( (nCollide--)==0 ){
|
||||||
|
return SQLITE_CORRUPT_BKPT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user