<?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>68753</bug_id>
          
          <creation_ts>2011-09-24 02:13:54 -0700</creation_ts>
          <short_desc>[WinCairo] BitmapImage::drawFrameMatchingSourceSize causes access violation if BitmapImage::frameAtIndex() returns NULL</short_desc>
          <delta_ts>2012-11-24 15:05:48 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit API</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</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></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="David Delaune">david.delaune</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>aroben</cc>
    
    <cc>bfulgham</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>472745</commentid>
    <comment_count>0</comment_count>
    <who name="David Delaune">david.delaune</who>
    <bug_when>2011-09-24 02:13:54 -0700</bug_when>
    <thetext>Hi,

I encountered an access violation in one of my unit tests at BitmapImage::drawFrameMatchingSourceSize. Below is the call stack:

&gt;	WebKit.dll!WebCore::BitmapImage::drawFrameMatchingSourceSize(WebCore::GraphicsContext * ctxt=0x0023edb0, const WebCore::FloatRect &amp; dstRect={...}, const WebCore::IntSize &amp; srcSize={...}, WebCore::ColorSpace styleColorSpace=ColorSpaceDeviceRGB, WebCore::CompositeOperator compositeOp=CompositeCopy)  Line 100 + 0x10 bytes
 	WebKit.dll!WebCore::BitmapImage::getHBITMAPOfSize(HBITMAP__ * bmp=0xee0510de, tagSIZE * size=0x0023ef74)  Line 90
 	WebKit.dll!WebIconDatabase::iconForURL(wchar_t * url=0x77f34618, tagSIZE * size=0x0023ef74, int __formal=1, unsigned int * bitmap=0x0023ef84)  Line 179 + 0xb bytes

After an investigation it appears that in some circumstances frameAtIndex() can return a NULL NativeImagePtr pointer. The WinCairo branch calls cairo_image_surface_get_height and cairo_image_surface_get_width and these functions will throw an exception if passed a NULL pointer. I noticed that the ImageCGWin.cpp implementation is nearly identical and based the comments in the Bug 61684 patch I wonder if it should also be reviewed.

Best Wishes,
-David Delaune</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>472747</commentid>
    <comment_count>1</comment_count>
      <attachid>108581</attachid>
    <who name="David Delaune">david.delaune</who>
    <bug_when>2011-09-24 02:53:48 -0700</bug_when>
    <thetext>Created attachment 108581
Check for zero cairo_surface_t * pointer to avoid null pointer exception</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>473054</commentid>
    <comment_count>2</comment_count>
      <attachid>108581</attachid>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2011-09-26 05:01:16 -0700</bug_when>
    <thetext>Comment on attachment 108581
Check for zero cairo_surface_t * pointer to avoid null pointer exception

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

Is it possible to add a regression test for this? Perhaps via TestWebKitAPI?

&gt; Source/WebCore/platform/graphics/win/ImageCairoWin.cpp:100
&gt;      for (size_t i = 0; i &lt; frames; ++i) {
&gt;          cairo_surface_t* image = frameAtIndex(i);
&gt; -        if (cairo_image_surface_get_height(image) == static_cast&lt;size_t&gt;(srcSize.height()) &amp;&amp; cairo_image_surface_get_width(image) == static_cast&lt;size_t&gt;(srcSize.width())) {
&gt; +        if (image &amp;&amp; cairo_image_surface_get_height(image) == static_cast&lt;size_t&gt;(srcSize.height()) &amp;&amp; cairo_image_surface_get_width(image) == static_cast&lt;size_t&gt;(srcSize.width())) {

I think this would be a little clearer using an early continue:

cairo_surface_t* image = frameAtIndex(i);
if (!image)
    continue;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>476636</commentid>
    <comment_count>3</comment_count>
      <attachid>108581</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2011-10-01 22:12:17 -0700</bug_when>
    <thetext>Comment on attachment 108581
Check for zero cairo_surface_t * pointer to avoid null pointer exception

You mentioned you found this during unit test. Is this a test we could integrate into WebKit&apos;s own test infrastructure?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>476637</commentid>
    <comment_count>4</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2011-10-01 22:14:00 -0700</bug_when>
    <thetext>Nice catch!

(In reply to comment #2)
&gt; (From update of attachment 108581 
&gt; I think this would be a little clearer using an early continue:
&gt; 
&gt; cairo_surface_t* image = frameAtIndex(i);
&gt; if (!image)
&gt;     continue;

I agree. Please make this change, and let me know about the test case.

Thanks!

-Brent</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>534932</commentid>
    <comment_count>5</comment_count>
      <attachid>122266</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2012-01-12 10:06:30 -0800</bug_when>
    <thetext>Created attachment 122266
Avoid passing a null pointer to the Cairo library.

Since David never responded to my comments, I&apos;ve revised the source change per Adam&apos;s comment.  No test case provided since exercising this logic requires calling WebKit API calls that are not used in the existing test infrastructure.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>535054</commentid>
    <comment_count>6</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2012-01-12 12:22:36 -0800</bug_when>
    <thetext>(In reply to comment #5)
&gt; Created an attachment (id=122266) [details]
&gt; Avoid passing a null pointer to the Cairo library.
&gt; 
&gt; Since David never responded to my comments, I&apos;ve revised the source change per Adam&apos;s comment.  No test case provided since exercising this logic requires calling WebKit API calls that are not used in the existing test infrastructure.

Brent, did you consider add a test to TestWebKitAPI for this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>553266</commentid>
    <comment_count>7</comment_count>
    <who name="David Delaune">david.delaune</who>
    <bug_when>2012-02-09 10:12:20 -0800</bug_when>
    <thetext>Hi,

I have not tried this... I am just guessing that the manual test located at:

\WebKit\ManualTests\resources\favicon-loads-for-local-files.html

could potentially be modified to demonstrate this bug on WinCairo.

You could probably generate a corrupt icon by doing something like:

head -c 1024 /dev/urandom &gt; corrupt_favicon.ico

Best Wishes,
-David Delaune</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>560315</commentid>
    <comment_count>8</comment_count>
      <attachid>122266</attachid>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2012-02-20 12:14:59 -0800</bug_when>
    <thetext>Comment on attachment 122266
Avoid passing a null pointer to the Cairo library.

Discussion in this bug makes it sound like it should be possible to write an automated test. So let&apos;s wait until we have one.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>624472</commentid>
    <comment_count>9</comment_count>
    <who name="David Delaune">david.delaune</who>
    <bug_when>2012-05-15 13:23:20 -0700</bug_when>
    <thetext>What automated test is Apple using to test for Bug 61684?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>624491</commentid>
    <comment_count>10</comment_count>
      <attachid>122266</attachid>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2012-05-15 13:34:22 -0700</bug_when>
    <thetext>Comment on attachment 122266
Avoid passing a null pointer to the Cairo library.

It would be nice to have a test for this if you can make one (with a corrupted image file or something). I don&apos;t think it&apos;s necessary though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>774891</commentid>
    <comment_count>11</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2012-11-24 15:05:48 -0800</bug_when>
    <thetext>Committed r135659: &lt;http://trac.webkit.org/changeset/135659&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>108581</attachid>
            <date>2011-09-24 02:53:48 -0700</date>
            <delta_ts>2012-01-12 10:06:30 -0800</delta_ts>
            <desc>Check for zero cairo_surface_t * pointer to avoid null pointer exception</desc>
            <filename>patch.diff</filename>
            <type>text/plain</type>
            <size>1873</size>
            <attacher name="David Delaune">david.delaune</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV2Vi
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDk1OTA3KQorKysgU291cmNlL1dlYkNvcmUvQ2hhbmdl
TG9nCSh3b3JraW5nIGNvcHkpCkBAIC0xLDMgKzEsMTYgQEAKKzIwMTEtMDktMjQgIERhdmlkIERl
bGF1bmUgIDxkYXZpZC5kZWxhdW5lQGdvb2dsZW1haWwuY29tPgorCisgICAgICAgIFtXaW5DYWly
b10gQml0bWFwSW1hZ2U6OmRyYXdGcmFtZU1hdGNoaW5nU291cmNlU2l6ZSBjYXVzZXMgYWNjZXNz
IHZpb2xhdGlvbiBpZiBCaXRtYXBJbWFnZTo6ZnJhbWVBdEluZGV4KCkgcmV0dXJucyBOVUxMCisg
ICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD02ODc1MworCisg
ICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAgIE5vIG5ldyBmdW5j
dGlvbmFsaXR5IGFkZGVkIGluIHRoaXMgY2hhbmdlLgorCisgICAgICAgICogcGxhdGZvcm0vZ3Jh
cGhpY3Mvd2luL0ltYWdlQ2Fpcm9XaW4uY3BwOgorICAgICAgICAoV2ViQ29yZTo6Qml0bWFwSW1h
Z2U6OmRyYXdGcmFtZU1hdGNoaW5nU291c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q+KHNyY1NpemUud2lkdGgoKSkpIHsKKyAg
ICAgICAgaWYgKGltYWdlICYmIGNhaXJvX2ltYWdlX3N1cmZhY2VfZ2V0X2hlaWdodChpbWFnZSkg
PT0gc3RhdGljX2Nhc3Q8c2l6ZV90PihzcmNTaXplLmhlaWdodCgpKSAmJiBjYWlyb19pbWFnZV9z
dXJmYWNlX2dldF93aWR0aChpbWFnZSkgPT0gc3RhdGljX2Nhc3Q8c2l6ZV90PihzcmNTaXplLndp
ZHRoKCkpKSB7CiAgICAgICAgICAgICBzaXplX3QgY3VycmVudEZyYW1lID0gbV9jdXJyZW50RnJh
bWU7CiAgICAgICAgICAgICBtX2N1cnJlbnRGcmFtZSA9IGk7CiAgICAgICAgICAgICBkcmF3KGN0
eHQsIGRzdFJlY3QsIEZsb2F0UmVjdCgwLjBmLCAwLjBmLCBzcmNTaXplLndpZHRoKCksIHNyY1Np
emUuaGVpZ2h0KCkpLCBDb2xvclNwYWNlRGV2aWNlUkdCLCBjb21wb3NpdGVPcCk7Cg==
</data>
<flag name="review"
          id="105579"
          type_id="1"
          status="-"
          setter="aroben"
    />
          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>122266</attachid>
            <date>2012-01-12 10:06:30 -0800</date>
            <delta_ts>2012-05-15 13:34:21 -0700</delta_ts>
            <desc>Avoid passing a null pointer to the Cairo library.</desc>
            <filename>bitmapImage.patch</filename>
            <type>text/plain</type>
            <size>1691</size>
            <attacher name="Brent Fulgham">bfulgham</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV2Vi
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDEwNDgzMikKKysrIFNvdXJjZS9XZWJDb3JlL0NoYW5n
ZUxvZwkod29ya2luZy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uY3BwCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT0KLS0tIFNvdXJjZS9XZWJDb3JlL3BsYXRmb3JtL2dyYXBoaWNz
L3dpbi9JbWFnZUNhaXJvV2luLmNwcAkocmV2aXNpb24gMTA0NzMxKQorKysgU291cmNlL1dlYkNv
cmUvcGxhdGZvcm0vZ3JhcGhpY3Mvd2luL0ltYWdlQ2Fpcm9XaW4uY3BwCSh3b3JraW5nIGNvcHkp
CkBAIC05Nyw2ICs5Nyw5IEBAIHZvaWQgQml0bWFwSW1hZ2U6OmRyYXdGcmFtZU1hdGNoaW5nU291
cmMKICAgICBzaXplX3QgZnJhbWVzID0gZnJhbWVDb3VudCgpOwogICAgIGZvciAoc2l6ZV90IGkg
PSAwOyBpIDwgZnJhbWVzOyArK2kpIHsKICAgICAgICAgY2Fpcm9fc3VyZmFjZV90KiBpbWFnZSA9
IGZyYW1lQXRJbmRleChpKTsKKyAgICAgICAgaWYgKCFpbWFnZSkKKyAgICAgICAgICAgIGNvbnRp
bnVlOworCiAgICAgICAgIGlmIChjYWlyb19pbWFnZV9zdXJmYWNlX2dldF9oZWlnaHQoaW1hZ2Up
ID09IHN0YXRpY19jYXN0PHNpemVfdD4oc3JjU2l6ZS5oZWlnaHQoKSkgJiYgY2Fpcm9faW1hZ2Vf
c3VyZmFjZV9nZXRfd2lkdGgoaW1hZ2UpID09IHN0YXRpY19jYXN0PHNpemVfdD4oc3JjU2l6ZS53
aWR0aCgpKSkgewogICAgICAgICAgICAgc2l6ZV90IGN1cnJlbnRGcmFtZSA9IG1fY3VycmVudEZy
YW1lOwogICAgICAgICAgICAgbV9jdXJyZW50RnJhbWUgPSBpOwo=
</data>
<flag name="review"
          id="123012"
          type_id="1"
          status="+"
          setter="simon.fraser"
    />
          </attachment>
      

    </bug>

</bugzilla>