<?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>26527</bug_id>
          
          <creation_ts>2009-06-18 16:37:50 -0700</creation_ts>
          <short_desc>XBM decoder fails if it gets a packet boundary whilst parsing the width / height</short_desc>
          <delta_ts>2010-04-29 11:43:07 -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>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</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="Chris Evans">scarybeasts</reporter>
          <assigned_to name="Peter Kasting">pkasting</assigned_to>
          <cc>abarth</cc>
    
    <cc>pkasting</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>126810</commentid>
    <comment_count>0</comment_count>
    <who name="Chris Evans">scarybeasts</who>
    <bug_when>2009-06-18 16:37:50 -0700</bug_when>
    <thetext>Let&apos;s say we have an XBM file that starts like this:

#define dolphin_width 64
#define dolphin_height 64
static char dolphin_bits[] = {... blah

And the first 49 bytes of this file arrive in a packet, to be processed by the XBM parser. The first 49 bytes would be:

#define dolphin_width 64
#define dolphin_height 6

Looking at how the XBM decoder parses the header, we see:

        if (sscanf(&amp;input[m_decodeOffset], &quot;#define %*s %i #define %*s %i%n&quot;,
                   &amp;width, &amp;height, &amp;count) != 2)
            return false;

In the case of the above 49 bytes, the sscanf() will be successful, leaving width==64, height==6 (should be 64) and therefore a corrupt image results.

The fix, which I will attach shortly, is to defer setting the width and the height if the sscanf() consumed the last byte of input.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126812</commentid>
    <comment_count>1</comment_count>
      <attachid>31518</attachid>
    <who name="Chris Evans">scarybeasts</who>
    <bug_when>2009-06-18 16:38:33 -0700</bug_when>
    <thetext>Created attachment 31518
Fix packet boundary parsing error in the XBM decoder</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126815</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Evans">scarybeasts</who>
    <bug_when>2009-06-18 16:39:53 -0700</bug_when>
    <thetext>Regrettably, I&apos;m swamped at the moment. So I&apos;m going to have to leave the patch with you. In particular, I didn&apos;t provide a test and do not anticipate having resources to do this in the short to medium term.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126895</commentid>
    <comment_count>3</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2009-06-18 23:44:35 -0700</bug_when>
    <thetext>It seems possible to write a test that uses PHP flush() in the middle of transferring the bytes of the image.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126992</commentid>
    <comment_count>4</comment_count>
      <attachid>31518</attachid>
    <who name="David Levin">levin</who>
    <bug_when>2009-06-19 12:01:53 -0700</bug_when>
    <thetext>Comment on attachment 31518
Fix packet boundary parsing error in the XBM decoder

As Adam indicated, this needs a layout test -- http://webkit.org/coding/contributing.html


Also, please add the link to the bug in the ChangeLog.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127016</commentid>
    <comment_count>5</comment_count>
    <who name="Chris Evans">scarybeasts</who>
    <bug_when>2009-06-19 13:23:59 -0700</bug_when>
    <thetext>As per previous comment, I don&apos;t have resource to drive this one further at this time. I didn&apos;t intent to mark the bug as Review:? -- sorry about that.

I was hoping that by doing the tricky work (diagnosing subtle issue and creating patch), we can just leave this bug open until the WebKit image-decoders maintainer sees it and pulls it in.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127017</commentid>
    <comment_count>6</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2009-06-19 13:29:06 -0700</bug_when>
    <thetext>Peter, see comment 5.  *ducks*</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127023</commentid>
    <comment_count>7</comment_count>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2009-06-19 13:44:42 -0700</bug_when>
    <thetext>Yeah, I despise the sscanf crap this was written with.  Chris&apos; fix is fine in the short term but really we need to just rewrite the parser here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127026</commentid>
    <comment_count>8</comment_count>
    <who name="Chris Evans">scarybeasts</who>
    <bug_when>2009-06-19 13:51:04 -0700</bug_when>
    <thetext>Does anyone care about XBM any more? I&apos;d say it&apos;s not worth the effort of a rewrite; might as well panel-beat the thing into shape with bugfixes and leave it? I can&apos;t imagine there are many bugs left.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127028</commentid>
    <comment_count>9</comment_count>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2009-06-19 13:52:47 -0700</bug_when>
    <thetext>Many bugs left?  This just landed in the non-Chromium ports a few days ago :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>157682</commentid>
    <comment_count>10</comment_count>
    <who name="Chris Evans">scarybeasts</who>
    <bug_when>2009-10-25 22:56:26 -0700</bug_when>
    <thetext>I know a bit more about WebKit testing now, so I&apos;ll take another crack at this in the absence of any objections :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>157683</commentid>
    <comment_count>11</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2009-10-25 23:01:57 -0700</bug_when>
    <thetext>(In reply to comment #10)
&gt; I know a bit more about WebKit testing now, so I&apos;ll take another crack at this
&gt; in the absence of any objections :)

No objections!  Go for it.  :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>157703</commentid>
    <comment_count>12</comment_count>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2009-10-26 00:37:00 -0700</bug_when>
    <thetext>The XBM decoder is slated to be ripped out entirely in bug 27823 (other browsers no longer decode this format).  Don&apos;t waste your time on it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>158056</commentid>
    <comment_count>13</comment_count>
    <who name="Chris Evans">scarybeasts</who>
    <bug_when>2009-10-26 18:51:30 -0700</bug_when>
    <thetext>Doesn&apos;t Firefox still decode XBM??
Still, no objections to removing it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>158345</commentid>
    <comment_count>14</comment_count>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2009-10-27 13:55:33 -0700</bug_when>
    <thetext>(In reply to comment #13)
&gt; Doesn&apos;t Firefox still decode XBM??

Nope: https://bugzilla.mozilla.org/show_bug.cgi?id=504822</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>219125</commentid>
    <comment_count>15</comment_count>
    <who name="Peter Kasting">pkasting</who>
    <bug_when>2010-04-29 11:43:07 -0700</bug_when>
    <thetext>This bug report has become invalid because the XBM decoder has been removed from the tree (hooray!).</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>31518</attachid>
            <date>2009-06-18 16:38:33 -0700</date>
            <delta_ts>2009-06-19 12:01:53 -0700</delta_ts>
            <desc>Fix packet boundary parsing error in the XBM decoder</desc>
            <filename>xbm.diff</filename>
            <type>text/plain</type>
            <size>1616</size>
            <attacher name="Chris Evans">scarybeasts</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiA0NDgzMikKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzE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h0LCAmY291bnQpICE9IDIpCiAgICAgICAg
ICAgICByZXR1cm4gZmFsc2U7CiAKKyAgICAgICAgLy8gRW5zdXJlIHdlIGFyZSBub3QgYnJlYWtp
bmcgYW4gaW50ZWdlciBpbnRvIHR3byBwaWVjZXMgLS0gdGhpcyBtYXkKKyAgICAgICAgLy8gb2Nj
dXIgaWYgdGhlIGlucHV0IGJ1ZmZlciBlbmRzIHJpZ2h0IGF0IHRoZSBsYXN0IGJ5dGUgb2YgaW50
ZWdlcgorICAgICAgICAvLyB3ZSBwYXJzZWQuIFRoZSAtMSBpcyBiZWNhdXNlIG1feGJtU3RyaW5n
LnNpemUoKSBpbmNsdWRlcyB0aGUKKyAgICAgICAgLy8gdGVybWluYXRpbmcgTlVMTCBieXRlLgor
ICAgICAgICBpZiAoY291bnQgPT0gKG1feGJtU3RyaW5nLnNpemUoKSAtIG1fZGVjb2RlT2Zmc2V0
KSAtIDEpCisgICAgICAgICAgICByZXR1cm4gZmFsc2U7CisKICAgICAgICAgLy8gVGhlIHdpZHRo
IGFuZCBoZWlnaHQgbmVlZCB0byBmb2xsb3cgc29tZSBydWxlcy4KICAgICAgICAgaWYgKHdpZHRo
IDwgMCB8fCB3aWR0aCA+IG1heERpbWVuc2lvbiB8fCBoZWlnaHQgPCAwIHx8IGhlaWdodCA+IG1h
eERpbWVuc2lvbikgewogICAgICAgICAgICAgLy8gSWYgdGhpcyBoYXBwZW5zLCBkZWNvZGluZyBz
aG91bGQgbm90IGNvbnRpbnVlLgo=
</data>
<flag name="review"
          id="16177"
          type_id="1"
          status="-"
          setter="levin"
    />
          </attachment>
      

    </bug>

</bugzilla>