Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Issue 216026: Fix numerous bugs in fts2 where a corrupt fts2 database could cause... (Closed)

Created:
11 years, 3 months ago by Chris Evans
Modified:
9 years, 6 months ago
CC:
chromium-reviews_googlegroups.com, huanr, cpu_(ooo_6.6-7.5)
Visibility:
Public.

Description

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. Committed revision: http://src.chromium.org/viewvc/chrome?view=rev&revision=27679

Patch Set 1 #

Patch Set 2 : '' #

Patch Set 3 : '' #

Total comments: 65

Patch Set 4 : '' #

Unified diffs Side-by-side diffs Delta from patch set Stats (+515 lines, -237 lines) Patch
M third_party/sqlite/ext/fts2/fts2.c View 1 2 3 65 chunks +515 lines, -237 lines 0 comments Download

Messages

Total messages: 7 (0 generated)
Chris Evans
11 years, 3 months ago (2009-09-18 21:17:07 UTC) #1
Scott Hess - ex-Googler
Chris, thank you for doing this. Negative thanks for making me look at it :-). ...
11 years, 3 months ago (2009-09-22 21:03:41 UTC) #2
Scott Hess - ex-Googler
On 2009/09/22 21:03:41, shess wrote: > Chris, thank you for doing this. Negative thanks for ...
11 years, 3 months ago (2009-09-22 21:11:42 UTC) #3
cevans
On Tue, Sep 22, 2009 at 2:11 PM, <shess@chromium.org> wrote: > On 2009/09/22 21:03:41, shess ...
11 years, 3 months ago (2009-09-22 21:39:28 UTC) #4
Scott Hess - ex-Googler
I haven't done that in over a year, so your guess is as good as ...
11 years, 3 months ago (2009-09-22 21:42:52 UTC) #5
Chris Evans
Thank you Scott for such a thorough review! Can I get a final look? I ...
11 years, 2 months ago (2009-09-28 23:19:04 UTC) #6
Scott Hess - ex-Googler
11 years, 2 months ago (2009-09-30 21:46:46 UTC) #7
LGTM.

I just don't have the gumption to give this a ground-up re-review.  Your changes
address my concerns from the first pass.  I have butterflies in my tummy.  Trust
the SQLite tests, I guess!

http://codereview.chromium.org/216026/diff/4001/3002
File third_party/sqlite/ext/fts2/fts2.c (right):

http://codereview.chromium.org/216026/diff/4001/3002#newcode697
Line 697: if( pReader->nData>0 ){
On 2009/09/28 23:19:04, Chris Evans wrote:
> On 2009/09/22 21:03:41, shess wrote:
> > Throw corrupt on <0 data?
> This really is a "can't happen" condition with my change so I prefer to leave
it
> to the asserts.

OK.

http://codereview.chromium.org/216026/diff/4001/3002#newcode3902
Line 3902: if( rc!=SQLITE_OK ) return rc;
On 2009/09/28 23:19:04, Chris Evans wrote:
> On 2009/09/22 21:03:41, shess wrote:
> > queryClear(pQuery); dataBufferDestroy(&new);
> 
> Done. Actually - did "if( i!=nNot ) dataBufferDestroy(&left);" as per other
> error paths too.

I think this is the right thing to do, here, but it's really opaque code.  I
often wished for a scoped_whatever<>() when writing this code.  [OK, I didn't
write this specific code, but you get my point!]

http://codereview.chromium.org/216026/diff/4001/3002#newcode6088
Line 6088: }
On 2009/09/28 23:19:04, Chris Evans wrote:
> On 2009/09/22 21:03:41, shess wrote:
> > Instead of the goto in this case, use an else.
> 
> Done. By moving "rc = SQLITE_OK" up, don't even need an else.

Excellent!

http://codereview.chromium.org/216026/diff/4001/3002#newcode6521
Line 6521: dlrDestroy(&dlReaders[0]);
On 2009/09/28 23:19:04, Chris Evans wrote:
> On 2009/09/22 21:03:41, shess wrote:
> > Your goto err cases above leak this guy.
> 
> I don't see that they do? The first "goto err" is just after a while loop
which
> blasts them all. The second "goto err" is the case where dlrInit() failed and
so
> dlrDestroy() should not be needed.

You're right!  I think.  Who wrote this code, anyhow?

Powered by Google App Engine
This is Rietveld 408576698