<?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>261104</bug_id>
          
          <creation_ts>2023-09-04 02:00:04 -0700</creation_ts>
          <short_desc>[Curl] Support multipart response</short_desc>
          <delta_ts>2023-09-28 00:36: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>Platform</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Kenji Shukuwa">kenji.shukuwa</reporter>
          <assigned_to name="Fujii Hironori">fujii</assigned_to>
          <cc>fujii</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1975340</commentid>
    <comment_count>0</comment_count>
    <who name="Kenji Shukuwa">kenji.shukuwa</who>
    <bug_when>2023-09-04 02:00:04 -0700</bug_when>
    <thetext>WinCairo WK1 supported multipart response. However, WinCairo WK1 has been removed.
Also, WinCairo WK2 does not support multipart responses. Because of this, current
WinCairo (curl port) does not support multipart responses.

We still have the multipart response code from WinCairo WK1, so let&apos;s enable it in WinCairo WK2.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1975343</commentid>
    <comment_count>1</comment_count>
    <who name="Kenji Shukuwa">kenji.shukuwa</who>
    <bug_when>2023-09-04 02:15:10 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/17403</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1976781</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-09-11 02:01:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/115277024&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1978571</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-09-19 23:00:19 -0700</bug_when>
    <thetext>Committed 268180@main (a3b8bd468c68): &lt;https://commits.webkit.org/268180@main&gt;

Reviewed commits have been landed. Closing PR #17403 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1978757</commentid>
    <comment_count>4</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2023-09-20 13:09:53 -0700</bug_when>
    <thetext>Reverted by https://github.com/WebKit/WebKit/pull/17987</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1978758</commentid>
    <comment_count>5</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2023-09-20 13:09:55 -0700</bug_when>
    <thetext>Re-opening for pull request https://github.com/WebKit/WebKit/pull/17987</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1978759</commentid>
    <comment_count>6</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2023-09-20 13:12:43 -0700</bug_when>
    <thetext>WinCairo was crasing.

https://build.webkit.org/#/builders/727/builds/20953
https://build.webkit.org/#/builders/728/builds/2181</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1978760</commentid>
    <comment_count>7</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-09-20 13:15:18 -0700</bug_when>
    <thetext>Committed 268213@main (c12cd61edd95): &lt;https://commits.webkit.org/268213@main&gt;

Reviewed commits have been landed. Closing PR #17987 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1980848</commentid>
    <comment_count>8</comment_count>
    <who name="Kenji Shukuwa">kenji.shukuwa</who>
    <bug_when>2023-09-27 23:25:08 -0700</bug_when>
    <thetext>&gt; WinCairo was crasing.
&gt;
&gt; https://build.webkit.org/#/builders/727/builds/20953
&gt; https://build.webkit.org/#/builders/728/builds/2181

Crash trace:

---
 	WebCore.dll!WTF::StringImpl::ref() line 1142	C++
 	WebCore.dll!WTF::DefaultRefDerefTraits&lt;WTF::StringImpl&gt;::refIfNotNull(WTF::StringImpl * ptr) line 37	C++
 	WebCore.dll!WTF::RefPtr&lt;WTF::StringImpl,WTF::RawPtrTraits&lt;WTF::StringImpl&gt;,WTF::DefaultRefDerefTraits&lt;WTF::StringImpl&gt;&gt;::RefPtr&lt;WTF::StringImpl,WTF::RawPtrTraits&lt;WTF::StringImpl&gt;,WTF::DefaultRefDerefTraits&lt;WTF::StringImpl&gt;&gt;(const WTF::RefPtr&lt;WTF::StringImpl,WTF::RawPtrTraits&lt;WTF::StringImpl&gt;,WTF::DefaultRefDerefTraits&lt;WTF::StringImpl&gt;&gt; &amp; o) line 64	C++
 	WebCore.dll!WTF::String::String(const WTF::String &amp; __that) line 84	C++
 	WebCore.dll!WebCore::ParsedContentType::mimeType() line 51	C++
&gt;	WebCore.dll!WebCore::extractBoundary(const WebCore::CurlResponse &amp; response) line 54	C++
 	WebCore.dll!WebCore::CurlMultipartHandle::createIfNeeded(WebCore::CurlMultipartHandleClient &amp; client, const WebCore::CurlResponse &amp; response) line 70	C++
 	WebCore.dll!WebCore::CurlRequest::didReceiveHeader(WTF::String &amp;&amp; header) line 339	C++
 	WebCore.dll!WebCore::CurlRequest::didReceiveHeaderCallback(char * ptr, unsigned __int64 blockSize, unsigned __int64 numberOfBlocks, void * userData) line 637	C++
 	[external code]	
 	WebCore.dll!WebCore::CurlMultiHandle::perform(int &amp; runningHandles) line 284	C++
 	WebCore.dll!WebCore::CurlRequestScheduler::workerThread() line 176	C++
 	WebCore.dll!`WebCore::CurlRequestScheduler::startOrWakeUpThread&apos;::`2&apos;::&lt;lambda_1&gt;::operator()() line 99	C++
 	WebCore.dll!WTF::Detail::CallableWrapper&lt;`WebCore::CurlRequestScheduler::startOrWakeUpThread&apos;::`2&apos;::&lt;lambda_1&gt;,void&gt;::call() line 53	C++
 	WTF.dll!WTF::Function&lt;void __cdecl(void)&gt;::operator()() line 83	C++
 	WTF.dll!WTF::Thread::entryPoint(WTF::Thread::NewThreadContext * newThreadContext) line 259	C++
 	WTF.dll!WTF::wtfThreadEntryPoint(void * data) line 151	C++
 	[external code]	
---</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1980852</commentid>
    <comment_count>9</comment_count>
    <who name="Kenji Shukuwa">kenji.shukuwa</who>
    <bug_when>2023-09-27 23:32:12 -0700</bug_when>
    <thetext>ParsedContentType::create() returns std::nullopt if parsing the Content-Type fails. 

https://github.com/WebKit/WebKit/blob/ac6be1003b5936badc0a7333bfa630df2a8f498c/Source/WebCore/platform/network/ParsedContentType.cpp#L330-L336
---
std::optional&lt;ParsedContentType&gt; ParsedContentType::create(const String&amp; contentType, Mode mode)
{
    ParsedContentType parsedContentType(mode == Mode::Rfc2045 ? contentType : contentType.trim(isASCIIWhitespaceWithoutFF&lt;UChar&gt;));
    if (!parsedContentType.parseContentType(mode))
        return std::nullopt; // ### here ###
    return { WTFMove(parsedContentType) };
}
---

However, the extractBoundary() function in CurlMultipartHandle.cpp did not include guard handling for that case.

---
static std::optional&lt;CString&gt; extractBoundary(const CurlResponse&amp; response)
{
    static const auto contentTypeLength = strlen(&quot;content-type:&quot;);

    for (auto header : response.headers) {
        if (!header.startsWithIgnoringASCIICase(&quot;content-type:&quot;_s))
            continue;

        auto contentType = ParsedContentType::create(header.substring(contentTypeLength));
        // ### Need guard process ###

        if (!equalLettersIgnoringASCIICase(contentType-&gt;mimeType(), &quot;multipart/x-mixed-replace&quot;_s))
            return std::nullopt;

---</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1980853</commentid>
    <comment_count>10</comment_count>
    <who name="Kenji Shukuwa">kenji.shukuwa</who>
    <bug_when>2023-09-27 23:37:14 -0700</bug_when>
    <thetext>Since PR#17403 has been reverted, I will create the PR again.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1980858</commentid>
    <comment_count>11</comment_count>
    <who name="Kenji Shukuwa">kenji.shukuwa</who>
    <bug_when>2023-09-27 23:57:25 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/18332</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1980866</commentid>
    <comment_count>12</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-09-28 00:36:25 -0700</bug_when>
    <thetext>Committed 268569@main (5379982beccd): &lt;https://commits.webkit.org/268569@main&gt;

Reviewed commits have been landed. Closing PR #18332 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>