Bug 146391 - ResourceError should store failingURL as URL instead of String to avoid reparsing and to address FIXME comments in ResourceErrorCF.cpp and ResourceErrorMac.mm
Summary: ResourceError should store failingURL as URL instead of String to avoid repar...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Page Loading (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords:
Depends on: 146384 152563
Blocks:
  Show dependency treegraph
 
Reported: 2015-06-27 21:25 PDT by David Kilzer (:ddkilzer)
Modified: 2016-01-12 08:30 PST (History)
9 users (show)

See Also:


Attachments
Patch v1 (3.07 KB, patch)
2015-06-27 21:36 PDT, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v2 (3.27 KB, patch)
2015-12-22 20:25 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v3 (checking EFL/GTK builds) (36.62 KB, patch)
2015-12-23 18:58 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v4 (38.06 KB, patch)
2015-12-23 19:27 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v5 (48.49 KB, patch)
2015-12-23 22:24 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v6 (52.77 KB, patch)
2015-12-23 22:49 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v7 (52.90 KB, patch)
2015-12-24 07:56 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v8 (52.91 KB, patch)
2015-12-24 08:06 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v9 (55.94 KB, patch)
2015-12-24 08:22 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v10 (56.79 KB, patch)
2015-12-24 08:34 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2015-06-27 21:25:04 PDT
Address the FIXME comments added for the build for for Bug 146384:
Committed r186036: <http://trac.webkit.org/changeset/186036>
Comment 1 David Kilzer (:ddkilzer) 2015-06-27 21:36:53 PDT
Created attachment 255717 [details]
Patch v1
Comment 2 Alexey Proskuryakov 2015-06-27 23:22:10 PDT
Comment on attachment 255717 [details]
Patch v1

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

> Source/WebCore/platform/network/cf/ResourceErrorCF.cpp:157
> +            if (RetainPtr<CFURLRef> url = URL(URL(), m_failingURL).createCFURL())

Can this be tested?

As a general principle, I think that we shouldn't expose invalid URLs in API. The fact that the URL is invalid gets lost in conversion, and it's too easy for the client to make incorrect decisions based on the URL string. I can't find it now, but we even had security bugs caused by handling invalid URLs.
Comment 3 David Kilzer (:ddkilzer) 2015-06-28 01:02:45 PDT
(In reply to comment #2)
> Comment on attachment 255717 [details]
> Patch v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=255717&action=review
> 
> > Source/WebCore/platform/network/cf/ResourceErrorCF.cpp:157
> > +            if (RetainPtr<CFURLRef> url = URL(URL(), m_failingURL).createCFURL())
> 
> Can this be tested?

It's not known how to reproduce the crash.  Do you have ideas about how to reproduce it based on the crashing stack?  Maybe setting the source of an iframe with an invalid URL?
Comment 4 Darin Adler 2015-06-28 11:12:45 PDT
Comment on attachment 255717 [details]
Patch v1

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

Before we make this change, I’d like to understand more about where the string is coming from. In particular, did this already come out of a WebCore::URL, and if so, can we avoid the round trip through a string?

>>> Source/WebCore/platform/network/cf/ResourceErrorCF.cpp:157
>>> +            if (RetainPtr<CFURLRef> url = URL(URL(), m_failingURL).createCFURL())
>> 
>> Can this be tested?
>> 
>> As a general principle, I think that we shouldn't expose invalid URLs in API. The fact that the URL is invalid gets lost in conversion, and it's too easy for the client to make incorrect decisions based on the URL string. I can't find it now, but we even had security bugs caused by handling invalid URLs.
> 
> It's not known how to reproduce the crash.  Do you have ideas about how to reproduce it based on the crashing stack?  Maybe setting the source of an iframe with an invalid URL?

I think you have an interesting point, Alexey, about invalid URLs. But please keep in mind that we are exposing that same URL above in failingURLStringKey; I am not certain that an NSURL is an additional risk.

> Source/WebCore/platform/network/mac/ResourceErrorMac.mm:186
> +        if (RetainPtr<NSURL> cocoaURL = (NSURL *)URL(URL(), resourceError.failingURL()))

No reason to use RetainPtr here instead of just NSURL *. The NSURL will be autoreleased.
Comment 5 David Kilzer (:ddkilzer) 2015-12-22 20:23:27 PST
(In reply to comment #4)
> Comment on attachment 255717 [details]
> Patch v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=255717&action=review
> 
> Before we make this change, I’d like to understand more about where the
> string is coming from. In particular, did this already come out of a
> WebCore::URL, and if so, can we avoid the round trip through a string?

The CFErrorRef and NSError objects come from CFNetwork callbacks, so I don't think there are any round trip savings to be had here.

> >>> Source/WebCore/platform/network/cf/ResourceErrorCF.cpp:157
> >>> +            if (RetainPtr<CFURLRef> url = URL(URL(), m_failingURL).createCFURL())
> >> 
> >> Can this be tested?
> >> 
> >> As a general principle, I think that we shouldn't expose invalid URLs in API. The fact that the URL is invalid gets lost in conversion, and it's too easy for the client to make incorrect decisions based on the URL string. I can't find it now, but we even had security bugs caused by handling invalid URLs.
> > 
> > It's not known how to reproduce the crash.  Do you have ideas about how to reproduce it based on the crashing stack?  Maybe setting the source of an iframe with an invalid URL?
> 
> I think you have an interesting point, Alexey, about invalid URLs. But
> please keep in mind that we are exposing that same URL above in
> failingURLStringKey; I am not certain that an NSURL is an additional risk.
> 
> > Source/WebCore/platform/network/mac/ResourceErrorMac.mm:186
> > +        if (RetainPtr<NSURL> cocoaURL = (NSURL *)URL(URL(), resourceError.failingURL()))
> 
> No reason to use RetainPtr here instead of just NSURL *. The NSURL will be
> autoreleased.

I thought we preferred explicit retain/release instead of putting objects into autoreleasepools (generally speaking), but removing RetainPtr<> will make the conversion to ARC easier when that happens, and it's only a single object being put in the pool, so I'll change it.
Comment 6 David Kilzer (:ddkilzer) 2015-12-22 20:25:40 PST
Created attachment 267825 [details]
Patch v2
Comment 7 David Kilzer (:ddkilzer) 2015-12-22 20:56:20 PST
(In reply to comment #5)
> (In reply to comment #4)
> > Comment on attachment 255717 [details]
> > Patch v1
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=255717&action=review
> > 
> > Before we make this change, I’d like to understand more about where the
> > string is coming from. In particular, did this already come out of a
> > WebCore::URL, and if so, can we avoid the round trip through a string?
> 
> The CFErrorRef and NSError objects come from CFNetwork callbacks, so I don't
> think there are any round trip savings to be had here.

Oops, I was looking in the wrong direction!

Looking at the ResourceError() constructors that use the multi-argument constructor, I think nearly all of them are converting a URL() to a String(), so we could save a round trip here.

I will try changing the failingURL argument of ResourceError() from String() to URL().
Comment 8 David Kilzer (:ddkilzer) 2015-12-23 18:58:56 PST
Created attachment 267885 [details]
Patch v3 (checking EFL/GTK builds)
Comment 9 WebKit Commit Bot 2015-12-23 18:59:47 PST
Attachment 267885 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/gtk/ErrorsGtk.cpp:33:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/gtk/ErrorsGtk.cpp:39:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/gtk/ErrorsGtk.cpp:50:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/gtk/ErrorsGtk.cpp:56:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/gtk/ErrorsGtk.cpp:62:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/gtk/ErrorsGtk.cpp:68:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/gtk/ErrorsGtk.cpp:74:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/gtk/ErrorsGtk.cpp:86:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
ERROR: Source/WebCore/platform/gtk/ErrorsGtk.cpp:92:  Weird number of spaces at line-start.  Are you using a 4-space indent?  [whitespace/indent] [3]
Total errors found: 9 in 20 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 David Kilzer (:ddkilzer) 2015-12-23 19:27:05 PST
Created attachment 267886 [details]
Patch v4
Comment 11 David Kilzer (:ddkilzer) 2015-12-23 22:24:10 PST
Created attachment 267891 [details]
Patch v5
Comment 12 David Kilzer (:ddkilzer) 2015-12-23 22:49:35 PST
Created attachment 267892 [details]
Patch v6
Comment 13 David Kilzer (:ddkilzer) 2015-12-24 07:56:52 PST
Created attachment 267896 [details]
Patch v7
Comment 14 David Kilzer (:ddkilzer) 2015-12-24 08:06:35 PST
Created attachment 267897 [details]
Patch v8
Comment 15 David Kilzer (:ddkilzer) 2015-12-24 08:22:35 PST
Created attachment 267898 [details]
Patch v9
Comment 16 David Kilzer (:ddkilzer) 2015-12-24 08:34:10 PST
Created attachment 267899 [details]
Patch v10
Comment 17 WebKit Commit Bot 2015-12-25 04:22:41 PST
Comment on attachment 267899 [details]
Patch v10

Clearing flags on attachment: 267899

Committed r194419: <http://trac.webkit.org/changeset/194419>
Comment 18 WebKit Commit Bot 2015-12-25 04:22:49 PST
All reviewed patches have been landed.  Closing bug.
Comment 19 Csaba Osztrogonác 2015-12-26 11:39:15 PST
(In reply to comment #18)
> All reviewed patches have been landed.  Closing bug.

It broke the WinCairo (curl) build.
Comment 20 David Kilzer (:ddkilzer) 2015-12-31 15:28:43 PST
(In reply to comment #19)
> (In reply to comment #18)
> > All reviewed patches have been landed.  Closing bug.
> 
> It broke the WinCairo (curl) build.

That build needs to be on the dashboard.
Comment 21 peavo 2016-01-04 08:21:02 PST
(In reply to comment #20)
> (In reply to comment #19)
> > (In reply to comment #18)
> > > All reviewed patches have been landed.  Closing bug.
> > 
> > It broke the WinCairo (curl) build.
> 
> That build needs to be on the dashboard.

Yes, that would be very nice :)
Comment 22 Csaba Osztrogonác 2016-01-06 02:01:03 PST
(In reply to comment #19)
> (In reply to comment #18)
> > All reviewed patches have been landed.  Closing bug.
> 
> It broke the WinCairo (curl) build.

Fixed in bug152563. Thanks.
Comment 23 Darin Adler 2016-01-12 08:30:57 PST
(In reply to comment #5)
> (In reply to comment #4)
> > Comment on attachment 255717 [details]
> > Patch v1
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=255717&action=review
> > 
> > > Source/WebCore/platform/network/mac/ResourceErrorMac.mm:186
> > > +        if (RetainPtr<NSURL> cocoaURL = (NSURL *)URL(URL(), resourceError.failingURL()))
> > 
> > No reason to use RetainPtr here instead of just NSURL *. The NSURL will be
> > autoreleased.
> 
> I thought we preferred explicit retain/release instead of putting objects
> into autoreleasepools (generally speaking), but removing RetainPtr<> will
> make the conversion to ARC easier when that happens, and it's only a single
> object being put in the pool, so I'll change it.

While this code no longer exists, I wanted to clear up a misunderstanding here. The local decision here had nothing to do with conversion to ARC.

The function that converts a URL to an NSURL puts the URL into the autorelease pool. Using a RetainPtr doesn't prevent it from doing that, instead it retains and releases an additional time, unnecessarily. There's no choice between autorelease and retain/release in this code, just a choice between doing an extra retain/release or not doing it.

If we wanted to use retain/release instead of an autorelease pool we would have to change the function that converts a URL into an NSURL * so that it doesn't autorelease.