<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://bugs.gentoo.org/bugzilla.dtd">

<bugzilla version="2.22.7"
          urlbase="http://bugs.gentoo.org/"
          maintainer="bugzilla@gentoo.org"
>

    <bug>
          <bug_id>234080</bug_id>
          <alias>CVE-2008-2327</alias>
          <creation_ts>2008-08-06 12:15 0000</creation_ts>
          <short_desc>media-libs/tiff &lt;3.8.2-r4 buffer underflow in LZW decoding (CVE-2008-2327)</short_desc>
          <delta_ts>2008-09-08 18:01:22 0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Gentoo Security</product>
          <component>Vulnerabilities</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <status_whiteboard>A2 [glsa]</status_whiteboard>
          
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>rbu@gentoo.org</reporter>
          <assigned_to>security@gentoo.org</assigned_to>
          <cc>arm@gentoo.org</cc>
    
    <cc>graphics@gentoo.org</cc>
    
    <cc>m68k@gentoo.org</cc>
    
    <cc>nerdboy@gentoo.org</cc>
    
    <cc>s390@gentoo.org</cc>
    
    <cc>sh@gentoo.org</cc>

      

      
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-08-06 12:15:21 0000</bug_when>
            <thetext>** Please note that this issue is confidential and no information should be
disclosed until it is made public, see &quot;Whiteboard&quot; for a date **

Drew Yao writes:
We have found a security issue in libTIFF&apos;s handling of LZW-encoded  
images.  The use of uninitialized data could lead to a buffer  
underflow and a crash or arbitrary code execution.

CVE-ID: CVE-2008-2327

Versions known to be affected:
v3.8.2

Timing:
This issue should remain embargoed until 8/25/2008.

Credit:
Drew Yao of Apple Product Security

We have contacted the libTIFF maintainers about this issue.

A brief introduction to LZW decoding:
http://www.fileformat.info/format/tiff/corion-lzw.htm
http://en.wikipedia.org/wiki/Lzw#Decoding

The LZW algorithm is based on a translation table, or string table,  
that maps strings of input characters into codes. The TIFF  
implementation uses variable-length codes, with a maximum code length  
of 12 bits
The string table is initialized to contain all possible single- 
character strings. There are 256 of them, numbered 0 through 255,  
since our characters are bytes.  There are also special codes:
#define CODE_CLEAR      256             /* code to clear string table */
#define CODE_EOI        257             /* end-of-information code */
#define CODE_FIRST      258             /* first free code entry */
As decoding continues, longer strings are added to the string table as  
linked lists of characters.  If the string table gets full(4096  
entries), there is a &quot;Clear code&quot; which signals to reinitialize the  
string table.

tif_lzw.c

In LZWSetupDecode():
              sp-&gt;dec_codetab = (code_t*)_TIFFmalloc(CSIZE*sizeof  (code_t));

In LZWPreDecode():
       sp-&gt;dec_free_entp = sp-&gt;dec_codetab + CODE_FIRST;
      /*
       * Zero entries that are not yet filled in.  We do
       * this to guard against bogus input data that causes
       * us to index into undefined entries.  If you can
       * come up with a way to safely bounds-check input codes
       * while decoding then you can remove this operation.
       */
      _TIFFmemset(sp-&gt;dec_free_entp, 0, (CSIZE-CODE_FIRST)*sizeof  (code_t));


In LZWDecodeCompat(), LZWDecode(), and LZWDecodeVector(), when a  
CODE_CLEAR code is received, the string table does not get re-zeroed,  
leading to uninitialized data in the table being used, if the next  
code after the CODE_CLEAR is &gt; CODE_FIRST.

For example in LZWDecodeCompat():
      while (occ &gt; 0) {
              NextCode(tif, sp, bp, code, GetNextCodeCompat);
              if (code == CODE_EOI)
                      break;
              if (code == CODE_CLEAR) {
                      free_entp = sp-&gt;dec_codetab +  CODE_FIRST;          &lt;-- free_entp points to the first free entry  
after the constant entries.
                      nbits = BITS_MIN;
                      nbitsmask = MAXCODE(BITS_MIN);
                      maxcodep = sp-&gt;dec_codetab + nbitsmask;
                      NextCode(tif, sp, bp, code,  GetNextCodeCompat);     &lt;-- get the next code.   The implementation  
expects it to be &lt; CODE_FIRST, but that might not be true in a  
malicious file.
                      if (code == CODE_EOI)
                              break;
                      *op++ = code, occ--;
                      oldcodep = sp-&gt;dec_codetab + code;
                      continue;
              }
              codep = sp-&gt;dec_codetab + code;              &lt;--codep  
points into uninitialized data
...

                      do {
                              *--tp = codep-&gt;value;                    &lt;-- potential buffer underflow
                      } while( (codep = codep-&gt;next) != NULL);


[...]

A simple fix is to zero out the whole string table starting at  
CODE_FIRST whenever a CODE_CLEAR is received.
The attached patch against 3.8.2 does this.

I have tested this fix to properly display a bunch of valid files, and  
not crash after heavy fuzzing.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-08-06 12:39:06 0000</bug_when>
            <thetext>Drew also informed us about the following issue:
http://bugzilla.maptools.org/show_bug.cgi?id=1929
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-08-06 12:44:31 0000</bug_when>
            <thetext>Created an attachment (id=162354)
tiff-3.8.2-CVE-2008-2327.patch

</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-08-06 12:44:51 0000</bug_when>
            <thetext>Created an attachment (id=162356)
tiff-3.8.2-bug1929.patch

</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-08-20 12:48:15 0000</bug_when>
            <thetext>We have no upstream comment on either of the two patches, and probably won&apos;t have until after the embargo timeline. I&apos;ll attach an ebuild applying the existing patches, and we can update them later if upstream decides otherwise.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-08-20 12:48:34 0000</bug_when>
            <thetext>Created an attachment (id=163378)
tiff-3.8.2-r4.ebuild

</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-08-20 12:49:25 0000</bug_when>
            <thetext>Arch Security Liaisons, please test the attached ebuild and report it stable on this bug.
Target keywords : &quot;alpha amd64 arm hppa ia64 m68k ppc ppc64 s390 sh sparc x86&quot;

CC&apos;ing current Liaisons:
   alpha : yoswink, armin76
   amd64 : keytoaster, tester
    hppa : jer
     ppc : dertobi123
   ppc64 : corsair
   sparc : fmccor
     x86 : maekke, armin76
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jer@gentoo.org</who>
            <bug_when>2008-08-20 15:47:43 0000</bug_when>
            <thetext>HPPA is OK.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>maekke@gentoo.org</who>
            <bug_when>2008-08-20 17:50:38 0000</bug_when>
            <thetext>looks good on amd64/x86.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>corsair@gentoo.org</who>
            <bug_when>2008-08-20 22:39:48 0000</bug_when>
            <thetext>looks good on ppc64</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>yoswink@gentoo.org</who>
            <bug_when>2008-08-20 23:24:44 0000</bug_when>
            <thetext>alpha is ok</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-08-26 14:32:05 0000</bug_when>
            <thetext>now public via http://secunia.com/advisories/31610/</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>rbu@gentoo.org</who>
            <bug_when>2008-08-26 14:53:44 0000</bug_when>
            <thetext>I combined both patches into one because it was decided to combine both issues (Drew Yao and the upstream bug) into the CVE. Committed the ebuild to the tree with the gathered keywords, still to do:

Arches, please test and mark stable:
=media-libs/tiff-3.8.2-r4
Target keywords : &quot;alpha amd64 arm hppa ia64 m68k ppc ppc64 s390 sh sparc x86&quot;
Already stabled : &quot;alpha amd64 hppa ppc64 x86&quot;
Missing keywords: &quot;arm ia64 m68k ppc s390 sh sparc&quot;
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>armin76@gentoo.org</who>
            <bug_when>2008-08-26 15:04:09 0000</bug_when>
            <thetext>ia64/sparc stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>dertobi123@gentoo.org</who>
            <bug_when>2008-08-30 11:30:45 0000</bug_when>
            <thetext>ppc stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>keytoaster@gentoo.org</who>
            <bug_when>2008-09-02 17:01:59 0000</bug_when>
            <thetext>GLSA request filed.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>py@gentoo.org</who>
            <bug_when>2008-09-08 18:01:22 0000</bug_when>
            <thetext>GLSA 200809-07</thetext>
          </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>162354</attachid>
            <date>2008-08-06 12:44 0000</date>
            <desc>tiff-3.8.2-CVE-2008-2327.patch</desc>
            <filename>tiff-3.8.2-CVE-2008-2327.patch</filename>
            <type>text/plain</type>
            <data encoding="base64">SW5kZXg6IHRpZmYtMy44LjIvbGlidGlmZi90aWZfbHp3LmMKPT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gdGlmZi0z
LjguMi5vcmlnL2xpYnRpZmYvdGlmX2x6dy5jCisrKyB0aWZmLTMuOC4yL2xpYnRpZmYvdGlmX2x6
dy5jCkBAIC00MDgsNiArNDA4LDcgQEAgTFpXRGVjb2RlKFRJRkYqIHRpZiwgdGlkYXRhX3Qgb3Aw
LCB0c2l6ZQogCQkJYnJlYWs7CiAJCWlmIChjb2RlID09IENPREVfQ0xFQVIpIHsKIAkJCWZyZWVf
ZW50cCA9IHNwLT5kZWNfY29kZXRhYiArIENPREVfRklSU1Q7CisJCQlfVElGRm1lbXNldChmcmVl
X2VudHAsIDAsIChDU0laRS1DT0RFX0ZJUlNUKSpzaXplb2YgKGNvZGVfdCkpOwogCQkJbmJpdHMg
PSBCSVRTX01JTjsKIAkJCW5iaXRzbWFzayA9IE1BWENPREUoQklUU19NSU4pOwogCQkJbWF4Y29k
ZXAgPSBzcC0+ZGVjX2NvZGV0YWIgKyBuYml0c21hc2stMTsKQEAgLTYwNCw2ICs2MDUsNyBAQCBM
WldEZWNvZGVDb21wYXQoVElGRiogdGlmLCB0aWRhdGFfdCBvcDAsCiAJCQlicmVhazsKIAkJaWYg
KGNvZGUgPT0gQ09ERV9DTEVBUikgewogCQkJZnJlZV9lbnRwID0gc3AtPmRlY19jb2RldGFiICsg
Q09ERV9GSVJTVDsKKwkJCV9USUZGbWVtc2V0KGZyZWVfZW50cCwgMCwgKENTSVpFLUNPREVfRklS
U1QpKnNpemVvZiAoY29kZV90KSk7CiAJCQluYml0cyA9IEJJVFNfTUlOOwogCQkJbmJpdHNtYXNr
ID0gTUFYQ09ERShCSVRTX01JTik7CiAJCQltYXhjb2RlcCA9IHNwLT5kZWNfY29kZXRhYiArIG5i
aXRzbWFzazsK
</data>        

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>162356</attachid>
            <date>2008-08-06 12:44 0000</date>
            <desc>tiff-3.8.2-bug1929.patch</desc>
            <filename>tiff-3.8.2-bug1929.patch</filename>
            <type>text/plain</type>
            <data encoding="base64">SW5kZXg6IHRpZmYtMy44LjIvbGlidGlmZi90aWZfbHp3LmMKPT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gdGlmZi0z
LjguMi5vcmlnL2xpYnRpZmYvdGlmX2x6dy5jCisrKyB0aWZmLTMuOC4yL2xpYnRpZmYvdGlmX2x6
dy5jCkBAIC0yMzcsNiArMjM3LDEyIEBAIExaV1NldHVwRGVjb2RlKFRJRkYqIHRpZikKICAgICAg
ICAgICAgICAgICAgICAgc3AtPmRlY19jb2RldGFiW2NvZGVdLmxlbmd0aCA9IDE7CiAgICAgICAg
ICAgICAgICAgICAgIHNwLT5kZWNfY29kZXRhYltjb2RlXS5uZXh0ID0gTlVMTDsKICAgICAgICAg
ICAgICAgICB9IHdoaWxlIChjb2RlLS0pOworCQkvKg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kJCQkiTFpXRGVjb2RlOiBDb3Jy
dXB0ZWQgTFpXIHRhYmxlIGF0IHNjYW5saW5lICVkIiwKKwkJCQl0aWYtPnRpZl9yb3cpOworCQkJ
CXJldHVybiAoMCk7CisJCQl9CiAJCQkqb3ArKyA9IGNvZGUsIG9jYy0tOwogCQkJb2xkY29kZXAg
PSBzcC0+ZGVjX2NvZGV0YWIgKyBjb2RlOwogCQkJY29udGludWU7Cg==
</data>        

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>163378</attachid>
            <date>2008-08-20 12:48 0000</date>
            <desc>tiff-3.8.2-r4.ebuild</desc>
            <filename>tiff-3.8.2-r4.ebuild</filename>
            <type>text/plain</type>
            <data encoding="base64">IyBDb3B5cmlnaHQgMTk5OS0yMDA4IEdlbnRvbyBGb3VuZGF0aW9uCiMgRGlzdHJpYnV0ZWQgdW5k
ZXIgdGhlIHRlcm1zIG9mIHRoZSBHTlUgR2VuZXJhbCBQdWJsaWMgTGljZW5zZSB2MgojICRIZWFk
ZXI6IC92YXIvY3Zzcm9vdC9nZW50b28teDg2L21lZGlhLWxpYnMvdGlmZi90aWZmLTMuOC4yLXIz
LmVidWlsZCx2IDEuOSAyMDA4LzAzLzA0IDIyOjQxOjUyIG1hZWtrZSBFeHAgJAoKaW5oZXJpdCBl
dXRpbHMgbGlidG9vbAoKREVTQ1JJUFRJT049IkxpYnJhcnkgZm9yIG1hbmlwdWxhdGlvbiBvZiBU
SUZGIChUYWcgSW1hZ2UgRmlsZSBGb3JtYXQpIGltYWdlcyIKSE9NRVBBR0U9Imh0dHA6Ly93d3cu
cmVtb3Rlc2Vuc2luZy5vcmcvbGlidGlmZi8iClNSQ19VUkk9ImZ0cDovL2Z0cC5yZW1vdGVzZW5z
aW5nLm9yZy9wdWIvbGlidGlmZi8ke1B9LnRhci5negoJbWlycm9yOi8vZ2VudG9vLyR7UH0tdGlm
ZjJwZGYucGF0Y2guYnoyIgoKTElDRU5TRT0i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