<?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>135060</bug_id>
          
          <creation_ts>2014-07-18 12:15:13 -0700</creation_ts>
          <short_desc>Reduce the chances of a race condition when sharing SharedBuffer</short_desc>
          <delta_ts>2014-07-20 23:16:35 -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>WebCore Misc.</component>
          <version>528+ (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="Pratik Solanki">psolanki</reporter>
          <assigned_to name="Pratik Solanki">psolanki</assigned_to>
          <cc>ap</cc>
    
    <cc>commit-queue</cc>
    
    <cc>darin</cc>
    
    <cc>kling</cc>
    
    <cc>koivisto</cc>
    
    <cc>psolanki</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>thorton</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1023309</commentid>
    <comment_count>0</comment_count>
    <who name="Pratik Solanki">psolanki</who>
    <bug_when>2014-07-18 12:15:13 -0700</bug_when>
    <thetext>We currently pass a SharedBuffer to ImageIO by creating a WebCoreSharedBufferData. This means ImageIO will access the SharedBuffer on a separate thread and this can cause data corruption bugs. While the actual fix is complex, we can at least reduce the time interval for this race condition to happen by setting the ShardBuffer size after the data is copied in SharedBuffer::append().

&lt;rdar://problem/17729444&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1023313</commentid>
    <comment_count>1</comment_count>
      <attachid>235136</attachid>
    <who name="Pratik Solanki">psolanki</who>
    <bug_when>2014-07-18 12:25:32 -0700</bug_when>
    <thetext>Created attachment 235136
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1023331</commentid>
    <comment_count>2</comment_count>
      <attachid>235136</attachid>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2014-07-18 13:02:38 -0700</bug_when>
    <thetext>Comment on attachment 235136
Patch

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

&gt; Source/WebCore/ChangeLog:17
&gt; +        cector has finished appending.

cector =&gt; vector

&gt; Source/WebCore/platform/SharedBuffer.cpp:362
&gt; -    m_size += length;
&gt;      if (m_buffer.isEmpty())
&gt;          m_buffer.reserveInitialCapacity(length);
&gt;      m_buffer.append(data, length);
&gt; +    m_size += length;

What is the plan for fixing the race condition?

It&apos;s hard to evaluate whether this change is right. If you wanted to make this data thread-consistent, you would probably do something like a store barrier before setting m_size. It&apos;s not really coherent to move the setting of m_size because, in an SMP environment, all code runs out of order anyway.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1023358</commentid>
    <comment_count>3</comment_count>
    <who name="Pratik Solanki">psolanki</who>
    <bug_when>2014-07-18 13:55:38 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; (From update of attachment 235136 [details])
&gt; View in context: https://bugs.webkit.org/attachment.cgi?id=235136&amp;action=review
&gt; 
&gt; &gt; Source/WebCore/ChangeLog:17
&gt; &gt; +        cector has finished appending.
&gt; 
&gt; cector =&gt; vector
&gt; 
&gt; &gt; Source/WebCore/platform/SharedBuffer.cpp:362
&gt; &gt; -    m_size += length;
&gt; &gt;      if (m_buffer.isEmpty())
&gt; &gt;          m_buffer.reserveInitialCapacity(length);
&gt; &gt;      m_buffer.append(data, length);
&gt; &gt; +    m_size += length;
&gt; 
&gt; What is the plan for fixing the race condition?

&lt;rdar://17470655&gt; tracks this. I also filed &lt;https://bugs.webkit.org/show_bug.cgi?id=135069&gt;.

&gt; It&apos;s hard to evaluate whether this change is right. If you wanted to make this data thread-consistent, you would probably do something like a store barrier before setting m_size. It&apos;s not really coherent to move the setting of m_size because, in an SMP environment, all code runs out of order anyway.

I am not trying to fix the actual race condition - merely trying to reduce the time where it can happen. Testing indicates that the fix helps. It is possible that the compiler could reorder the instructions but my testing shows improvements from previous behavior. At the very least, this change should not make anything worse than before.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1023416</commentid>
    <comment_count>4</comment_count>
    <who name="Pratik Solanki">psolanki</who>
    <bug_when>2014-07-18 18:23:30 -0700</bug_when>
    <thetext>So, would it be okay to make this change? Or should the patch be r-?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1023499</commentid>
    <comment_count>5</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2014-07-19 22:49:45 -0700</bug_when>
    <thetext>What’s the timeline on the real fix? I’m not sure making this tweak to reduce the frequency of the bug’s symptom is a good thing to do, but it’s hard to see how it would do harm.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1023609</commentid>
    <comment_count>6</comment_count>
      <attachid>235136</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2014-07-20 20:58:50 -0700</bug_when>
    <thetext>Comment on attachment 235136
Patch

Lets get this change in even though it’s not a real fix. I’m still not sure about the strategy; it seems strange to do this instead of fixing the bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1023610</commentid>
    <comment_count>7</comment_count>
      <attachid>235136</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2014-07-20 21:30:38 -0700</bug_when>
    <thetext>Comment on attachment 235136
Patch

Clearing flags on attachment: 235136

Committed r171289: &lt;http://trac.webkit.org/changeset/171289&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1023611</commentid>
    <comment_count>8</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2014-07-20 21:30:42 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1023620</commentid>
    <comment_count>9</comment_count>
    <who name="Pratik Solanki">psolanki</who>
    <bug_when>2014-07-20 23:16:35 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; What’s the timeline on the real fix? I’m not sure making this tweak to reduce the frequency of the bug’s symptom is a good thing to do, but it’s hard to see how it would do harm.

I have the fix almost working - I am running into issues with custom fonts that I am trying to figure out. The bug I see is identical to what was seen in bug 115131. CGFont/CGFontDataProvider is not happy with my code changes in WebCoreSharedBufferData.

(In reply to comment #6)
&gt; (From update of attachment 235136 [details])
&gt; Lets get this change in even though it’s not a real fix. I’m still not sure about the strategy; it seems strange to do this instead of fixing the bug.

This was a quick change that at least makes images load. We should have a clean way of sharing data with ImageIO but my changes started looking risky - not to mention the perf impact it might have due to more copying. I&apos;ll upload my wip patches to bug 135069 while I continue testing.

Thanks for the review!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>235136</attachid>
            <date>2014-07-18 12:25:32 -0700</date>
            <delta_ts>2014-07-20 21:30:38 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-135060.patch</filename>
            <type>text/plain</type>
            <size>2097</size>
            <attacher name="Pratik Solanki">psolanki</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZyBiL1NvdXJjZS9XZWJDb3JlL0No
YW5nZUxvZwppbmRleCA3NTIyY2VlLi44NTMzODM1IDEwMDY0NAotLS0gYS9Tb3VyY2UvV2ViQ29y
ZS9DaGFuZ2VMb2cKKysrIGIvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMjYg
QEAKKzIwMTQtMDctMTggIFByYXRpayBTb2xhb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