Bug 70065 - IndexedDB: Throw DATA_ERR on invalid keys, remove null key support
Summary: IndexedDB: Throw DATA_ERR on invalid keys, remove null key support
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Joshua Bell
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-13 15:31 PDT by Joshua Bell
Modified: 2011-10-24 13:50 PDT (History)
6 users (show)

See Also:


Attachments
Patch (75.82 KB, patch)
2011-10-13 15:40 PDT, Joshua Bell
no flags Details | Formatted Diff | Diff
Patch (72.31 KB, patch)
2011-10-14 15:03 PDT, Joshua Bell
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joshua Bell 2011-10-13 15:31:11 PDT
IndexedDB: Throw DATA_ERR on invalid keys, remove null key support
Comment 1 Joshua Bell 2011-10-13 15:40:49 PDT
Created attachment 110917 [details]
Patch
Comment 2 Joshua Bell 2011-10-13 15:43:25 PDT
Note: this requires 3 commits:
(1) WebKit Part 1 (this patch) - renames IDBKey::NullKey to IDBKey::InvalidKey and has the validation logic in the methods that take keys
(2) Chromium patch which drops dependency on WebIDBKey::NullType, treating it the same as the previously existing WebIDBKey::InvalidType
(3) WebKit Part 2 - removes WebIDBKey::NullType
Comment 3 Joshua Bell 2011-10-13 15:49:10 PDT
Any feedback on how to handle the optional parameters in IDBKeyRange.h in a less grotesque way would be appreciated.
Comment 4 Joshua Bell 2011-10-13 15:54:11 PDT
The Chromium side is at: http://codereview.chromium.org/8276023
Comment 5 WebKit Review Bot 2011-10-13 16:13:17 PDT
Comment on attachment 110917 [details]
Patch

Attachment 110917 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/10066316
Comment 6 Hans Wennborg 2011-10-14 07:15:36 PDT
Comment on attachment 110917 [details]
Patch

LGTM with nits; thanks for fixing.

View in context: https://bugs.webkit.org/attachment.cgi?id=110917&action=review
> Source/WebCore/storage/IDBKeyRange.cpp:44
> +PassRefPtr<IDBKeyRange> IDBKeyRange::only(PassRefPtr<IDBKey> prpValue, ExceptionCode& ec)

maybe rename prpValue to prpKey while you're at it?

> Source/WebCore/storage/IDBKeyRange.h:51
> +    static PassRefPtr<IDBKeyRange> only(PassRefPtr<IDBKey> value, ExceptionCode&);

i think you need to forward-declare ExceptionCode

> Source/WebCore/storage/IDBLevelDBCoding.cpp:355
> +        return Vector<char>();

being paranoid, if we ever end up in this code path, in a Release built (so we don't hit the assert), it might be bad if we end up writing an empty string for a key, since we could have problems parsing that later. So definitely keep the assert, but maybe return encodeByte(kIDBKeyNullTypeByte)?

> Source/WebCore/storage/IDBSQLiteBackingStore.cpp:345
> +    case IDBKey::InvalidType:

I believe this file is now actually gone :)

> Source/WebKit/chromium/src/AssertMatchingEnums.cpp:395
> +COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::NullType, IDBKey::InvalidType);

not that it makes much difference, but a FIXME that this is temporary would be nice.

> Source/WebKit/chromium/src/WebIDBKey.cpp:98
> +    m_private = 0;

why not IDBKey::createInvalid() ?
Comment 7 Joshua Bell 2011-10-14 09:49:09 PDT
Comment on attachment 110917 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=110917&action=review

Thanks, all the nits are good.

>> Source/WebKit/chromium/src/WebIDBKey.cpp:98
>> +    m_private = 0;
> 
> why not IDBKey::createInvalid() ?

WebIDBKey already has a notion of invalid which it stores with a null pointer. Since we're collapsing the the Null and Invalid types together, I made Null act like Invalid rather than vice versa. I could go the other way and have invalid WebIDBKeys store an Invalid IDBKey; I don't have a strong preference.
Comment 8 Joshua Bell 2011-10-14 15:03:55 PDT
Created attachment 111087 [details]
Patch
Comment 9 Hans Wennborg 2011-10-24 02:35:26 PDT
(In reply to comment #7)
> >> Source/WebKit/chromium/src/WebIDBKey.cpp:98
> >> +    m_private = 0;
> > 
> > why not IDBKey::createInvalid() ?
> 
> WebIDBKey already has a notion of invalid which it stores with a null pointer. Since we're collapsing the the Null and Invalid types together, I made Null act like Invalid rather than vice versa. I could go the other way and have invalid WebIDBKeys store an Invalid IDBKey; I don't have a strong preference.

Ok, that makes sense.

LGTM
Comment 10 Joshua Bell 2011-10-24 10:09:58 PDT
Tony, can you give this a look-see?
Comment 11 Tony Chang 2011-10-24 10:35:56 PDT
Comment on attachment 111087 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=111087&action=review

> Source/WebCore/storage/IDBKeyRange.h:56
> +      return lowerBound(bound, false, ec);

Nit: WebKit style prefers using enums rather than bools for arguments.  It makes it more clear at the caller what the second param is.  Since the code was already using bools, this is just a suggestion for a future cleanup.  This would only apply to the private methods, not the idl methods.
Comment 12 Joshua Bell 2011-10-24 11:02:20 PDT
Comment on attachment 111087 [details]
Patch

Filed https://bugs.webkit.org/show_bug.cgi?id=70743 as a TODO for the bool->enum nit
Comment 13 WebKit Review Bot 2011-10-24 13:50:10 PDT
Comment on attachment 111087 [details]
Patch

Clearing flags on attachment: 111087

Committed r98278: <http://trac.webkit.org/changeset/98278>
Comment 14 WebKit Review Bot 2011-10-24 13:50:15 PDT
All reviewed patches have been landed.  Closing bug.