Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: filtered@awaresystems.be
Received: from mx1.public.one.com ([10.246.18.21])
	by mail6.local.one.com (Dovecot) with LMTP id YsSjA/Ang1mM0gAAsyOMew
	for <filtered@awaresystems.be>; Thu, 03 Aug 2017 15:25:27 +0000
X-HalOne-ID: f8248c2d-785f-11e7-9341-b82a72d859f1
Received: from mail-oi0-f51.google.com (unknown [209.85.218.51])
	by mx1.public.one.com (Halon) with ESMTPS
	id f8248c2d-785f-11e7-9341-b82a72d859f1;
	Thu, 03 Aug 2017 15:25:24 +0000 (UTC)
Received: by mail-oi0-f51.google.com with SMTP id g131so15551872oic.3
        for <filtered@awaresystems.be>; Thu, 03 Aug 2017 08:25:24 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-original-authentication-results:x-gm-message-state:delivered-to
         :date:from:to:in-reply-to:message-id:references:user-agent
         :mime-version:cc:subject:precedence:list-id:list-unsubscribe
         :list-archive:list-post:list-help:list-subscribe
         :content-transfer-encoding:sender:errors-to;
        bh=oa3arfefilYTRo0Doz8hFR0VCAIPltFWmVKVS80M3zY=;
        b=rJr+ANfA/pds5dEpuDiWjQqBopQeMoT6/1GDXV1p2GgTldWL5dwnHB+DxynsCQayU3
         oHjE80PZuKbedwqULEZVjmsSwltAznQi5e+/CCqHy/nSef/ZFqStNdWhVd/InOzMhqyZ
         wXKWpEO4BXBSSocoQqFa52gukzNyXmONs/DBwPcMg6H+E1E0weytgmeUEa9g4vKFIjQV
         pkCWspe3tyBPW/ig3cg1qSbWXvvfzAMo3juz7EUXP/tSfZ5oaTOllLs/ZKkxW82gGLb4
         PYk823oo1OOn9TtsJkc54mfcUbK2ET+NIgHNo6wqm84KDGKaAbp2t33eMoTZaSNrbLdQ
         vkZw==
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: AIVw113HiOfu2juQrIHiTByElMpsCLQ+lFdBJlzo9PDpWBx3Roq2JY4L
	uaM+sPCvsBg33rHaqTwzN+8bPwbe2HPxxbo+qg/qxA==
X-Received: by 10.202.66.7 with SMTP id p7mr2047106oia.162.1501773922406;
        Thu, 03 Aug 2017 08:25:22 -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.74.68.1 with SMTP id o1csp925505ooa;
        Thu, 3 Aug 2017 08:25:21 -0700 (PDT)
X-Received: by 10.28.182.84 with SMTP id g81mr1455471wmf.100.1501773920957;
        Thu, 03 Aug 2017 08:25:20 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1501773920; cv=none;
        d=google.com; s=arc-20160816;
        b=yfVnpq7nI2+F9oqy5qcLsawDQRn2gFwxgDxq3lWrrQN93dFxhYe3nXTXT2fX76uTY3
         yhN7pzad1pi6AkzKVy7UvxYc/pwfgrEAEOdOT8sBPnKF4QFICclh3iNdpvFZ6aHkTLo1
         yWq3RuDCUkdaKYjbbHjTHDGA4+T6DTflz4zsXK3qf24qjzx0FWabr4JUfUBFz+dikz7c
         6K6yRrlQBzOHFPMaKVmu3qrVmqw2uwrXJS4mC3Fzb+/dafyi3xgGDano98in+N123cLN
         rcQevb1Uc6aVFvVqXyuXdY1m5RPArS8TyZqG+GRLxm2lGqhLKrWLmQZqMrSwUiVW/hNC
         8GPQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help
         :list-post:list-archive:list-unsubscribe:list-id:precedence:subject
         :cc:mime-version:user-agent:references:message-id:in-reply-to:to
         :from:date:arc-authentication-results;
        bh=oa3arfefilYTRo0Doz8hFR0VCAIPltFWmVKVS80M3zY=;
        b=hdVaFGlEFNuLoZPK560YniJnzg+NtsA/jfI2sVVxMJr04UhthycSaQYM3/H7lUvWAD
         G2ZHivP451f0zS8nOwpKbLaNRp8hQ6vjxvckcBLS30vAl1IJIn9jkQP78TCy7/HhU6mb
         CkPdHu59Dgvqo9/8Yu8rJeY1hhj7rA5dLp1iSLQUfhcP+xcHIVh8lcnUV8frbMyRAxtw
         EgzkUxh/3NGwkHeYMPIbScx4BO0MHvm4sT0TBcGo6r+/AtyDNQcWCTNWjsbq+Z9pYXzS
         7JZvJ1GeVsGyjwO270bQd+nrQKGEWzBOJvqGRL3Z1keZZKuuwHCE+lqu1vBIATlEUKRF
         OisA==
ARC-Authentication-Results: i=1; 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
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 23si1833395wrt.4.2017.08.03.08.25.20;
        Thu, 03 Aug 2017 08:25:20 -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 4137C35C038;
	Thu,  3 Aug 2017 10:24:16 -0500 (EST)
Received: from smtp.simplesystems.org (smtp.simplesystems.org [65.66.246.90])
	by lists.maptools.org (Postfix) with ESMTPS id 6961635C036
	for <tiff@lists.maptools.org>; Thu,  3 Aug 2017 10:23:08 -0500 (EST)
Received: from scrappy.simplesystems.org (scrappy.simplesystems.org
	[65.66.246.73])
	by smtp.simplesystems.org (8.14.4+Sun/8.14.4) with ESMTP id
	v73FN5oX021273; Thu, 3 Aug 2017 10:23:05 -0500 (CDT)
Date: Thu, 3 Aug 2017 10:23:05 -0500 (CDT)
From: Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
X-X-Sender: bfriesen@scrappy.simplesystems.org
To: Nicolas RUFF <nicolas.ruff@gmail.com>
In-Reply-To: <CABoQFUCwG6Nb7GNwkU1xp-jdUP2eeEqWdGoYXkHs2t2fJzc2GA@mail.gmail.com>
Message-ID: <alpine.GSO.2.20.1708031016050.18408@scrappy.simplesystems.org>
References: <CABoQFUD-RYPQeJSCBPVdXNeA-yESnHH1QcySUPd3QA=SxMcOOA@mail.gmail.com>
	<alpine.GSO.2.20.1708021019070.287@scrappy.simplesystems.org>
	<CABoQFUCwG6Nb7GNwkU1xp-jdUP2eeEqWdGoYXkHs2t2fJzc2GA@mail.gmail.com>
User-Agent: Alpine 2.20 (GSO 67 2015-01-07)
MIME-Version: 1.0
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16
	(smtp.simplesystems.org [65.66.246.90]);
	Thu, 03 Aug 2017 10:23:05 -0500 (CDT)
Cc: tiff@lists.maptools.org
Subject: Re: [Tiff] Error handling in Read/Write/Seek
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

On Thu, 3 Aug 2017, Nicolas RUFF wrote:

>> It seems best to block any negative size values from being passed into these
>> functions in the first place.  Libtiff is not in control of the I/O
>> functions, so it is best to assure that they are not passed illegal values
>> which might cause I/O implementations to do very bad things.
>
> Not sure to understand what you mean here. Here are all call locations
> for SeekOK():
> tif_dir.c : 2 times
> tif_read.c : 4 times
> tif_write.c : 1 time
> tif_dirread.c : 3 times
> tif_dirwrite.c : 9 times
>
> Do you suggest to add an extra check for (off<0) before each call? If
> yes, I can prepare a patch.

Yes, I am suggesting that it is best to avoid passing a wrong request 
to the I/O functions (which might have been implemented by a library 
user or are implemented in a C library on any operating system libtiff 
may be compiled on) rather than dealing with a subsquent possible 
error return due to the wrong request.  This approach assures 
consistent behavior.  It can also produce a better quality (more 
appropriate) error message for the library user.

> Also, is there any chance that TIFFSeekFile() could legitimately be
> called with off<0 and whence=SEEK_CUR? I mean, is there any reason to
> seek backward in a TIFF file? Looking at the code, the only calls to
> TIFFSeekFile(whence=SEEK_CUR) take (dircount*object_size) as an offset
> and should therefore always be positive, but I am not super-familiar
> with TIFF format(s).

I don't know what might happen in the future.  We only know what 
libtiff does now.  The seek operation used should be apparent at each 
call point.

Bob
-- 
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
