<?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>177944</bug_id>
          
          <creation_ts>2017-10-05 08:25:19 -0700</creation_ts>
          <short_desc>Avoid integer overflow in DFGStrengthReduction.cpp</short_desc>
          <delta_ts>2017-10-06 09:34:46 -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>JavaScriptCore</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="Robin Morisset">rmorisset</reporter>
          <assigned_to name="Robin Morisset">rmorisset</assigned_to>
          <cc>buildbot</cc>
    
    <cc>commit-queue</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>msaboff</cc>
    
    <cc>saam</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1357026</commentid>
    <comment_count>0</comment_count>
    <who name="Robin Morisset">rmorisset</who>
    <bug_when>2017-10-05 08:25:19 -0700</bug_when>
    <thetext>The check that we won&apos;t cause integer overflow is itself a signed integer overflow! I believe this is undefined behavior, and a future compiler could remove the check altogether.
Instead, make it an explicit check that value != INT32_MIN.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1357027</commentid>
    <comment_count>1</comment_count>
      <attachid>322838</attachid>
    <who name="Robin Morisset">rmorisset</who>
    <bug_when>2017-10-05 08:27:52 -0700</bug_when>
    <thetext>Created attachment 322838
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1357032</commentid>
    <comment_count>2</comment_count>
      <attachid>322838</attachid>
    <who name="Saam Barati">saam</who>
    <bug_when>2017-10-05 08:58:36 -0700</bug_when>
    <thetext>Comment on attachment 322838
Patch

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

&gt; Source/JavaScriptCore/dfg/DFGStrengthReductionPhase.cpp:158
&gt; +                if (value != INT32_MIN) {

Why not use Checked here?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1357545</commentid>
    <comment_count>3</comment_count>
    <who name="Robin Morisset">rmorisset</who>
    <bug_when>2017-10-06 03:15:10 -0700</bug_when>
    <thetext>(In reply to Saam Barati from comment #2)
&gt; Comment on attachment 322838 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=322838&amp;action=review
&gt; 
&gt; &gt; Source/JavaScriptCore/dfg/DFGStrengthReductionPhase.cpp:158
&gt; &gt; +                if (value != INT32_MIN) {
&gt; 
&gt; Why not use Checked here?

I just did not know about the existence of Checked.

I could use it here, but I am not sure it would be a win: the check here is trivial, and using Checked would be a bit more bothersome:
  Checked&lt;int32_t, RecordOnOverflow&gt; checkedNewValue = 0;
  checkedNewValue -= value;
  int32_t newValue;
  if (CheckedState::DidNotOverflow == checkedNewValue.safeGet(newValue)) {
    ... (newValue)...
  }
Instead of
  if (value != INT32_MIN) {
    ... (-value) ...
  }

If you think it would be better, I can do the change and use it, it is as you want.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1357592</commentid>
    <comment_count>4</comment_count>
    <who name="Saam Barati">saam</who>
    <bug_when>2017-10-06 08:56:05 -0700</bug_when>
    <thetext>(In reply to Robin Morisset from comment #3)
&gt; (In reply to Saam Barati from comment #2)
&gt; &gt; Comment on attachment 322838 [details]
&gt; &gt; Patch
&gt; &gt; 
&gt; &gt; View in context:
&gt; &gt; https://bugs.webkit.org/attachment.cgi?id=322838&amp;action=review
&gt; &gt; 
&gt; &gt; &gt; Source/JavaScriptCore/dfg/DFGStrengthReductionPhase.cpp:158
&gt; &gt; &gt; +                if (value != INT32_MIN) {
&gt; &gt; 
&gt; &gt; Why not use Checked here?
&gt; 
&gt; I just did not know about the existence of Checked.
&gt; 
&gt; I could use it here, but I am not sure it would be a win: the check here is
&gt; trivial, and using Checked would be a bit more bothersome:
&gt;   Checked&lt;int32_t, RecordOnOverflow&gt; checkedNewValue = 0;
&gt;   checkedNewValue -= value;
&gt;   int32_t newValue;
&gt;   if (CheckedState::DidNotOverflow == checkedNewValue.safeGet(newValue)) {
&gt;     ... (newValue)...
&gt;   }
&gt; Instead of
&gt;   if (value != INT32_MIN) {
&gt;     ... (-value) ...
&gt;   }
&gt; 
&gt; If you think it would be better, I can do the change and use it, it is as
&gt; you want.

Keep it as you have it. r=me still</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1357607</commentid>
    <comment_count>5</comment_count>
      <attachid>322838</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2017-10-06 09:33:46 -0700</bug_when>
    <thetext>Comment on attachment 322838
Patch

Clearing flags on attachment: 322838

Committed r222981: &lt;http://trac.webkit.org/changeset/222981&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1357608</commentid>
    <comment_count>6</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2017-10-06 09:33:47 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1357609</commentid>
    <comment_count>7</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2017-10-06 09:34:46 -0700</bug_when>
    <thetext>&lt;rdar://problem/34857276&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>322838</attachid>
            <date>2017-10-05 08:27:52 -0700</date>
            <delta_ts>2017-10-06 09:33:46 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-177944-20171005172751.patch</filename>
            <type>text/plain</type>
            <size>1782</size>
            <attacher name="Robin Morisset">rmorisset</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjIyOTA4CmRpZmYgLS1naXQgYS9Tb3VyY2UvSmF2YVNjcmlw
dENvcmUvQ2hhbmdlTG9nIGIvU291cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwppbmRleCA1
YzRlNGM5ZDEyODI1OTNlN2FhZGZmNDMwNDEwZTZiOWE3NTc2ZGU1Li45MzVkZDdhZDk1ZWVhNGEy
NWVhNDQxNGIyNzAxY2IxZDdhNzEwM2VlIDEwMDY0NAotLS0gYS9Tb3VyY2UvSmF2YVNjcmlwdENv
cmUvQ2hhbmdlTG9nCisrKyBiL1NvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKQEAgLTEs
MyArMSwxNiBAQAorMjAxNy0xMC0wNSAgUm9iaW4gTW9yaXNzZXQgIDxybW9yaXNzZXRAYXBwbGUu
Y29tPgorCisgICAgICAgIEF2b2lkIGludGVnZXIgb3ZlcmZsb3cgaW4gREZHU3RyZW5ndGhSZWR1
Y3Rpb24uY3BwCisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9p
ZD0xNzc5NDQKKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAg
ICBUaGUgY2hlY2sgdGhhdCB3ZSB3b24ndCBkbyBpbnRlZ2VyIG92ZXJmbG93IGJ5IG5lZ2F0aW5n
IElOVDMyX01JTiB3YXMgaXRzZWxmIGFuIGludGVnZXIgb3ZlcmZsb3cuCisgICAgICAgIEkgdGhp
bmsgdGhhdCBzaW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nQzMkNvbnN0
YW50KCkKICAgICAgICAgICAgICAgICAmJiBtX25vZGUtPmlzQmluYXJ5VXNlS2luZChJbnQzMlVz
ZSkpIHsKICAgICAgICAgICAgICAgICBpbnQzMl90IHZhbHVlID0gbV9ub2RlLT5jaGlsZDIoKS0+
YXNJbnQzMigpOwotICAgICAgICAgICAgICAgIGlmICgtdmFsdWUgIT0gdmFsdWUpIHsKKyAgICAg
ICAgICAgICAgICBpZiAodmFsdWUgIT0gSU5UMzJfTUlOKSB7CiAgICAgICAgICAgICAgICAgICAg
IG1fbm9kZS0+c2V0T3AoQXJpdGhBZGQpOwogICAgICAgICAgICAgICAgICAgICBtX25vZGUtPmNo
aWxkMigpLnNldE5vZGUoCiAgICAgICAgICAgICAgICAgICAgICAgICBtX2luc2VydGlvblNldC5p
bnNlcnRDb25zdGFudCgK
</data>

          </attachment>
      

    </bug>

</bugzilla>