Bug 47700 - Make mime type lookup in File::create(path) thread-safe
Summary: Make mime type lookup in File::create(path) thread-safe
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
: 35616 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-10-14 16:48 PDT by Kinuko Yasuda
Modified: 2019-09-11 03:18 PDT (History)
5 users (show)

See Also:


Attachments
Patch (10.90 KB, patch)
2011-01-23 22:37 PST, Dai Mikurube
no flags Details | Formatted Diff | Diff
Patch (11.25 KB, patch)
2011-01-25 03:03 PST, Dai Mikurube
no flags Details | Formatted Diff | Diff
Patch (11.00 KB, patch)
2011-01-31 20:06 PST, Dai Mikurube
no flags Details | Formatted Diff | Diff
Patch (12.72 KB, patch)
2011-02-01 23:35 PST, Dai Mikurube
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kinuko Yasuda 2010-10-14 16:48:33 PDT
Make mime type lookup in File::create(path) thread-safe.  This is dangerous when this code runs on workers.

Currently when we create a File object (WebCore/fileapi/File) from a file path, it calls MIMETypeRegistry::getMIMETypeForExtension() to initialize File.type based on the given path.
But this is not thread-safe on many platforms.
Comment 1 Dai Mikurube 2011-01-23 22:37:57 PST
Created attachment 79894 [details]
Patch
Comment 2 Dai Mikurube 2011-01-23 22:38:50 PST
Hi,

The patch is not to be reviewed (not tested!), but what do you think about it?
Comment 3 Kinuko Yasuda 2011-01-23 23:11:47 PST
Comment on attachment 79894 [details]
Patch

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

Thanks for uploading this.  You'd want to wait for David's (or someone who knows very well) comments, but I put a few minor ones:

> Source/WebCore/ChangeLog:20
> +        * platform/MIMETypeRegistry.h:

It is generally encouraged to put short change summary (ideally) for each file, maybe the first two files may deserve short summary in this patch?

> Source/WebCore/platform/android/TemporaryLinkStubs.cpp:310
> +    ASSERT_NOT_REACHED();

This shouldn't compile if this happens right?

How about changing this to more generic check like:
ASSERT(isMainThread());
without guards, or only with ENABLE(WORKERS).
Comment 4 Dai Mikurube 2011-01-25 03:03:28 PST
Created attachment 80040 [details]
Patch
Comment 5 Dai Mikurube 2011-01-25 03:07:15 PST
Comment on attachment 79894 [details]
Patch

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

Hi Kinuko-san,

Thank you for your comments.

>> Source/WebCore/ChangeLog:20
>> +        * platform/MIMETypeRegistry.h:
> 
> It is generally encouraged to put short change summary (ideally) for each file, maybe the first two files may deserve short summary in this patch?

Exactly. I've added summary.

>> Source/WebCore/platform/android/TemporaryLinkStubs.cpp:310
>> +    ASSERT_NOT_REACHED();
> 
> This shouldn't compile if this happens right?
> 
> How about changing this to more generic check like:
> ASSERT(isMainThread());
> without guards, or only with ENABLE(WORKERS).

Changed as your advice. Thanks.
Comment 6 Kinuko Yasuda 2011-01-28 02:44:13 PST
lgtm; now you'll need a real reviewer.
Comment 7 Adam Barth 2011-01-28 11:19:10 PST
Comment on attachment 80040 [details]
Patch

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

> Source/WebCore/platform/mac/MIMETypeRegistryMac.mm:39
> +#if ENABLE(WORKERS)
> +    ASSERT(isMainThread());
> +#endif

Can we make these asserts even if we haven't enabled workers?
Comment 8 Dai Mikurube 2011-01-31 20:06:25 PST
Created attachment 80710 [details]
Patch
Comment 9 Dai Mikurube 2011-01-31 20:07:46 PST
(In reply to comment #7)
HI Adam,

Thank you for your review. I've removed #if ENABLED(WORKERS).
Comment 10 David Levin 2011-02-01 08:57:40 PST
Comment on attachment 80710 [details]
Patch

This looks good. One last thing to fix up wherever you added ASSERT(isMainThread()); please make sure that the file has the following includes:

#include <wtf/Assertions.h>
#include <wtf/MainThread.h>

I spot checked MIMETypeRegistryWinCE.cpp and MimeTypeRegistryWx.cpp and noticed they didn't have these so those builds may get broken by this change.
Comment 11 Dai Mikurube 2011-02-01 23:35:08 PST
Created attachment 80898 [details]
Patch
Comment 12 Dai Mikurube 2011-02-01 23:36:05 PST
(In reply to comment #10)
Hi Levin,

Thank you for your review. Added the header files!
Comment 13 WebKit Commit Bot 2011-02-02 00:24:23 PST
Comment on attachment 80898 [details]
Patch

Clearing flags on attachment: 80898

Committed r77368: <http://trac.webkit.org/changeset/77368>
Comment 14 WebKit Commit Bot 2011-02-02 00:24:29 PST
All reviewed patches have been landed.  Closing bug.
Comment 15 David Levin 2011-02-09 15:32:07 PST
*** Bug 35616 has been marked as a duplicate of this bug. ***