<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>27381</bug_id>
          
          <creation_ts>2009-07-17 11:20:23 -0700</creation_ts>
          <short_desc>WinLauncher Crash with File URLs</short_desc>
          <delta_ts>2009-07-20 10:15:27 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows XP</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Brent Fulgham">bfulgham</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>132642</commentid>
    <comment_count>0</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2009-07-17 11:20:23 -0700</bug_when>
    <thetext>Attempting to open a file URL in WinLauncher (e.g., C:\Cygwin\tmp\layout-test-results\results.html) will result in a crash in FastAlloc.  This is happening because it is trying to allocate an enormous number of bytes (e.g., 174266262).

The problem is caused by this section of code:

         BSTR urlBstr = ...

         TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
         DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
         if (SUCCEEDED(UrlCreateFromPath(urlBStr, fileURL, &amp;fileURLLength, 0)))
              urlBStr = fileURL;

It is attempting to assign a TCHAR (generally a UNICODE string) to a BSTR.  While the compiler allows this, the BSTR looses the size value that should be prepended to the string.  Later on, in MarshallingHelpers.cpp we attempt this code:

KURL MarshallingHelpers::BSTRToKURL(BSTR urlStr)
{
    return KURL(KURL(), String(urlStr, SysStringLen(urlStr)));
}

The call to SysStringLen attempts to interpret the first four bytes of the UNICODE value as a string length, which in the test case results in an size that is larger than available memory.

Fix is attached.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>132646</commentid>
    <comment_count>1</comment_count>
      <attachid>32960</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2009-07-17 11:25:27 -0700</bug_when>
    <thetext>Created attachment 32960
Correct BSTR mishandling.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>132648</commentid>
    <comment_count>2</comment_count>
      <attachid>32960</attachid>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2009-07-17 11:34:10 -0700</bug_when>
    <thetext>Comment on attachment 32960
Correct BSTR mishandling.

&gt;          if (SUCCEEDED(UrlCreateFromPath(urlBStr, fileURL, &amp;fileURLLength, 0)))
&gt; -            urlBStr = fileURL;
&gt; +            SysReAllocString(&amp;urlBStr, fileURL);

It doesn&apos;t seem so great to be modifying the urlBStr parameter like this. Maybe it would be better to put the file: URL into a separate variable? Something like:

BSTR fileURLBstr = 0;
if (...) {
    fileURLBstr = SysAllocString(...);
    urlBStr = fileURLBstr;
}

...actual loading calls here...

if (fileURLBstr)
    SysFreeString(fileURLBstr);

But it seems OK as-is.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>132668</commentid>
    <comment_count>3</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2009-07-17 12:42:06 -0700</bug_when>
    <thetext>Landed in @r46050.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>133163</commentid>
    <comment_count>4</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2009-07-20 10:15:27 -0700</bug_when>
    <thetext>Forgot to close issue.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>32960</attachid>
            <date>2009-07-17 11:25:27 -0700</date>
            <delta_ts>2009-07-17 11:34:10 -0700</delta_ts>
            <desc>Correct BSTR mishandling.</desc>
            <filename>winlauncher_fix.patch</filename>
            <type>text/plain</type>
            <size>1542</size>
            <attacher name="Brent Fulgham">bfulgham</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYktpdFRvb2xzL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBXZWJLaXRUb29scy9D
aGFuZ2VMb2cJKHJldmlzaW9uIDQ2MDQxKQorKysgV2ViS2l0VG9vbHMvQ2hhbmdlTG9nCSh3b3Jr
aW5nIGNvcHkpCkBAIC0xLDMgKzEsMTUgQEAKKzIwMDktMDctMTcgIEJyZW50IEZ1bGdoYW0gIDxi
ZnVsZ2hhbUB3ZWJraXQub3JnPgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEp
LgorCisgICAgICAgIENvcnJlY3QgY3Jhc2ggaW4gV2luTGF1bmNoZXIgZHVlIHRvIGltcHJvcGVy
IG1peGluZyBvZiBCU1RSCisgICAgICAgIGFuZCBUQ0hBUiB0eXBlcy4KKyAgICAgICAgaHR0cHM6
Ly9idWdzLndlYmtpdC5vcmcvc2hvd19idWcuY2dpP2lkPTI3MzgxCisKKyAgICAgICAgKiBXaW5M
YXVuY2hlci9XaW5MYXVuY2hlci5jcHA6CisgICAgICAgIChsb2FkVVJMKTogUGVyZm9ybSBTeXNS
ZUFsbG9jU3RyaW5nIHRvIHVwZGF0ZSB0aGUgQlNUUiB3aXRoCisgICAgICAgICAgdGhlIGNvbnRl
bnRzIG9mIHRoZSBUQ0hBUiBzdHJpbmcuCisKIDIwMDktMDYtMzAgIEhvbGdlciBIYW5zIFBldGVy
IEZ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U3lzUmVBbGxvY1N0cmluZygmdXJsQlN0ciwgZmlsZVVS
TCk7CiAgICAgfQogCiAgICAgSFJFU1VMVCBociA9IGdXZWJWaWV3LT5tYWluRnJhbWUoJmZyYW1l
KTsK
</data>
<flag name="review"
          id="17302"
          type_id="1"
          status="+"
          setter="aroben"
    />
          </attachment>
      

    </bug>

</bugzilla>