Fix a segfault that can occur in matchinfo if an fts4 table contains mostly zero-length documents. Specifically, if the table contains more rows than it does bytes of text.

FossilOrigin-Name: fe9047668eaaf76e7aa1ef1f32dec7c7c4226e45
This commit is contained in:
dan 2011-01-13 10:58:26 +00:00
parent efd95a7aca
commit 86596e552e
8 changed files with 43 additions and 25 deletions

View File

@ -956,6 +956,7 @@ static int fts3MatchinfoSelectDoctotal(
if( rc!=SQLITE_OK ) return rc;
}
pStmt = *ppStmt;
assert( sqlite3_data_count(pStmt)==1 );
a = sqlite3_column_blob(pStmt, 0);
a += sqlite3Fts3GetVarint(a, &nDoc);

View File

@ -1104,7 +1104,7 @@ int sqlite3Fts3SegReaderCost(
sqlite3_stmt *pStmt;
rc = fts3SqlStmt(p, SQL_SELECT_DOCTOTAL, &pStmt, 0);
if( rc ) return rc;
if( sqlite3_step(pStmt)==SQLITE_ROW ){
if( sqlite3_data_count(pStmt) || sqlite3_step(pStmt)==SQLITE_ROW ){
sqlite3_int64 nDoc = 0;
sqlite3_int64 nByte = 0;
const char *a = sqlite3_column_blob(pStmt, 0);
@ -1116,7 +1116,8 @@ int sqlite3Fts3SegReaderCost(
}
}
pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz - 1) / pgsz);
pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz);
assert( pCsr->nRowAvg>0 );
}
rc = sqlite3_reset(pStmt);
if( rc!=SQLITE_OK || pCsr->nRowAvg==0 ) return rc;

0
install-sh Executable file → Normal file
View File

View File

@ -1,8 +1,5 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Do\snot\sraise\san\sSQLITE_CORRUPT\serror\sin\sRecoverymode\s\nif\sthe\sdatabase\ssize\sin\sthe\sheader\sis\slarger\sthan\sthe\sphysical\sfile\nsize.\s\sThis\sfacilitates\srecovery\sof\sa\sdatabase\sin\swhich\sthe\sdatabase\ssize\nfield\shas\sbeen\scorrupted.
D 2011-01-12T17:56:26.948
C Fix\sa\ssegfault\sthat\scan\soccur\sin\smatchinfo\sif\san\sfts4\stable\scontains\smostly\szero-length\sdocuments.\sSpecifically,\sif\sthe\stable\scontains\smore\srows\sthan\sit\sdoes\sbytes\sof\stext.
D 2011-01-13T10:58:27
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in de6498556d536ae60bb8bb10e8c1ba011448658c
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -72,11 +69,11 @@ F ext/fts3/fts3_hash.c 3c8f6387a4a7f5305588b203fa7c887d753e1f1c
F ext/fts3/fts3_hash.h 8331fb2206c609f9fc4c4735b9ab5ad6137c88ec
F ext/fts3/fts3_icu.c ac494aed69835008185299315403044664bda295
F ext/fts3/fts3_porter.c d61cfd81fb0fd8fbcb25adcaee0ba671aefaa5c2
F ext/fts3/fts3_snippet.c 3a26a835732619b62f3af1b73f96d017f8651f9f
F ext/fts3/fts3_snippet.c 196c5e6cde57bfc1907c2d60e9c29590e4f93fb6
F ext/fts3/fts3_tokenizer.c 055f3dc7369585350b28db1ee0f3b214dca6724d
F ext/fts3/fts3_tokenizer.h 13ffd9fcb397fec32a05ef5cd9e0fa659bf3dbd3
F ext/fts3/fts3_tokenizer1.c 6e5cbaa588924ac578263a598e4fb9f5c9bb179d
F ext/fts3/fts3_write.c 1fd0988538fb3b40009a99068148e63cec7426aa
F ext/fts3/fts3_write.c 9f3545ae27c13553a6f433fa0ec260fe8bf0cf2f
F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9
F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100
F ext/icu/README.txt bf8461d8cdc6b8f514c080e4e10dc3b2bbdfefa9
@ -100,7 +97,7 @@ F ext/rtree/rtree_util.tcl 06aab2ed5b826545bf215fff90ecb9255a8647ea
F ext/rtree/sqlite3rtree.h 1af0899c63a688e272d69d8e746f24e76f10a3f0
F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de
F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F main.mk 05d0f3475dd331896bd607cfb45c5e21b94589ad
F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a
@ -453,7 +450,7 @@ F test/fts3expr.test 5e745b2b6348499d9ef8d59015de3182072c564c
F test/fts3expr2.test 18da930352e5693eaa163a3eacf96233b7290d1a
F test/fts3fault.test f83e556465bb69dc8bc676339eca408dce4ca246
F test/fts3malloc.test 9c8cc3f885bb4dfc66d0460c52f68f45e4710d1b
F test/fts3matchinfo.test ae910aa666285e14743a80799214bfb3f1aab8f2
F test/fts3matchinfo.test 32e31467963698cc7fa311e9a61f99d7d06cf72b
F test/fts3near.test 2e318ee434d32babd27c167142e2b94ddbab4844
F test/fts3query.test ef79d31fdb355d094baec1c1b24b60439a1fb8a2
F test/fts3rnd.test 2b1a579be557ab8ac54a51b39caa4aa8043cc4ad
@ -592,7 +589,7 @@ F test/permutations.test c0ce0f3b741dd92a6d4c2671dbacba4b92dd81eb
F test/pragma.test fdfc09067ea104a0c247a1a79d8093b56656f850
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 05970cde31b1a9f54bd75af60597be75a5c54fea
F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301
F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x
F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc
F test/quick.test 1681febc928d686362d50057c642f77a02c62e57
F test/quota.test ddafe133653093eb9a99ccd6264884ae43f9c9b8
@ -873,7 +870,7 @@ F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5
F tool/lemon.c dfd81a51b6e27e469ba21d01a75ddf092d429027
F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc
F tool/mkkeywordhash.c d2e6b4a5965e23afb80fbe74bb54648cd371f309
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
F tool/mksqlite3c.tcl e0db70c2c52b0e3d0867ca931229e5b90ffe7837
F tool/mksqlite3h.tcl d76c226a5e8e1f3b5f6593bcabe5e98b3b1ec9ff
@ -898,14 +895,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P b7d080b8e850bd262f53f29ba4687a62cf76d4ef
R 3df20cbf1e57e735d0696445d60d0fe8
U drh
Z 2ae16dc41b5332856d6b8afad9a17eaa
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFNLetOoxKgR168RlERAtbpAJsHFAuvo+hb/a4kPy6JuXOle+B9JQCeJDIz
fRWuQnWOMCXleg04aoLM6ng=
=2nsc
-----END PGP SIGNATURE-----
P 114640d920e16c85de90b19d53c485135875de5b
R f5eb10b21437fad711a6b9be4e7a8db9
U dan
Z a737930e0e8a10b4bde0b31ffbd88e53

View File

@ -1 +1 @@
114640d920e16c85de90b19d53c485135875de5b
fe9047668eaaf76e7aa1ef1f32dec7c7c4226e45

View File

@ -337,6 +337,32 @@ do_execsql_test 7.4 {
FROM t10 WHERE t10 MATCH 'record'
} {blob 20 blob 20}
#-------------------------------------------------------------------------
# Test a special case - matchinfo('nxa') with many zero length documents.
# Special because "x" internally uses a statement used by both "n" and "a".
# This was causing a problem at one point in the obscure case where the
# total number of bytes of data stored in an fts3 table was greater than
# the number of rows. i.e. when the following query returns true:
#
# SELECT sum(length(content)) < count(*) FROM fts4table;
#
do_execsql_test 8.1 {
CREATE VIRTUAL TABLE t11 USING fts4;
INSERT INTO t11(t11) VALUES('nodesize=24');
INSERT INTO t11 VALUES('quitealongstringoftext');
INSERT INTO t11 VALUES('anotherquitealongstringoftext');
INSERT INTO t11 VALUES('athirdlongstringoftext');
INSERT INTO t11 VALUES('andonemoreforgoodluck');
}
do_test 8.2 {
for {set i 0} {$i < 200} {incr i} {
execsql { INSERT INTO t11 VALUES('') }
}
execsql { INSERT INTO t11(t11) VALUES('optimize') }
} {}
do_execsql_test 8.3 {
SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*'
} {{204 1 3 3 0} {204 1 3 3 0} {204 1 3 3 0}}
finish_test

0
test/progress.test Normal file → Executable file
View File

0
tool/mkopts.tcl Normal file → Executable file
View File