Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84636 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68541 invoked from network); 12 Mar 2015 13:29:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2015 13:29:07 -0000 X-Host-Fingerprint: 88.149.172.234 88-149-172-234.v4.ngi.it Received: from [88.149.172.234] ([88.149.172.234:11879] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/74-42021-0A491055 for ; Thu, 12 Mar 2015 08:29:05 -0500 Message-ID: <2D.74.42021.0A491055@pb1.pair.com> To: internals@lists.php.net User-Agent: tt v. 1.0.5, http://www.icosaedro.it/tt Date: Thu, 12 Mar 2015 14:28:48 +0100 X-Posted-By: 88.149.172.234 Subject: php_stream_read(...) may return less than expected From: salsi@icosaedro.it (Umberto Salsi) 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. Regards, ___ /_|_\ Umberto Salsi \/_\/ www.icosaedro.it