<?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>39786</bug_id>
          
          <creation_ts>2010-05-26 14:55:49 -0700</creation_ts>
          <short_desc>Public GIF decoder fails to mark some images as &quot;done&quot;</short_desc>
          <delta_ts>2010-05-26 15:26:55 -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>Images</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://threeframes.net/</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="Peter Kasting">pkasting</reporter>
          <assigned_to name="Peter Kasting">pkasting</assigned_to>
          <cc>abarth</cc>
    
    <cc>hyatt</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>230937</commentid>
    <comment_count>0</comment_count>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2010-05-26 14:55:49 -0700</bug_when>
    <thetext>The open-source GIF decoder has a bug that results in it never marking some GIFs as &quot;done&quot;.  The problematic code is effectively:

for (...; bytes remaining &gt; bytes to consume in current state; ...) {
    switch (state) {
    ...
    case x:
        if (consuming bytes led to a finished GIF)
            state = gif_done;
            break;
    ...
    case gif_done:
        clientptr-&gt;gifComplete();
        return true;  // &quot;success&quot;
    }
}
return false;  // &quot;need more bytes to continue&quot;

The reason this is a problem is that when we switch the state to gif_done, we don&apos;t reset the &quot;bytes to consume&quot; value to 0.  So we go to run through the loop again and find that there are no more bytes in the file, but we want to consume some bytes.  Thus we exit the loop and return false, without ever marking the GIF as &quot;done&quot;.

The effect of this is that we erroneously mark these GIFs as having failed, and in some cases fail to properly set things like the repeat count.  Try running Chrome 6.0.408.1 on the URL given in this bug&apos;s URL field and note that while the GIFs on the page should all animate indefinitely, most don&apos;t until you refresh or reload the page.

The fix here is that instead of setting the state directly, we should use a macro that is used to do all the other state changes, which simultaneously sets the new state and the new &quot;bytes to consume&quot; value (which in this case should be 0).

Patch coming shortly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>230942</commentid>
    <comment_count>1</comment_count>
      <attachid>57165</attachid>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2010-05-26 15:01:04 -0700</bug_when>
    <thetext>Created attachment 57165
patch v1

This patch fixes both places that failed to use GETN() to change state: one by using the macro, and the other by eliminating it entirely.  (WebKit uses this code differently than Mozilla did, and marking corrupt GIFs as &quot;failed&quot; won&apos;t prevent their display.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>230944</commentid>
    <comment_count>2</comment_count>
      <attachid>57165</attachid>
    <who name="Adam Barth">abarth</who>
    <bug_when>2010-05-26 15:03:46 -0700</bug_when>
    <thetext>Comment on attachment 57165
patch v1

I have no idea what this does, but I believe you.  It&apos;s too bad we don&apos;t have more than one image expert.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>230945</commentid>
    <comment_count>3</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2010-05-26 15:04:13 -0700</bug_when>
    <thetext>Maybe Hyatt has some idea who might know this code better?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>230947</commentid>
    <comment_count>4</comment_count>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2010-05-26 15:06:59 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; Maybe Hyatt has some idea who might know this code better?

Sadly, I think hyatt and I are the only people to have worked on this, and it was years ago for him.

I probably ought to just gut GIFImageReader.cpp someday and rewrite it from scratch.  It&apos;s been a never-ending source of problems.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>230962</commentid>
    <comment_count>5</comment_count>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2010-05-26 15:26:55 -0700</bug_when>
    <thetext>Fixed in r60255.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>57165</attachid>
            <date>2010-05-26 15:01:04 -0700</date>
            <delta_ts>2010-05-26 15:03:45 -0700</delta_ts>
            <desc>patch v1</desc>
            <filename>gif_patch</filename>
            <type>text/plain</type>
            <size>2476</size>
            <attacher name="Peter Kasting">pkasting</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiA2MDI1MikKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMTcgQEAKKzIwMTAtMDUtMjYgIFBldGVyIEthc3RpbmcgIDxwa2FzdGluZ0Bnb29n
bGUuY29tPgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAg
IGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0zOTc4NgorICAgICAgICBQ
cm9wZXJseSByZXNldCB8Ynl0ZXNfdG9fY29uc3VtZXwgd2hlbiByZWFjaGluZyB0aGUgImdpZl9k
b25lIiBzdGF0ZSBpbgorICAgICAgICB0aGUgb3Blbi1zb3VyY2UgR0lGIGRlY29kZXIuCisgICAg
ICAgIAorICAgICAgICBObyB0ZXN0cywgc2luY2UgdGhlcmUncyBubyB0ZXN0IGhhcm5lc3Mgc3Vw
cG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SBlbHNlIHsKLSAgICAgICAgICAvKiBObyBpbWFnZXMgZGVjb2RlZCwg
dGhlcmUgaXMgbm90aGluZyB0byBkaXNwbGF5LiAqLwotICAgICAgICAgIHJldHVybiBjbGllbnRw
dHIgPyBjbGllbnRwdHItPnNldEZhaWxlZCgpIDogZmFsc2U7Ci0gICAgICAgIH0KLSAgICAgICAg
YnJlYWs7Ci0gICAgICB9IGVsc2UKLSAgICAgICAgR0VUTig5LCBnaWZfaW1hZ2VfaGVhZGVyKTsK
KyAgICAgIGlmICgqcSAhPSAnLCcpCisgICAgICAgIHJldHVybiBjbGllbnRwdHIgPyBjbGllbnRw
dHItPnNldEZhaWxlZCgpIDogZmFsc2U7CisKKyAgICAgIEdFVE4oOSwgZ2lmX2ltYWdlX2hlYWRl
cik7CiAgICAgfQogICAgIGJyZWFrOwogCg==
</data>
<flag name="review"
          id="41721"
          type_id="1"
          status="+"
          setter="abarth"
    />
          </attachment>
      

    </bug>

</bugzilla>