<?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>84225</bug_id>
          
          <creation_ts>2012-04-17 21:31:28 -0700</creation_ts>
          <short_desc>Skia OOM error when upscaling small subsets of images by large quantities</short_desc>
          <delta_ts>2012-04-18 11:44:34 -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>Mac</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>GoogleBug</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Rachel Blum">groby</reporter>
          <assigned_to name="Rachel Blum">groby</assigned_to>
          <cc>jamesr</cc>
    
    <cc>jbates</cc>
    
    <cc>mark</cc>
    
    <cc>ojan</cc>
    
    <cc>pkasting</cc>
    
    <cc>reed</cc>
    
    <cc>senorblanco</cc>
    
    <cc>webkit.review.bot</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>604580</commentid>
    <comment_count>0</comment_count>
      <attachid>137653</attachid>
    <who name="Rachel Blum">groby</who>
    <bug_when>2012-04-17 21:31:28 -0700</bug_when>
    <thetext>Created attachment 137653
Suggested patch

When upscaling a small subsection of an image by a large amount, Skia can erroneously decide to upscale and cache the entire image. This can lead to OOM issues. See http://code.google.com/p/chromium/issues/detail?id=123589

Suggested patch included</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604582</commentid>
    <comment_count>1</comment_count>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2012-04-17 21:36:44 -0700</bug_when>
    <thetext>See http://code.google.com/p/chromium/issues/detail?id=123589#c26</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604586</commentid>
    <comment_count>2</comment_count>
    <who name="James Robinson">jamesr</who>
    <bug_when>2012-04-17 21:47:27 -0700</bug_when>
    <thetext>Try using the Tools/Scripts/webkit-patch script to upload a patch - &quot;webkit-patch upload&quot; from the root of the WebKit checkout should do what you want, just follow the prompts.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604587</commentid>
    <comment_count>3</comment_count>
    <who name="Rachel Blum">groby</who>
    <bug_when>2012-04-17 21:48:49 -0700</bug_when>
    <thetext>jamesr@: It&apos;s coming. Still waiting for update-webkit to complete :) (Tried the patch in Chromium tree first)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604598</commentid>
    <comment_count>4</comment_count>
      <attachid>137653</attachid>
    <who name="David Levin">levin</who>
    <bug_when>2012-04-17 22:37:34 -0700</bug_when>
    <thetext>Comment on attachment 137653
Suggested patch

cq- simply because it will need a ChangeLog before landing. I&apos;ll let someone else do a real review. :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604601</commentid>
    <comment_count>5</comment_count>
      <attachid>137655</attachid>
    <who name="Rachel Blum">groby</who>
    <bug_when>2012-04-17 22:44:07 -0700</bug_when>
    <thetext>Created attachment 137655
Proper patch - combined overflow &amp; size test into one, too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604609</commentid>
    <comment_count>6</comment_count>
      <attachid>137655</attachid>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-04-17 23:36:47 -0700</bug_when>
    <thetext>Comment on attachment 137655
Proper patch - combined overflow &amp; size test into one, too.

Clearing flags on attachment: 137655

Committed r114487: &lt;http://trac.webkit.org/changeset/114487&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604610</commentid>
    <comment_count>7</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-04-17 23:36:51 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604883</commentid>
    <comment_count>8</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2012-04-18 10:51:53 -0700</bug_when>
    <thetext>Just curious, why doesn&apos;t the destVisibleSize check a few lines later catch this case?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604889</commentid>
    <comment_count>9</comment_count>
    <who name="John Bates">jbates</who>
    <bug_when>2012-04-18 10:56:50 -0700</bug_when>
    <thetext>(In reply to comment #8)
&gt; Just curious, why doesn&apos;t the destVisibleSize check a few lines later catch this case?

It probably does at first, but if the same resize is requested kManyRequestThreshold (4) times, it will cache it anyway (see code above destVisibleSize).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604891</commentid>
    <comment_count>10</comment_count>
    <who name="Rachel Blum">groby</who>
    <bug_when>2012-04-18 10:59:43 -0700</bug_when>
    <thetext>Three reasons why that final check doesn&apos;t work by itself

1) It&apos;s not overflow-proof. 
2) It happens after we check for repeated requests
3) It doesn&apos;t prevent requests for insanely large destSizes if the destVisibleSize is very large, too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604914</commentid>
    <comment_count>11</comment_count>
    <who name="John Bates">jbates</who>
    <bug_when>2012-04-18 11:15:48 -0700</bug_when>
    <thetext>(In reply to comment #10)
&gt; Three reasons why that final check doesn&apos;t work by itself
&gt; 
&gt; 1) It&apos;s not overflow-proof. 

Shouldn&apos;t overflow be handled before getting here?

&gt; 2) It happens after we check for repeated requests
&gt; 3) It doesn&apos;t prevent requests for insanely large destSizes if the destVisibleSize is very large, too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604920</commentid>
    <comment_count>12</comment_count>
    <who name="Rachel Blum">groby</who>
    <bug_when>2012-04-18 11:23:17 -0700</bug_when>
    <thetext>(In reply to comment #11)
&gt; (In reply to comment #10)
&gt; &gt; Three reasons why that final check doesn&apos;t work by itself
&gt; &gt; 
&gt; &gt; 1) It&apos;s not overflow-proof. 
&gt; 
&gt; Shouldn&apos;t overflow be handled before getting here?

To be clear, I&apos;m talking about integer overflow when multiplying destWidth * destHeight.

And no, it&apos;s not handled earlier - that&apos;s why the above patch does the ugly cast to ULL. The overflow happens if you take a source image (say, of the entire world) and blow it up insanely (down to street level). In that use case, we only want a tiny part of that giant image - the amount that fits on our screen.

If we decide this should be cached (as the code originally did, and as it still would according to #2), this would lead to OOM since we always cache the full image. (In the repro case, it went up to sizes of 130Kx130K pixels, IIRC)

And since that multiplication can overflow, there&apos;s a chance it erroneously decides to cache because the code thinks it&apos;s a small image. Nothing in the original code prevented that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604924</commentid>
    <comment_count>13</comment_count>
    <who name="Mark Mentovai">mark</who>
    <bug_when>2012-04-18 11:27:26 -0700</bug_when>
    <thetext>This function now computes destWidth * destHeight three different times, one of which happens at a different bit width than the others. Does it need to be done three times?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604944</commentid>
    <comment_count>14</comment_count>
    <who name="Rachel Blum">groby</who>
    <bug_when>2012-04-18 11:39:54 -0700</bug_when>
    <thetext>(In reply to comment #13)
&gt; This function now computes destWidth * destHeight three different times, one of which happens at a different bit width than the others. Does it need to be done three times?

Obviously not, but I wanted to get the patch in quickly, so this is as minimal a change set as possible.

Happy to add another patch to clean that up. (I assume under a new bug?)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>604950</commentid>
    <comment_count>15</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2012-04-18 11:44:34 -0700</bug_when>
    <thetext>(In reply to comment #14)
&gt; (I assume under a new bug?)

Yes. For the most part, webkit takes a one-patch-per-bug approach.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>137653</attachid>
            <date>2012-04-17 21:31:28 -0700</date>
            <delta_ts>2012-04-17 22:44:01 -0700</delta_ts>
            <desc>Suggested patch</desc>
            <filename>crash-fix.patch</filename>
            <type>text/plain</type>
            <size>1342</size>
            <attacher name="Rachel Blum">groby</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJDb3JlL3BsYXRmb3JtL2dyYXBoaWNzL3NraWEvTmF0aXZl
SW1hZ2VTa2lhLmNwcCBiL1NvdXJjZS9XZWJDb3JlL3BsYXRmb3JtL2dyYXBoaWNzL3NraWEvTmF0
aXZlSW1hZ2VTa2lhLmNwcAppbmRleCA1ZTY2Y2E0Li5iN2Y5MjhjIDEwMDY0NAotLS0gYS9Tb3Vy
Y2UvV2ViQ29yZS9wbGF0Zm9ybS9ncmFwaGljcy9za2lhL05hdGl2ZUltYWdlU2tpYS5jcHAKKysr
IGIvU291cmNlL1dlYkNvcmUvcGxhdGZvcm0vZ3JhcGhpY3Mvc2tpYS9OYXRpdmVJbWFnZVNraWEu
Y3BwCkBAIC0xMjcsMTIgKzEyNywyMiBAQCBib29sIE5hdGl2ZUltYWdlU2tpYTo6c2hvdWxkQ2Fj
aGVSZXNhbXBsaW5nKGNvbnN0IFNrSVJlY3QmIHNyY1N1YnNldCwKICAgICBpZiAoIWlzRGF0YUNv
bXBsZXRlKCkpCiAgICAgICAgIHJldHVybiBmYWxzZTsKIAorICAgIHN0YXRpYyBjb25zdCBpbnQg
a0xhcmdlRGltZW5zaW9uID0gMzI3Njg7CisgICAgLy8gV2UgY2hlY2sgZm9yIGEgbWF4aW11bSBk
aW1lbnNpb24gdG8gYXZvaWQgaW50ZWdlciBvdmVyZmxvdy4KKyAgICBpZiAoZGVzdFdpZHRoID4g
a0xhcmdlRGltZW5zaW9uIHx8IGRlc3RIZWlnaHQgPiBrTGFyZ2VEaW1lbnNpb24pCisgICAgICAg
IHJldHVybiBmYWxzZTsKKwogICAgIC8vIElmIHRoZSBkZXN0aW5hdGlvbiBiaXRtYXAgaXMgc21h
bGwsIHdlJ2xsIGFsd2F5cyBhbGxvdyBjYWNoaW5nLCBzaW5jZQogICAgIC8vIHRoZXJlIGlzIG5v
dCB2ZXJ5IG11Y2ggcGVuYWx0eSBmb3IgY29tcHV0aW5nIGl0IGFuZCBpdCBtYXkgY29tZSBpbiBo
YW5keS4KICAgICBzdGF0aWMgY29uc3QgaW50IGtTbWFsbEJpdG1hcFNpemUgPSA0MDk2OwogICAg
IGlmIChkZXN0V2lkdGggKiBkZXN0SGVpZ2h0IDw9IGtTbWFsbEJpdG1hcFNpemUpCiAgICAgICAg
IHJldHVybiB0cnVlOwogCisgICAgLy8gSWYgdGhlIGRlc3RpbmF0aW9uIGJpdG1hcCBpcyBleGNl
c3NpdmVseSBsYXJnZSwgd2UnbGwgbmV2ZXIgYWxsb3cgY2FjaGluZy4KKyAgICBzdGF0aWMgY29u
c3QgaW50IGtMYXJnZUJpdG1hcFNpemUgPSA0MDk2ICogNDA5NjsKKyAgICBpZiAoZGVzdFdpZHRo
ICogZGVzdEhlaWdodCA+IGtMYXJnZUJpdG1hcFNpemUpCisgICAgICAgIHJldHVybiBmYWxzZTsK
KwogICAgIC8vIElmICJ0b28gbWFueSIgcmVxdWVzdHMgaGF2ZSBiZWVuIG1hZGUgZm9yIHRoaXMg
Yml0bWFwLCB3ZSBhc3N1bWUgdGhhdAogICAgIC8vIG1hbnkgbW9yZSB3aWxsIGJlIG1hZGUgYXMg
d2VsbCwgYW5kIHdlJ2xsIGdvIGFoZWFkIGFuZCBjYWNoZSBpdC4KICAgICBzdGF0aWMgY29uc3Qg
aW50IGtNYW55UmVxdWVzdFRocmVzaG9sZCA9IDQ7Cg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>137655</attachid>
            <date>2012-04-17 22:44:07 -0700</date>
            <delta_ts>2012-04-17 23:36:47 -0700</delta_ts>
            <desc>Proper patch - combined overflow &amp; size test into one, too.</desc>
            <filename>bug-84225-20120417224405.patch</filename>
            <type>text/plain</type>
            <size>1783</size>
            <attacher name="Rachel Blum">groby</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTE0NDgwCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggNDM5ZjIwOTE0ZmI0MDll
ZDFmZGMxZWFhNWUwNzg1MDY3YWMzM2YzYi4uYjM2YTRjNWVlYmEzZWU2NzA0NGMwNGNmYzIzODM3
NzA0ZTBhNDk0OCAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAtMSwzICsxLDE1IEBACisyMDEyLTA0LTE3ICBSYWNo
ZWwgQmx1bSAgPGdyb2J5QGNocm9taXVtLm9yZz4KKworICAgICAgICBTa2lhIE9PTSBlcnJvciB3
aGVuIHVwc2NhbGluZyBzbWFsbCBzdWJzZXRzIG9mIGltYWdlcyBieSBsYXJnZSBxdWFudGl0aWVz
CisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD04NDIyNQor
CisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAgIFRlc3RlZCB3
aXRoIG1hbnVhbCB0ZXN0cy4gCisKKyAgICAgICAgKiBwbGF0Zm9ybS9ncmFwaGljcy9za2lhL05h
dGl2ZUltYWdlU2tpYS5jcHA6CisgICAgICAgIChXZWJDb3JlOjpOYXRpdmVJbWFnZVNraWE6OnNo
b3VsZENhY2hlUmVzYW1wbGluZyk6CisKIDIwMTItMDQtMTcgIEpvaG4gQmF1bWFuICA8amJhdW1h
bkBjaHJvbWl1bS5vcmc+CiAKICAgICAgICAgW2Nocm9taXVtXSB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