Bug 64469 (CVE-2004-1308)

Summary: VUL-0: CVE-2004-1308: libtiff directory entry count Int Overflow
Product: [Novell Products] SUSE Security Incidents Reporter: Sebastian Krahmer <krahmer>
Component: IncidentsAssignee: Marcus Meissner <meissner>
Status: RESOLVED FIXED QA Contact: Security Team bot <security-team>
Severity: Major    
Priority: P3 - Medium CC: nadvornik, qa-bugs, security-team
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Whiteboard: CVE-2004-1308: CVSS v2 Base Score: 10.0 (AV:N/AC:L/Au:N/C:C/I:C/A:C)
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: libtiff.patchinfo

Description Sebastian Krahmer 2004-12-22 21:12:33 UTC
LibTIFF Directory Entry Count Integer Overflow Vulnerability 

iDEFENSE Security Advisory 12.21.04 
December 21, 2004


This software provides support for the Tag Image File Format (TIFF), a 
widely used format for storing image data. Included in this software 
distribution is a library, libtiff, for reading and writing TIFF, a 
small collection of tools for doing simple manipulations of TIFF images 
on UNIX systems, and documentation on the library and tools. A small 
assortment of TIFF-related software for UNIX that has been contributed 
by others is also included.

More information is available at the following site: 


Remote exploitation of a heap-based buffer overflow vulnerability 
within the LibTIFF package could allow attackers to execute arbitrary 

The vulnerability specifically exists due to insufficient validation of 
user-supplied data when calculating the size of a directory entry. A 
TIFF file includes a number of directory entry header fields that 
describe the data in the file. Included in these entries is an entry 
count and offset value that are calculated to determine the size and 
location of the data for that entry. If the directory entry type is 
TIFF_ASCII or TIFF_UNDEFINED, the a call to CheckMalloc is made in 
order to allocate space for the entry contents as shown below from 

cp = CheckMalloc(tif, dp->tdir_count+1, 1, mesg); 
if( (ok = (cp && TIFFFetchString(tif, dp, cp))) != 0 )
    cp[dp->tdir_count] = '\0';  /* XXX */

If the tdir_count is set to 0xffffffff, the increment will cause the 
function call to allocate 0 bytes of memory and later memcpy calls will 
cause the buffer to overflow. An attacker may generate a malicious TIFF 
file which takes advantage of this unchecked calculation to execute 
arbitrary code with permissions of the user opening the TIFF file.


Remote attackers may be able to execute arbitrary code with permissions 
of the user opening the malformed TIFF file. The exposure to this 
vulnerability is mitigated by the fact that user interaction is 
required and that the user must view the malicious TIFF file in an 
application that is linked to a vulnerable version of libtiff.


iDEFENSE has confirmed the existence of this vulnerability in LibTIFF 
3.5.7 and 3.7.0.

The following vendors distribute susceptible TIFF packages within their 
respective operating system distributions:

    - Debian Linux
    - Gentoo Linux
    - RedHat Linux
    - SuSE Linux 

Only open TIFF files from trusted users or in an application not linked 
against vulnerable versions of libtiff.

The following patch will address this vulnerability:

--- tif_dirread.c.bak  2004-12-19 21:04:00.000000000 +0300
+++ tif_dirread.c      2004-12-19 21:04:03.000000000 +0300
@@ -71,7 +71,7 @@
        * XXX: Check for integer overflow.
-      if (elem_size && bytes / elem_size == nmemb)
+      if (nmemb && elem_size && bytes / elem_size == nmemb)
       cp = (char*)_TIFFmalloc(bytes);
       if (cp == NULL)

(the same applies for tif_fax3.c)

This patch has been incorporated into libtiff 3.7.1.


A Mitre Corp. Common Vulnerabilities and Exposures (CVE) number has not
been assigned yet.


12/17/2004  Initial vendor notification
12/17/2004  iDEFENSE clients notified
12/21/2004  Coordinated public disclosure


The discoverer of this vulnerability wishes to remain anonymous.

Get paid for vulnerability research


Copyright (c) 2004 iDEFENSE, Inc.

Permission is granted for the redistribution of this alert
electronically. It may not be edited in any way without the express
written consent of iDEFENSE. If you wish to reprint the whole or any
part of this alert in any other medium other than electronically, please
email customerservice@idefense.com for permission.

Disclaimer: The information in the advisory is believed to be accurate
at the time of publishing based on currently available information. Use
of the information constitutes acceptance for use in an AS IS condition.
There are no warranties with regard to this information. Neither the
author nor the publisher accepts any liability for any direct, indirect,
or consequential loss or damage arising from use of, or reliance on,
this information.
Comment 1 Sebastian Krahmer 2004-12-22 21:12:34 UTC
<!-- SBZ_reproduce  -->
Comment 2 Sebastian Krahmer 2004-12-22 21:29:25 UTC
From: Dmitry V. Levin <ldv@altlinux.org>
To: vendor-sec@lst.de
Cc: Andrey Kiselev <dron@remotesensing.org>
Subject: Re: [vendor-sec] Re: additional tiffdump vulnerability
   1 Shown    ~28 lines  Text
   2          196 bytes  Application


On Wed, Dec 22, 2004 at 12:52:40PM +0100, Martin Pitt wrote:
> This patch will cause the else clause to be executed, which will call
> malloc() with a negative value. This can still lead to buffer
> overflows AFAICS. Thus I propose the following patch:

What about this?

--- tiff-3.7.1/tools/tiffdump.c.orig   2004-09-03 12:16:01 +0400
+++ tiff-3.7.1/tools/tiffdump.c2004-12-22 01:57:51 +0300
@@ -307,6 +307,11 @@ ReadDirectory(int fd, unsigned ix, off_t
       space = dp->tdir_count * datawidth[dp->tdir_type];
+      if (space <= 0) {
+      printf(">\n");
+      Error("Invalid count for tag %u", dp->tdir_tag);
+      continue;
+      }
       if (space <= 4) {
       switch (dp->tdir_type) {
       case TIFF_FLOAT:

Comment 3 Marcus Meissner 2005-01-03 19:01:11 UTC
Comment 4 Marcus Meissner 2005-01-03 19:02:10 UTC
Comment 5 Vladimir Nadvornik 2005-01-03 23:56:53 UTC
Packages are submitted to 8.1 - 9.2 
Can you please submit patchinfos? 
Comment 6 Marcus Meissner 2005-01-03 23:58:16 UTC
will do that. 
Comment 7 Marcus Meissner 2005-01-04 00:18:34 UTC
Created attachment 27359 [details]

8.1 - 9.0 box patchinfo
Comment 8 Marcus Meissner 2005-01-04 00:18:53 UTC
Created attachment 27360 [details]

9.2 box patchinfo
Comment 9 Marcus Meissner 2005-01-04 00:19:16 UTC
Created attachment 27361 [details]

libtiff maintained patchinfo
Comment 10 Marcus Meissner 2005-01-04 00:19:43 UTC
Created attachment 27362 [details]

tiff maintained patchinfo (for tiffdump)
Comment 11 Marcus Meissner 2005-01-06 01:04:40 UTC
updated packages approved. 
Comment 12 Marcus Meissner 2005-01-08 00:45:12 UTC
CAN-2004-1308 more likely ... 
Comment 13 Marcus Meissner 2005-01-08 00:46:39 UTC
CAN-2004-1183 is for the tiffdump problem also fixed here. (comment #2) 
Comment 14 Marcus Meissner 2005-01-10 21:26:08 UTC
advisory released. 
Comment 15 Thomas Biege 2009-10-13 20:08:10 UTC
CVE-2004-1308: CVSS v2 Base Score: 10.0 (AV:N/AC:L/Au:N/C:C/I:C/A:C)