From owner-freebsd-hackers@freebsd.org Sun May 22 23:11:05 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8A716B3B6EA for ; Sun, 22 May 2016 23:11:05 +0000 (UTC) (envelope-from joerg@bec.de) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 534791319; Sun, 22 May 2016 23:11:05 +0000 (UTC) (envelope-from joerg@bec.de) Received: from mfilter14-d.gandi.net (mfilter14-d.gandi.net [217.70.178.142]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 3B3D9A80C2; Mon, 23 May 2016 01:10:57 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter14-d.gandi.net Received: from relay3-d.mail.gandi.net ([IPv6:::ffff:217.70.183.195]) by mfilter14-d.gandi.net (mfilter14-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id I5PUNUZLeW94; Mon, 23 May 2016 01:10:55 +0200 (CEST) X-Originating-IP: 108.61.101.156 Received: from britannica.bec.de (unknown [108.61.101.156]) (Authenticated sender: joerg@bec.de) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id A5AFDA80C6; Mon, 23 May 2016 01:10:53 +0200 (CEST) Date: Mon, 23 May 2016 01:10:48 +0200 From: Joerg Sonnenberger To: Conrad Meyer Cc: Dirk Engling , FreeBSD Hackers Subject: Re: read(2) and thus bsdiff is limited to 2^31 bytes Message-ID: <20160522231048.GA25503@britannica.bec.de> Mail-Followup-To: Conrad Meyer , Dirk Engling , FreeBSD Hackers References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.1 (2016-04-27) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 May 2016 23:11:05 -0000 On Sun, May 22, 2016 at 03:56:33PM -0700, Conrad Meyer wrote: > On Sun, May 22, 2016 at 1:54 PM, Dirk Engling wrote: > > When trying to bsdiff two DVD images, I noticed it failing due to > > read(2) returning EINVAL to the tool. man 2 read says, this would only > > happen for a negative value for fildes, which clearly was not true. > > Actually, it's documented at the very bottom of the first section: > > ERRORS > The read(), readv(), pread() and preadv() system calls will succeed > unless: > ... > [EINVAL] The value nbytes is greater than INT_MAX. > > It does seem silly to me given nbytes is a size_t. I think it should > error if nbytes is greater than SSIZE_T_MAX, but on platforms where > size_t is larger than int (e.g. amd64) it shouldn't error for nbytes > in [INT_MAX, SSIZE_T_MAX - 1]. There are a lot of valid reasons for not doing arbitrarily large operations, especially since a certain amount of atomicity is expected for local IO. That doesn't mean that it can't be turned into a short read/write instead. Erroring out seeems completely unjustified. Joerg