Received: by mail.netbsd.org (Postfix, from userid 605) id B335884E2A; Thu, 25 Oct 2018 22:58:07 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id A88E684E29 for ; Thu, 25 Oct 2018 22:58:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([127.0.0.1]) by localhost (mail.netbsd.org [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id ELt7adRlVdOA for ; Thu, 25 Oct 2018 22:58:05 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.netbsd.org [199.233.217.197]) by mail.netbsd.org (Postfix) with ESMTP id 8E8CA84E24 for ; Thu, 25 Oct 2018 22:58:05 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id 79B9AFBEE; Thu, 25 Oct 2018 22:58:05 +0000 (UTC) Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_1540508285238610" MIME-Version: 1.0 Date: Thu, 25 Oct 2018 22:58:05 +0000 From: "Maya Rashish" Subject: CVS commit: pkgsrc/graphics/tiff To: pkgsrc-changes@NetBSD.org Reply-To: maya@netbsd.org X-Mailer: log_accum Message-Id: <20181025225805.79B9AFBEE@cvs.NetBSD.org> Sender: pkgsrc-changes-owner@NetBSD.org List-Id: pkgsrc-changes.NetBSD.org Precedence: bulk List-Unsubscribe: This is a multi-part message in MIME format. --_----------=_1540508285238610 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Module Name: pkgsrc Committed By: maya Date: Thu Oct 25 22:58:05 UTC 2018 Modified Files: pkgsrc/graphics/tiff: Makefile distinfo Added Files: pkgsrc/graphics/tiff/patches: patch-libtiff_tif__jbig.c patch-libtiff_tif__read.c Log Message: tiff: apply fix for CVE-2018-18557 From 681748ec2f5ce88da5f9fa6831e1653e46af8a66 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 14 Oct 2018 16:38:29 +0200 Subject: [PATCH 1/1] JBIG: fix potential out-of-bounds write in JBIGDecode() JBIGDecode doesn't check if the user provided buffer is large enough to store the JBIG decoded image, which can potentially cause out-of-bounds write in the buffer. This issue was reported and analyzed by Thomas Dullien. Also fixes a (harmless) potential use of uninitialized memory when tif->tif_rawsize > tif->tif_rawcc And in case libtiff is compiled with CHUNKY_STRIP_READ_SUPPORT, make sure that whole strip data is provided to JBIGDecode() The last part (CHUNKY_STRIP_READ_SUPPORT) was adapted by myself to fit the libtiff release. Bump PKGREVISION. To generate a diff of this commit: cvs rdiff -u -r1.141 -r1.142 pkgsrc/graphics/tiff/Makefile cvs rdiff -u -r1.90 -r1.91 pkgsrc/graphics/tiff/distinfo cvs rdiff -u -r0 -r1.1 pkgsrc/graphics/tiff/patches/patch-libtiff_tif__jbig.c \ pkgsrc/graphics/tiff/patches/patch-libtiff_tif__read.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. --_----------=_1540508285238610 Content-Disposition: inline Content-Length: 5509 Content-Transfer-Encoding: binary Content-Type: text/x-diff; charset=us-ascii Modified files: Index: pkgsrc/graphics/tiff/Makefile diff -u pkgsrc/graphics/tiff/Makefile:1.141 pkgsrc/graphics/tiff/Makefile:1.142 --- pkgsrc/graphics/tiff/Makefile:1.141 Thu Jun 21 23:11:04 2018 +++ pkgsrc/graphics/tiff/Makefile Thu Oct 25 22:58:05 2018 @@ -1,7 +1,7 @@ -# $NetBSD: Makefile,v 1.141 2018/06/21 23:11:04 tez Exp $ +# $NetBSD: Makefile,v 1.142 2018/10/25 22:58:05 maya Exp $ DISTNAME= tiff-4.0.9 -PKGREVISION= 3 +PKGREVISION= 4 CATEGORIES= graphics MASTER_SITES= ftp://download.osgeo.org/libtiff/ Index: pkgsrc/graphics/tiff/distinfo diff -u pkgsrc/graphics/tiff/distinfo:1.90 pkgsrc/graphics/tiff/distinfo:1.91 --- pkgsrc/graphics/tiff/distinfo:1.90 Thu Jun 21 23:11:04 2018 +++ pkgsrc/graphics/tiff/distinfo Thu Oct 25 22:58:05 2018 @@ -1,4 +1,4 @@ -$NetBSD: distinfo,v 1.90 2018/06/21 23:11:04 tez Exp $ +$NetBSD: distinfo,v 1.91 2018/10/25 22:58:05 maya Exp $ SHA1 (tiff-4.0.9.tar.gz) = 87d4543579176cc568668617c22baceccd568296 RMD160 (tiff-4.0.9.tar.gz) = ab5b3b7297e79344775b1e70c4d54c90c06836a3 @@ -7,4 +7,6 @@ Size (tiff-4.0.9.tar.gz) = 2305681 bytes SHA1 (patch-CVE-2017-9935) = d33f3311e5bb96bf415f894237ab4dfcfafd2610 SHA1 (patch-CVE-2018-8905) = 3a7081957ff2f4d6e777df5a9609ba89eecd8fbc SHA1 (patch-configure) = a0032133f06b6ac92bbf52349fabe83f74ea14a6 +SHA1 (patch-libtiff_tif__jbig.c) = feb404c5c70c0f4f10fa53351fab4db163bbccf3 +SHA1 (patch-libtiff_tif__read.c) = a69f7a462e0dfe6b01240816ed546d7e381044e8 SHA1 (patch-tools_pal2rgb.c) = f91652e8013940c162add870ceb9845e2730bc2c Added files: Index: pkgsrc/graphics/tiff/patches/patch-libtiff_tif__jbig.c diff -u /dev/null pkgsrc/graphics/tiff/patches/patch-libtiff_tif__jbig.c:1.1 --- /dev/null Thu Oct 25 22:58:05 2018 +++ pkgsrc/graphics/tiff/patches/patch-libtiff_tif__jbig.c Thu Oct 25 22:58:05 2018 @@ -0,0 +1,77 @@ +$NetBSD: patch-libtiff_tif__jbig.c,v 1.1 2018/10/25 22:58:05 maya Exp $ + +From 681748ec2f5ce88da5f9fa6831e1653e46af8a66 (CVE-2018-18557) + +JBIGDecode doesn't check if the user provided buffer is large enough +to store the JBIG decoded image, which can potentially cause out-of-bounds +write in the buffer. +This issue was reported and analyzed by Thomas Dullien. + +Also fixes a (harmless) potential use of uninitialized memory when +tif->tif_rawsize > tif->tif_rawcc + +--- libtiff/tif_jbig.c.orig 2017-06-30 13:27:54.399206925 +0000 ++++ libtiff/tif_jbig.c +@@ -53,17 +53,18 @@ static int JBIGDecode(TIFF* tif, uint8* + struct jbg_dec_state decoder; + int decodeStatus = 0; + unsigned char* pImage = NULL; +- (void) size, (void) s; ++ unsigned long decodedSize; ++ (void) s; + + if (isFillOrder(tif, tif->tif_dir.td_fillorder)) + { +- TIFFReverseBits(tif->tif_rawdata, tif->tif_rawdatasize); ++ TIFFReverseBits(tif->tif_rawcp, tif->tif_rawcc); + } + + jbg_dec_init(&decoder); + + #if defined(HAVE_JBG_NEWLEN) +- jbg_newlen(tif->tif_rawdata, (size_t)tif->tif_rawdatasize); ++ jbg_newlen(tif->tif_rawcp, (size_t)tif->tif_rawcc); + /* + * I do not check the return status of jbg_newlen because even if this + * function fails it does not necessarily mean that decoding the image +@@ -76,8 +77,8 @@ static int JBIGDecode(TIFF* tif, uint8* + */ + #endif /* HAVE_JBG_NEWLEN */ + +- decodeStatus = jbg_dec_in(&decoder, (unsigned char*)tif->tif_rawdata, +- (size_t)tif->tif_rawdatasize, NULL); ++ decodeStatus = jbg_dec_in(&decoder, (unsigned char*)tif->tif_rawcp, ++ (size_t)tif->tif_rawcc, NULL); + if (JBG_EOK != decodeStatus) + { + /* +@@ -98,9 +99,28 @@ static int JBIGDecode(TIFF* tif, uint8* + return 0; + } + ++ decodedSize = jbg_dec_getsize(&decoder); ++ if( (tmsize_t)decodedSize < size ) ++ { ++ TIFFWarningExt(tif->tif_clientdata, "JBIG", ++ "Only decoded %lu bytes, whereas %lu requested", ++ decodedSize, (unsigned long)size); ++ } ++ else if( (tmsize_t)decodedSize > size ) ++ { ++ TIFFErrorExt(tif->tif_clientdata, "JBIG", ++ "Decoded %lu bytes, whereas %lu were requested", ++ decodedSize, (unsigned long)size); ++ jbg_dec_free(&decoder); ++ return 0; ++ } + pImage = jbg_dec_getimage(&decoder, 0); +- _TIFFmemcpy(buffer, pImage, jbg_dec_getsize(&decoder)); ++ _TIFFmemcpy(buffer, pImage, decodedSize); + jbg_dec_free(&decoder); ++ ++ tif->tif_rawcp += tif->tif_rawcc; ++ tif->tif_rawcc = 0; ++ + return 1; + } + Index: pkgsrc/graphics/tiff/patches/patch-libtiff_tif__read.c diff -u /dev/null pkgsrc/graphics/tiff/patches/patch-libtiff_tif__read.c:1.1 --- /dev/null Thu Oct 25 22:58:05 2018 +++ pkgsrc/graphics/tiff/patches/patch-libtiff_tif__read.c Thu Oct 25 22:58:05 2018 @@ -0,0 +1,23 @@ +$NetBSD: patch-libtiff_tif__read.c,v 1.1 2018/10/25 22:58:05 maya Exp $ + +And in case libtiff is compiled with CHUNKY_STRIP_READ_SUPPORT, make sure +that whole strip data is provided to JBIGDecode() + +Part of commit 681748ec2f5ce88da5f9fa6831e1653e46af8a66 which fixes +CVE-2018-18557 + +--- libtiff/tif_read.c.orig 2017-11-18 14:42:21.664534434 +0000 ++++ libtiff/tif_read.c +@@ -348,6 +348,12 @@ TIFFSeek(TIFF* tif, uint32 row, uint16 s + return 0; + whole_strip = tif->tif_dir.td_stripbytecount[strip] < 10 + || isMapped(tif); ++ if( td->td_compression == COMPRESSION_JBIG ) ++ { ++ /* Ideally plugins should have a way to declare they don't support ++ * chunk strip */ ++ whole_strip = 1; ++ } + #else + whole_strip = 1; + #endif --_----------=_1540508285238610--