Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: <filtered@awaresystems.be>
Received: from mx5.public.one.com ([10.246.18.25])
	by mail6.local.one.com (Dovecot) with LMTP id ajr5AMmoe1exRgEAsyOMew
	for <filtered@awaresystems.be>; Tue, 05 Jul 2016 12:43:11 +0000
X-HalOne-ID: 07bc987f-42ae-11e6-953a-b82a72d82f61
Received: from mail-qt0-f177.google.com (unknown [209.85.216.177])
	by mx5.public.one.com (Halon Mail Gateway) with ESMTPS
	for <filtered@awaresystems.be>; Tue,  5 Jul 2016 12:43:10 +0000 (UTC)
Received: by mail-qt0-f177.google.com with SMTP id f89so99813482qtd.2
        for <filtered@awaresystems.be>; Tue, 05 Jul 2016 05:43:09 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-original-authentication-results:x-gm-message-state:delivered-to
         :mime-version:date:from:to:message-id:user-agent:subject:precedence
         :list-id:list-unsubscribe:list-archive:list-post:list-help
         :list-subscribe:content-transfer-encoding:sender:errors-to;
        bh=upYZvgWclYyGWW52RzPLQQxjXpJlTwiYUseHgnUrKTA=;
        b=HDSS6VqqQlDh7AU5EEzQrtNYmpaatKDWW3cpVArfiQvca1c0OEdb9oz63Moh4BveGO
         hU8k6chDNKdP6te4oF5GscTPcKEvUQR/5lNMLclUjXrZuFInDOCCx1ZWbu4BGLU42OKy
         2kd/cYhxQXOd4HGH5zI+58i7o4lPXXBNIpgSPr4S8ao0LuQZb7D8Yfi4BPRy5yqBYQYo
         oNUQopTP8+JdthLSuCjy1DHSxR5c1gQiF+vKL9uY8wIrjaP09gu+pv0b9KpavC+gmWQ7
         9OHMlxMOTVgyK5uJTt09Q38gj1xitpoNJ25y9Bza2GqyMOLRV0Pz0G1bPyUeJGgtJ16y
         CRiA==
X-Original-Authentication-Results: mx.google.com;       spf=neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) smtp.mailfrom=tiff-bounces@lists.maptools.org
X-Gm-Message-State: ALyK8tJ2vdVKjPTnkNqI6ExBA81eYNLXa4y+x5TWVk8vZ+YXDjuwFNA1fEJ5DAF02tWTH2Ete1XM26xm5mnEV11pYpAZcqM=
X-Received: by 10.200.39.66 with SMTP id h2mr25452515qth.7.1467722588739;
        Tue, 05 Jul 2016 05:43:08 -0700 (PDT)
X-Forwarded-To: filtered@awaresystems.be
X-Forwarded-For: awaresystems.be@gmail.com filtered@awaresystems.be
Delivered-To: awaresystems.be@gmail.com
Received: by 10.55.147.70 with SMTP id v67csp246576qkd;
        Tue, 5 Jul 2016 05:43:07 -0700 (PDT)
X-Received: by 10.194.87.169 with SMTP id az9mr9983811wjb.158.1467722587730;
        Tue, 05 Jul 2016 05:43:07 -0700 (PDT)
Return-Path: <tiff-bounces@lists.maptools.org>
Received: from lists.maptools.org (ks365428.kimsufi.com. [94.23.4.142])
        by mx.google.com with ESMTP id a79si3637623wma.76.2016.07.05.05.43.07;
        Tue, 05 Jul 2016 05:43:07 -0700 (PDT)
Received-SPF: neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) client-ip=94.23.4.142;
Authentication-Results: mx.google.com;
       spf=neutral (google.com: 94.23.4.142 is neither permitted nor denied by best guess record for domain of tiff-bounces@lists.maptools.org) smtp.mailfrom=tiff-bounces@lists.maptools.org
Received: from [10.1.0.241] (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 5795535C03F;
	Tue,  5 Jul 2016 07:42:11 -0500 (EST)
Received: from b.painless.aa.net.uk (b.painless.aa.net.uk [81.187.30.52])
	by lists.maptools.org (Postfix) with ESMTPS id 6989135C027
	for <tiff@lists.maptools.org>; Tue,  5 Jul 2016 07:40:03 -0500 (EST)
Received: from webmail2.aa.net.uk ([2001:8b0:0:30::56] helo=webmail.aa.net.uk)
	by b.painless.aa.net.uk with esmtpa (Exim 4.77)
	(envelope-from <rleigh@codelibre.net>) id 1bKPdy-0003ny-Lz
	for tiff@lists.maptools.org; Tue, 05 Jul 2016 13:40:02 +0100
Received: from [134.36.162.214] by webmail.aa.net.uk
	with HTTP (HTTP/1.1 POST); Tue, 05 Jul 2016 13:40:02 +0100
MIME-Version: 1.0
Date: Tue, 05 Jul 2016 12:40:02 +0000
From: rleigh@codelibre.net
To: tiff@lists.maptools.org
Message-ID: <a7454b814bbcfbc3a755af74bc2b9cac@codelibre.net>
X-Sender: rleigh@codelibre.net
User-Agent: Roundcube Webmail/1.1.4
Subject: [Tiff] Sanity checking and robustness
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

With regards to these bugs:

   http://bugzilla.maptools.org/show_bug.cgi?id=2524
   https://github.com/ome/ome-files-cpp/issues/22

I was looking at the possibilities for adding stricter bounds checks so 
that we could avoid allocations when the field values are obviously 
incorrect, the most obvious of which would be where the offset and size 
of some data would exceed the file size.

Is the size of the TIFF stored anywhere accessible on read, e.g. in the 
tiff struct?  If not, would it be possible to add this?

I found _tiffSizeProc(fd) but it's not public, and not even exposed for 
internal use by other translation units.  Would adding it to an internal 
header be possible, so we can call it either when initialising the tiff 
struct on read, or before performing allocations inside field accessor 
functions?

While being safe in the face of any possible error in the TIFF file 
being read is a significant challenge, it looks like there are a few 
simple checks which could be added to greatly improve the robustness of 
the library (and any application using it) by preventing 
untrusted/invalid input from causing potentially multi-gigabyte memory 
allocations where this is obviously wrong.


Thanks,
Roger
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
