Fix numerous bugs in fts2 where a corrupt fts2 database could cause out-of-bounds reads and writes.
Fix numerous bugs in fts2 where a corrupt fts2 database could cause
out-of-bounds reads and writes.

Apologies for the size of the change but once I got cranking, it was about
half a day to clean up most of the memory errors.

This should not conflict with the in-progress sqlite-3.6.18 upgrade. I diffed
sqlite-3.6.1 vs. sqlite-3.6.18 and the only changes to fts2.c were two spelling
corrections in comments.

These changes are not whimsical -- they do map to crashes we are seeing
in the wild, e.g.

1) Crash in allocator just after leafReaderStep:
http://crash/reportdetail?reportid=303de6d80936c11d

2) Crash in memcpy in leafReaderStep:
http://crash/reportdetail?reportid=6b2c65459042e67c

3) Crash in memcpy in interiorReaderStep:
http://crash/reportdetail?reportid=9f7ba5c321846302

4) Crash in loop in dlrStep trying to read past end of buffer:
http://crash/reportdetail?reportid=61b2eb58397913b2


In addition, this will give relief to users who have (for whatever root cause)
persistent corruption in their databases. Once you get into that state, Chrome
might be unlaunchable or it might crash multiple times per day.

There's a small chance this might help with our biggest crasher, as certain
types of corrupt database could corrupt memory rather than crashing immediately.

BUG=NONE
TEST=Running with tricked out build with assert()s to check for false positives.


Review URL: http://codereview.chromium.org/216026

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@27679 0039d316-1c4b-4281-b951-d872f2087c98

patrickm/chromium.src,Pluto-tv/chromium-crosswalk,mogoweb/chromium-crosswalk,hujiajie/pa-chromium,ltilve/chromium,ltilve/chromium,anirudhSK/chromium,anirudhSK/chromium,krieger-od/nwjs_chromium.src,dednal/chromium.src,pozdnyakov/chromium-crosswalk,timopulkkinen/BubbleFish,krieger-od/nwjs_chromium.src,ondra-novak/chromium.src,krieger-od/nwjs_chromium.src,robclark/chromium,littlstar/chromium.src,timopulkkinen/BubbleFish,zcbenz/cefode-chromium,axinging/chromium-crosswalk,hgl888/chromium-crosswalk,PeterWangIntel/chromium-crosswalk,markYoungH/chromium.src,crosswalk-project/chromium-crosswalk-efl,junmin-zhu/chromium-rivertrail,hujiajie/pa-chromium,junmin-zhu/chromium-rivertrail,M4sse/chromium.src,Pluto-tv/chromium-crosswalk,timopulkkinen/BubbleFish,chuan9/chromium-crosswalk,hgl888/chromium-crosswalk,Fireblend/chromium-crosswalk,axinging/chromium-crosswalk,ltilve/chromium,hgl888/chromium-crosswalk,Chilledheart/chromium,hgl888/chromium-crosswalk-efl,hgl888/chromium-crosswalk,patrickm/chromium.src,M4sse/chromium.src,patrickm/chromium.src,junmin-zhu/chromium-rivertrail,Chilledheart/chromium,TheTypoMaster/chromium-crosswalk,robclark/chromium,patrickm/chromium.src,Pluto-tv/chromium-crosswalk,littlstar/chromium.src,mohamed--abdel-maksoud/chromium.src,hujiajie/pa-chromium,keishi/chromium,axinging/chromium-crosswalk,littlstar/chromium.src,anirudhSK/chromium,mogoweb/chromium-crosswalk,anirudhSK/chromium,mohamed--abdel-maksoud/chromium.src,Chilledheart/chromium,mohamed--abdel-maksoud/chromium.src,markYoungH/chromium.src,mohamed--abdel-maksoud/chromium.src,PeterWangIntel/chromium-crosswalk,krieger-od/nwjs_chromium.src,pozdnyakov/chromium-crosswalk,markYoungH/chromium.src,Chilledheart/chromium,junmin-zhu/chromium-rivertrail,dednal/chromium.src,Just-D/chromium-1,ltilve/chromium,dushu1203/chromium.src,hgl888/chromium-crosswalk-efl,keishi/chromium,fujunwei/chromium-crosswalk,Jonekee/chromium.src,ChromiumWebApps/chromium,Pluto-tv/chromium-crosswalk,zcbenz/cefode-chromium,jaruba/chromium.src,nacl-webkit/chrome_deps,markYoungH/chromium.src,anirudhSK/chromium,bright-sparks/chromium-spacewalk,krieger-od/nwjs_chromium.src,dednal/chromium.src,pozdnyakov/chromium-crosswalk,hgl888/chromium-crosswalk,chuan9/chromium-crosswalk,dednal/chromium.src,zcbenz/cefode-chromium,TheTypoMaster/chromium-crosswalk,ChromiumWebApps/chromium,nacl-webkit/chrome_deps,mogoweb/chromium-crosswalk,dednal/chromium.src,dushu1203/chromium.src,nacl-webkit/chrome_deps,nacl-webkit/chrome_deps,Just-D/chromium-1,dushu1203/chromium.src,hgl888/chromium-crosswalk-efl,jaruba/chromium.src,axinging/chromium-crosswalk,TheTypoMaster/chromium-crosswalk,rogerwang/chromium,rogerwang/chromium,dushu1203/chromium.src,littlstar/chromium.src,Jonekee/chromium.src,PeterWangIntel/chromium-crosswalk,keishi/chromium,M4sse/chromium.src,crosswalk-project/chromium-crosswalk-efl,ChromiumWebApps/chromium,ltilve/chromium,bright-sparks/chromium-spacewalk,timopulkkinen/BubbleFish,mogoweb/chromium-crosswalk,Fireblend/chromium-crosswalk,Jonekee/chromium.src,zcbenz/cefode-chromium,fujunwei/chromium-crosswalk,Jonekee/chromium.src,pozdnyakov/chromium-crosswalk,timopulkkinen/BubbleFish,timopulkkinen/BubbleFish,markYoungH/chromium.src,krieger-od/nwjs_chromium.src,M4sse/chromium.src,jaruba/chromium.src,chuan9/chromium-crosswalk,jaruba/chromium.src,axinging/chromium-crosswalk,Jonekee/chromium.src,krieger-od/nwjs_chromium.src,mohamed--abdel-maksoud/chromium.src,timopulkkinen/BubbleFish,ondra-novak/chromium.src,Chilledheart/chromium,hujiajie/pa-chromium,Fireblend/chromium-crosswalk,junmin-zhu/chromium-rivertrail,krieger-od/nwjs_chromium.src,TheTypoMaster/chromium-crosswalk,jaruba/chromium.src,axinging/chromium-crosswalk,chuan9/chromium-crosswalk,mogoweb/chromium-crosswalk,M4sse/chromium.src,ltilve/chromium,axinging/chromium-crosswalk,junmin-zhu/chromium-rivertrail,nacl-webkit/chrome_deps,Chilledheart/chromium,dednal/chromium.src,hgl888/chromium-crosswalk-efl,junmin-zhu/chromium-rivertrail,jaruba/chromium.src,M4sse/chromium.src,PeterWangIntel/chromium-crosswalk,nacl-webkit/chrome_deps,robclark/chromium,TheTypoMaster/chromium-crosswalk,hujiajie/pa-chromium,markYoungH/chromium.src,markYoungH/chromium.src,bright-sparks/chromium-spacewalk,keishi/chromium,fujunwei/chromium-crosswalk,hujiajie/pa-chromium,rogerwang/chromium,ChromiumWebApps/chromium,timopulkkinen/BubbleFish,mohamed--abdel-maksoud/chromium.src,mogoweb/chromium-crosswalk,PeterWangIntel/chromium-crosswalk,mogoweb/chromium-crosswalk,Pluto-tv/chromium-crosswalk,anirudhSK/chromium,M4sse/chromium.src,ChromiumWebApps/chromium,nacl-webkit/chrome_deps,PeterWangIntel/chromium-crosswalk,ChromiumWebApps/chromium,crosswalk-project/chromium-crosswalk-efl,Fireblend/chromium-crosswalk,Just-D/chromium-1,mogoweb/chromium-crosswalk,Just-D/chromium-1,zcbenz/cefode-chromium,Pluto-tv/chromium-crosswalk,krieger-od/nwjs_chromium.src,patrickm/chromium.src,ChromiumWebApps/chromium,mohamed--abdel-maksoud/chromium.src,mohamed--abdel-maksoud/chromium.src,hujiajie/pa-chromium,pozdnyakov/chromium-crosswalk,anirudhSK/chromium,Jonekee/chromium.src,TheTypoMaster/chromium-crosswalk,ltilve/chromium,jaruba/chromium.src,ondra-novak/chromium.src,axinging/chromium-crosswalk,dednal/chromium.src,dushu1203/chromium.src,Fireblend/chromium-crosswalk,rogerwang/chromium,pozdnyakov/chromium-crosswalk,dednal/chromium.src,ChromiumWebApps/chromium,hgl888/chromium-crosswalk-efl,junmin-zhu/chromium-rivertrail,anirudhSK/chromium,dushu1203/chromium.src,rogerwang/chromium,Jonekee/chromium.src,patrickm/chromium.src,crosswalk-project/chromium-crosswalk-efl,keishi/chromium,dednal/chromium.src,Just-D/chromium-1,chuan9/chromium-crosswalk,Pluto-tv/chromium-crosswalk,Jonekee/chromium.src,junmin-zhu/chromium-rivertrail,rogerwang/chromium,ondra-novak/chromium.src,timopulkkinen/BubbleFish,jaruba/chromium.src,ondra-novak/chromium.src,Pluto-tv/chromium-crosswalk,Jonekee/chromium.src,hgl888/chromium-crosswalk,ltilve/chromium,littlstar/chromium.src,keishi/chromium,ChromiumWebApps/chromium,hgl888/chromium-crosswalk-efl,patrickm/chromium.src,pozdnyakov/chromium-crosswalk,bright-sparks/chromium-spacewalk,timopulkkinen/BubbleFish,markYoungH/chromium.src,jaruba/chromium.src,mohamed--abdel-maksoud/chromium.src,Jonekee/chromium.src,rogerwang/chromium,pozdnyakov/chromium-crosswalk,krieger-od/nwjs_chromium.src,ChromiumWebApps/chromium,hujiajie/pa-chromium,hgl888/chromium-crosswalk-efl,bright-sparks/chromium-spacewalk,robclark/chromium,mogoweb/chromium-crosswalk,dushu1203/chromium.src,robclark/chromium,keishi/chromium,PeterWangIntel/chromium-crosswalk,ondra-novak/chromium.src,chuan9/chromium-crosswalk,markYoungH/chromium.src,littlstar/chromium.src,crosswalk-project/chromium-crosswalk-efl,chuan9/chromium-crosswalk,bright-sparks/chromium-spacewalk,crosswalk-project/chromium-crosswalk-efl,M4sse/chromium.src,robclark/chromium,ChromiumWebApps/chromium,Fireblend/chromium-crosswalk,TheTypoMaster/chromium-crosswalk,rogerwang/chromium,pozdnyakov/chromium-crosswalk,junmin-zhu/chromium-rivertrail,ondra-novak/chromium.src,keishi/chromium,keishi/chromium,ondra-novak/chromium.src,crosswalk-project/chromium-crosswalk-efl,Just-D/chromium-1,fujunwei/chromium-crosswalk,M4sse/chromium.src,zcbenz/cefode-chromium,fujunwei/chromium-crosswalk,dushu1203/chromium.src,littlstar/chromium.src,Fireblend/chromium-crosswalk,zcbenz/cefode-chromium,bright-sparks/chromium-spacewalk,axinging/chromium-crosswalk,keishi/chromium,pozdnyakov/chromium-crosswalk,Chilledheart/chromium,Jonekee/chromium.src,keishi/chromium,markYoungH/chromium.src,jaruba/chromium.src,axinging/chromium-crosswalk,rogerwang/chromium,hgl888/chromium-crosswalk-efl,nacl-webkit/chrome_deps,Just-D/chromium-1,zcbenz/cefode-chromium,crosswalk-project/chromium-crosswalk-efl,robclark/chromium,zcbenz/cefode-chromium,mohamed--abdel-maksoud/chromium.src,Fireblend/chromium-crosswalk,hgl888/chromium-crosswalk,littlstar/chromium.src,mohamed--abdel-maksoud/chromium.src,timopulkkinen/BubbleFish,anirudhSK/chromium,hgl888/chromium-crosswalk-efl,dushu1203/chromium.src,hgl888/chromium-crosswalk,Chilledheart/chromium,patrickm/chromium.src,mogoweb/chromium-crosswalk,Pluto-tv/chromium-crosswalk,fujunwei/chromium-crosswalk,dushu1203/chromium.src,chuan9/chromium-crosswalk,axinging/chromium-crosswalk,ChromiumWebApps/chromium,junmin-zhu/chromium-rivertrail,crosswalk-project/chromium-crosswalk-efl,nacl-webkit/chrome_deps,anirudhSK/chromium,TheTypoMaster/chromium-crosswalk,robclark/chromium,fujunwei/chromium-crosswalk,chuan9/chromium-crosswalk,ltilve/chromium,PeterWangIntel/chromium-crosswalk,dednal/chromium.src,hgl888/chromium-crosswalk-efl,M4sse/chromium.src,Chilledheart/chromium,Just-D/chromium-1,bright-sparks/chromium-spacewalk,markYoungH/chromium.src,fujunwei/chromium-crosswalk,rogerwang/chromium,dushu1203/chromium.src,PeterWangIntel/chromium-crosswalk,M4sse/chromium.src,anirudhSK/chromium,dednal/chromium.src,ondra-novak/chromium.src,robclark/chromium,hujiajie/pa-chromium,hujiajie/pa-chromium,zcbenz/cefode-chromium,pozdnyakov/chromium-crosswalk,robclark/chromium,hujiajie/pa-chromium,hgl888/chromium-crosswalk,jaruba/chromium.src,Fireblend/chromium-crosswalk,krieger-od/nwjs_chromium.src,zcbenz/cefode-chromium,patrickm/chromium.src,TheTypoMaster/chromium-crosswalk,nacl-webkit/chrome_deps,anirudhSK/chromium,bright-sparks/chromium-spacewalk,Just-D/chromium-1,fujunwei/chromium-crosswalk,nacl-webkit/chrome_deps