<?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>209270</bug_id>
          
          <creation_ts>2020-03-18 21:09:27 -0700</creation_ts>
          <short_desc>decodeCFData should check bufferIsLargeEnoughToContain before allocating a buffer</short_desc>
          <delta_ts>2021-04-23 10:46:12 -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>DUPLICATE</resolution>
          <dup_id>224984</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>209131</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Fujii Hironori">fujii</reporter>
          <assigned_to name="Darin Adler">darin</assigned_to>
          <cc>darin</cc>
    
    <cc>hi</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1631529</commentid>
    <comment_count>0</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2020-03-18 21:09:27 -0700</bug_when>
    <thetext>decodeCFData should check bufferIsLargeEnoughToContain before allocating a buffer

This is a sub-task of Bug 209131.
  Bug 209131 – Don&apos;t allocate a buffer with the decoded size without ensuring bufferIsLargeEnoughToContain(size)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1631531</commentid>
    <comment_count>1</comment_count>
      <attachid>393943</attachid>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2020-03-18 21:11:28 -0700</bug_when>
    <thetext>Created attachment 393943
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1631547</commentid>
    <comment_count>2</comment_count>
      <attachid>393943</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2020-03-18 22:36:41 -0700</bug_when>
    <thetext>Comment on attachment 393943
Patch

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

&gt; Source/WebCore/platform/network/cf/CertificateInfo.h:118
&gt; +    if (!decoder.bufferIsLargeEnoughToContain&lt;uint8_t&gt;(static_cast&lt;size_t&gt;(size)))

This cast to size_t doesn’t look right, nor does the code below. If the size is larger than what will fit  in size_t, this will do the wrong thing. We can clean up this mix of types. CFDataCreate takes an argument of a type called CFIndex. So I think we need to write this:

    if (size &gt; std::numeric_limits&lt;CFIndex&gt;::max())
        return false;

    CFIndex length = size;

Then we should use length instead of static_cast&lt;size_t&gt;(size) in both places that it appears.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1631548</commentid>
    <comment_count>3</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2020-03-18 22:38:01 -0700</bug_when>
    <thetext>I’m also thinking that we could use a helper to decode a size, check the size, allocate a vector of that size, then decode the data into the vector. I think this pattern is happening over and over again. And every time we are writing the same code.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1631569</commentid>
    <comment_count>4</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2020-03-19 01:22:22 -0700</bug_when>
    <thetext>(In reply to Darin Adler from comment #3)
&gt; I’m also thinking that we could use a helper to decode a size, check the
&gt; size, allocate a vector of that size, then decode the data into the vector.
&gt; I think this pattern is happening over and over again. And every time we are
&gt; writing the same code.

Oops. There are already coder classes for Vector there. Will rewrite code with them.
 
https://trac.webkit.org/browser/webkit/trunk/Source/WTF/wtf/persistence/PersistentCoders.h#L167
https://trac.webkit.org/browser/webkit/trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h#L375</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1631698</commentid>
    <comment_count>5</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2020-03-19 09:56:16 -0700</bug_when>
    <thetext>Great! Looking forward to seeing that version.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1631839</commentid>
    <comment_count>6</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2020-03-19 14:45:46 -0700</bug_when>
    <thetext>VectorArgumentCoder is just only for WTF::Vector.
VectorArgumentCoder can&apos;t be used for this case of encodeCFData because encodeCFData doesn&apos;t treat WTF::Vector.

I will use IPC::VectorArgumentCoder and WTF::Persistence::VectorCoder for other cases in ohter bug tickets.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1631840</commentid>
    <comment_count>7</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2020-03-19 14:49:16 -0700</bug_when>
    <thetext>encodeCFData doesn&apos;t need to convert CFIndex to uint64_t.
If I understand correctly, CertificateInfo is passed only via IPC between web process and UI process, not in persistent storage.
I think it&apos;s safe to change the encoding format.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1632251</commentid>
    <comment_count>8</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2020-03-20 13:38:26 -0700</bug_when>
    <thetext>WTF::Persistence::Encoder can&apos;t encode &apos;long&apos;.
WTF::Persistence::Encoder has int32_t (int) and int64_t (long long) encoders, but long.
Even though both long and long long are 64bit, they are different types.

&gt; CompileC /Users/fujii/webkit/ga/WebKitBuild/WebCore.build/Debug/WebCore.build/Objects-normal/x86_64/ResourceResponseCocoa.o platform/network/cocoa/ResourceResponseCocoa.mm normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
&gt;     cd /Users/fujii/webkit/ga/Source/WebCore
&gt;     export LANG=en_US.US-ASCII
&gt;     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c++ -target x86_64-apple-macos10.15 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu++1z -stdlib=libc++ -f$
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm:27:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/ResourceResponse.h:28:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/ResourceResponseBase.h:30:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/CertificateInfo.h:32:
&gt; In file included from /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentCoders.h:36:
&gt; In file included from /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentDecoder.h:30:
&gt; /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentCoder.h:37:10: error: member reference base type &apos;const long&apos; is not a structure or union
&gt;         t.encode(encoder);
&gt;         ~^~~~~~~
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm:27:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/ResourceResponse.h:28:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/ResourceResponseBase.h:30:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/CertificateInfo.h:32:
&gt; In file included from /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentCoders.h:37:
&gt; /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentEncoder.h:65:19: note: in instantiation of member function &apos;WTF::Persistence::Coder&lt;long&gt;::encode&apos; requested here
&gt;         Coder&lt;T&gt;::encode(*this, t);
&gt;                   ^
&gt; /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentEncoder.h:70:9: note: in instantiation of function template specialization &apos;WTF::Persistence::Encoder::encode&lt;long&gt;&apos; requested here
&gt;         encode(t);
&gt;         ^
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm:27:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/ResourceResponse.h:28:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/ResourceResponseBase.h:30:
&gt; /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/CertificateInfo.h:108:13: note: in instantiation of function template specialization &apos;WTF::Persistence::Encoder::operator&lt;&lt;&lt;long&gt;&apos; requested here
&gt;     encoder &lt;&lt; length;
&gt;             ^
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm:27:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/ResourceResponse.h:28:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/ResourceResponseBase.h:30:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/CertificateInfo.h:32:
&gt; In file included from /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentCoders.h:36:
&gt; In file included from /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentDecoder.h:30:
&gt; /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentCoder.h:42:16: error: type &apos;long&apos; cannot be used prior to &apos;::&apos; because it has no members
&gt;         return T::decode(decoder, t);
&gt;                ^
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm:27:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/ResourceResponse.h:28:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/ResourceResponseBase.h:30:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/CertificateInfo.h:32:
&gt; In file included from /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentCoders.h:36:
&gt; /Users/fujii/webkit/ga/WebKitBuild/Debug/usr/local/include/wtf/persistence/PersistentDecoder.h:85:26: note: in instantiation of member function &apos;WTF::Persistence::Coder&lt;long&gt;::decode&apos; requested here
&gt;         return Coder&lt;T&gt;::decode(*this, t);
&gt;                          ^
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm:27:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/ResourceResponse.h:28:
&gt; In file included from /Users/fujii/webkit/ga/Source/WebCore/platform/network/ResourceResponseBase.h:30:
&gt; /Users/fujii/webkit/ga/Source/WebCore/platform/network/cf/CertificateInfo.h:115:18: note: in instantiation of function template specialization &apos;WTF::Persistence::Decoder::decode&lt;long&gt;&apos; requested here
&gt;     if (!decoder.decode(size))
&gt;                  ^
&gt; 2 errors generated.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1753637</commentid>
    <comment_count>9</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2021-04-23 10:46:12 -0700</bug_when>
    <thetext>I’m fixing this in bug 224984.

*** This bug has been marked as a duplicate of bug 224984 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>393943</attachid>
            <date>2020-03-18 21:11:28 -0700</date>
            <delta_ts>2020-03-18 22:36:41 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-209270-20200319131127.patch</filename>
            <type>text/plain</type>
            <size>1526</size>
            <attacher name="Fujii Hironori">fujii</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjU4Njc0CmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggOGM5NmM2ZGE2YjM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0ZUluZm8uaAppbmRleCBm
OTMxMTEzMDc5M2MxMzQ4NWFjYzY1N2M0MGQ2YWY1MTk5YjA0OWY4Li43YTg3MDI0ZWQwYzY3OTIw
ZThkODQzOWIwNGMzZGNhNTA4YjY4MGQ0IDEwMDY0NAotLS0gYS9Tb3VyY2UvV2ViQ29yZS9wbGF0
Zm9ybS9uZXR3b3JrL2NmL0NlcnRpZmljYXRlSW5mby5oCisrKyBiL1NvdXJjZS9XZWJDb3JlL3Bs
YXRmb3JtL25ldHdvcmsvY2YvQ2VydGlmaWNhdGVJbmZvLmgKQEAgLTExNSw2ICsxMTUsOSBAQCBz
dGF0aWMgYm9vbCBkZWNvZGVDRkRhdGEoRGVjb2RlciYgZGVjb2RlciwgUmV0YWluUHRyPENGRGF0
YVJlZj4mIGRhdGEpCiAgICAgaWYgKCFkZWNvZGVyLmRlY29kZShzaXplKSkKICAgICAgICAgcmV0
dXJuIGZhbHNlOwogCisgICAgaWYgKCFkZWNvZGVyLmJ1ZmZlcklzTGFyZ2VFbm91Z2hUb0NvbnRh
aW48dWludDhfdD4oc3RhdGljX2Nhc3Q8c2l6ZV90PihzaXplKSkpCisgICAgICAgIHJldHVybiBm
YWxzZTsKKwogICAgIFZlY3Rvcjx1aW50OF90PiB2ZWN0b3Ioc3RhdGljX2Nhc3Q8c2l6ZV90Pihz
aXplKSk7CiAgICAgaWYgKCFkZWNvZGVyLmRlY29kZUZpeGVkTGVuZ3RoRGF0YSh2ZWN0b3IuZGF0
YSgpLCB2ZWN0b3Iuc2l6ZSgpKSkKICAgICAgICAgcmV0dXJuIGZhbHNlOwo=
</data>
<flag name="review"
          id="409344"
          type_id="1"
          status="+"
          setter="darin"
    />
          </attachment>
      

    </bug>

</bugzilla>