<?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>157937</bug_id>
          
          <creation_ts>2016-05-19 17:53:56 -0700</creation_ts>
          <short_desc>WTF::Condition::waitFor() will time out immediately for relativeTimeout values with very large tick counts</short_desc>
          <delta_ts>2016-11-03 12:32:32 -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>Web Template Framework</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>152045</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=157924</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Andy Estes">aestes</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>aestes</cc>
    
    <cc>fpizlo</cc>
    
    <cc>ggaren</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1195060</commentid>
    <comment_count>0</comment_count>
    <who name="Andy Estes">aestes</who>
    <bug_when>2016-05-19 17:53:56 -0700</bug_when>
    <thetext>As discussed in &lt;https://bugs.webkit.org/show_bug.cgi?id=157924&gt;, WTF::Condition::waitFor() times out immediately if given a relativeTimeout of std::chrono::milliseconds::max(), due to two signed integer overflow bugs conspiring against us in Condition::absoluteFromRelative().

The first happens in this comparison:

        if (relativeTimeout &gt; Clock::duration::max()) {

std::chrono::duration converts the operands of its inequality operators to the type common to both durations (using std::common_type) before performing the comparison. In this case that&apos;s nanoseconds, and converting milliseconds::max() to nanoseconds will overflow since they both use the same underlying data type.

The second happens on this line, for the same reason, except this time the conversion is explicit:

        Clock::duration myRelativeTimeout =
            std::chrono::duration_cast&lt;Clock::duration&gt;(relativeTimeout);

Since the check that was supposed to protect us from overflowing itself overflowed, we now have a negative relative timeout.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1195061</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2016-05-19 17:55:06 -0700</bug_when>
    <thetext>&lt;rdar://problem/26382498&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1195400</commentid>
    <comment_count>2</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2016-05-21 19:41:00 -0700</bug_when>
    <thetext>(In reply to comment #0)
&gt; As discussed in &lt;https://bugs.webkit.org/show_bug.cgi?id=157924&gt;,
&gt; WTF::Condition::waitFor() times out immediately if given a relativeTimeout
&gt; of std::chrono::milliseconds::max(), due to two signed integer overflow bugs
&gt; conspiring against us in Condition::absoluteFromRelative().
&gt; 
&gt; The first happens in this comparison:
&gt; 
&gt;         if (relativeTimeout &gt; Clock::duration::max()) {
&gt; 
&gt; std::chrono::duration converts the operands of its inequality operators to
&gt; the type common to both durations (using std::common_type) before performing
&gt; the comparison. In this case that&apos;s nanoseconds, and converting
&gt; milliseconds::max() to nanoseconds will overflow since they both use the
&gt; same underlying data type.

Wow!  I did not know about this behavior.  That&apos;s so awkward!  I don&apos;t think I would have been so enthusiastic about using std::chrono if I had known how overflow-prone it was.

&gt; 
&gt; The second happens on this line, for the same reason, except this time the
&gt; conversion is explicit:
&gt; 
&gt;         Clock::duration myRelativeTimeout =
&gt;             std::chrono::duration_cast&lt;Clock::duration&gt;(relativeTimeout);
&gt; 
&gt; Since the check that was supposed to protect us from overflowing itself
&gt; overflowed, we now have a negative relative timeout.

Dang, that&apos;s too funny.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1195456</commentid>
    <comment_count>3</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2016-05-22 18:20:07 -0700</bug_when>
    <thetext>Kind of sad that std::chrono devotes so much boilerplate to giving each time unit its own type, only to explode anyway due to overflow. :(</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1195457</commentid>
    <comment_count>4</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2016-05-22 18:40:26 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; Kind of sad that std::chrono devotes so much boilerplate to giving each time
&gt; unit its own type, only to explode anyway due to overflow. :(

Yes.  I think we need to stop using std::chrono.  I just sent a proposal to that effect to webkit-dev.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1247802</commentid>
    <comment_count>5</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2016-11-03 12:32:32 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 152045 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>