Bug 31451 - LocalStorage quota should include key sizes in its count
Summary: LocalStorage quota should include key sizes in its count
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Jeremy Orlow
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-12 18:59 PST by Jeremy Orlow
Modified: 2009-11-13 16:27 PST (History)
1 user (show)

See Also:


Attachments
Patch (5.82 KB, patch)
2009-11-12 19:03 PST, Jeremy Orlow
no flags Details | Formatted Diff | Diff
Patch (5.98 KB, patch)
2009-11-12 20:20 PST, Jeremy Orlow
no flags Details | Formatted Diff | Diff
Patch (6.15 KB, patch)
2009-11-13 11:38 PST, Jeremy Orlow
dimich: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremy Orlow 2009-11-12 18:59:34 PST
LocalStorage quota should include key sizes in its count.
Comment 1 Jeremy Orlow 2009-11-12 19:03:21 PST
Created attachment 43126 [details]
Patch
Comment 2 Dmitry Titov 2009-11-12 19:40:15 PST
Comment on attachment 43126 [details]
Patch

> +    bool overflow = (newLength > m_currentLength) != (value.length() + keyLength > oldValue.length());
> +    ASSERT(!overflow);  // Make a fuss if we're debugging.  But even if we aren't, don't allow overflow.

If value.length() + keyLength overflows by itself, then this check might not detect the overflow.
It seems the two-step method of detection as in StorageMap::importItem would work better.
Comment 3 Jeremy Orlow 2009-11-12 20:20:00 PST
Created attachment 43129 [details]
Patch
Comment 4 Jeremy Orlow 2009-11-12 20:21:20 PST
If you have any ideas on how to simplify the logic, please let me know.  It seems like it should be possible, but I didn't see any good ways.  (Overflow sucks....)

I could just make everything long longs and assume it's not possible.  :-)
Comment 5 Dmitry Titov 2009-11-12 21:32:23 PST
Comment on attachment 43129 [details]
Patch

> +    unsigned adjustedKeyLength = oldValue.isNull() ? key.length() : 0;
> +    newLength += adjustedKeyLength;
> +    overflow |= (newLength > m_currentLength) != (value.length() + adjustedKeyLength > oldValue.length());

I think the last line could be simply:
overflow |= newLength < m_currentLength;

r=me
Comment 6 Jeremy Orlow 2009-11-13 11:38:16 PST
Created attachment 43173 [details]
Patch
Comment 7 Jeremy Orlow 2009-11-13 11:40:41 PST
Dmitry: What you posted won't quite work.  overflow |= newLength + adjustedKeyLength < newLength  would work.  That gave me an idea on how to simplify the whole thing, though.  So I re-did it with only making one adjustment at a time which greatly simplified the logic.  Take another look?
Comment 8 Dmitry Titov 2009-11-13 12:01:48 PST
Comment on attachment 43173 [details]
Patch

Awesome!
r=me
Comment 9 Jeremy Orlow 2009-11-13 16:27:46 PST
Committed r50979: <http://trac.webkit.org/changeset/50979>