Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84637 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70733 invoked from network); 12 Mar 2015 13:47:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2015 13:47:51 -0000 Authentication-Results: pb1.pair.com header.from=mike.php.net@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=mike.php.net@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.44 as permitted sender) X-PHP-List-Original-Sender: mike.php.net@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:44205] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 63/E4-42021-60991055 for ; Thu, 12 Mar 2015 08:47:50 -0500 Received: by wghl18 with SMTP id l18so16439693wgh.11 for ; Thu, 12 Mar 2015 06:47:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=6/RZLSQCmQjX6+o2h+r/0vfhNQRX2SIxGtDKA8/9tZY=; b=ZYo1UGgjKb8ZwaMpTTgT0Bv0Ss92P46cMdXeBinBjmi569Pf03V/dBwGKDS03ucB7P eQjj3VbMRfNPdSsIYT/F4SJARLogKDsVUZLWqP39pZk/l0g7wSTUYWAujdxprWNY/vnV fJXHOir9yscaejH8uqbtnHYtFsLsii2/0lkvBQwdLY144VY3aV9pk1umo3+mt7msBdfR Hl52xHymqM41CIMgYf1LNhGvwSwnm2VkFFCtQBr0hJX1Q+UW0Cxwn/5CgC/0UOphjqnG qU9+5PmOMUiQMu/xZK0lp3K8eYE0luaIOM33oxO2ndGkggKvl8iIh3f5Z1IGa4nxQNMV FPdA== X-Received: by 10.194.142.205 with SMTP id ry13mr89702738wjb.73.1426168066778; Thu, 12 Mar 2015 06:47:46 -0700 (PDT) Received: from [192.168.2.121] (89-104-28-113.customer.bnet.at. [89.104.28.113]) by mx.google.com with ESMTPSA id gd6sm11192078wib.17.2015.03.12.06.47.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Mar 2015 06:47:45 -0700 (PDT) Sender: Michael Wallner Message-ID: <55019901.3090107@php.net> Date: Thu, 12 Mar 2015 14:47:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Umberto Salsi , internals@lists.php.net References: <2D.74.42021.0A491055@pb1.pair.com> In-Reply-To: <2D.74.42021.0A491055@pb1.pair.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] php_stream_read(...) may return less than expected From: mike@php.net (Michael Wallner) On 12/03/15 14:28, Umberto Salsi wrote: > Hi all, > I'm not a PHP internals developer, but this might be a bug spread here and > there in the source. This coding pattern: > > if(php_stream_read(..., n) != n){ > php_error_docref(NULL TSRMLS_CC, E_SOMETHING, "Read error!"); > > seems wrong to me because there might be streams that returns less than > n bytes at once. When exactly n bytes are expected, not more not less, > a function similar to this one should be used instead: > > int php_stream_read_fully(..., int n){ > continue calling php_stream_read() until exactly n bytes are > collected, or a premature EOF, or I/O error > } > > I ran into this issue passing a custom stream to getimagesize(): > > getimagesize("myprotocol://"); > > where myprotocol:// may, in some situations, return less bytes than > expected (see the http://php.net/manual/en/class.streamwrapper.php > wrapper class, stream_read() method). Looking at the implementation of > this function in ext/standard/image.c, I just found the pattern above. > If this is really a bug, many other functions might be affected. Why does your stream behave non-blocking by default? Unless explicitly stated, those callees probably expect a blocking stream. -- Regards, Mike