Re: com php-src: Fix #71882: Negative ftruncate() on php://memory exhausts memory: NEWS ext/standard/file.c ext/standard/tests/file/bug71882.phpt
| From: | Christoph M. Becker | Date: | Wed, 31 Aug 2016 10:29:51 +0000 |
| Subject: | Re: com php-src: Fix #71882: Negative ftruncate() on php://memory exhausts memory: NEWS ext/standard/file.c ext/standard/tests/file/bug71882.phpt | ||
| References: | 1 2 3 4 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-94186@lists.php.net to get a copy of this message | ||
Hi Anatol!
On 31.08.2016 at 12:04, Anatol Belski wrote:
>
>> -----Original Message-----
>> From: Christoph M. Becker [mailto:cmbecker69@gmx.de]
>> Sent: Wednesday, August 31, 2016 11:45 AM
>> To: Matteo Beccati <php@beccati.com>; Anatol Belski
>> <anatol.php@belski.net>; php-cvs@lists.php.net
>> Cc: 'Ferenc Kovacs' <tyrael@php.net>; Davey Shafik <davey@php.net>
>> Subject: Re: [PHP-CVS] com php-src: Fix #71882: Negative ftruncate() on
>> php://memory exhausts memory: NEWS ext/standard/file.c
>> ext/standard/tests/file/bug71882.phpt
>>
>> On 31.08.2016 at 09:47, Matteo Beccati wrote:
>>
>>> negative size was tested in 4 existing phpt files, that are now
>>> failing due to the new warning. That seems a bit of a BC break to me.
>>
>> Okay, it might be better not to throw the warning (for BC), but in my opinion the
>> (zend)_long to size_t conversion has to be properly handled generally, not only
>> for memory streams.
>
> What is your suggestion? There's some general approach with Zend/zend_range_check.h, which
> still could be extended for +-/*, etc. But there are also many special cases where some individual
> solution is needed.
My suggestion is:
if (size < 0) {
/* php_error_docref(NULL TSRMLS_CC, E_WARNING, "Negative size is
not supported"); */
RETURN_FALSE;
}
And to uncomment the php_error_docref() call for master (maybe also 7.1).
>> I suggest to let ftruncate() silently fail (returning false) for negative sizes in PHP
>> 5.6 - 7.1, but to add a warning for master.
>>
>> Any objections?
>
> IMO the warning is useful, but the important part is the negative value check. Either way, the
> tests need to pass.
Of course, I will fix the tests, but how to do this depends on whether
ftruncate() will raise E_WARNING or not, so this should be decided
first. :-)
>>> https://revive.beccati.com/bamboo/browse/PHP-SRC/latest
>>>
>>> In fact ftruncate_variation4.phpt is dubbed "usage variations -
>>> truncate file to negative size". This is a reminder that we all should
>>> try to run the test suite before pushing changes, at least for the
>>> subset of functionalities that are affected by the commit ;)
>>
>> Running the tests is one thing, but ext/standard/tests/file/ has about
>> 90 failing test for me anyway. That's probably because I'm running in a Vagrant
>> Debian box on a Windows host in an NTFS folder. Running on Windows I still
>> have nearly 20 failing test, what's probably caused by running an admin account
>> with a console started without admin priviledges. So it's always a bit hard to
>> figure out if there's a regression.
>
> Looks like it's an environment issue. Many tests will likely to fail with a non English
> locale, as error messages from the CRT come localized. Still worth to check, could you please
> pastebin the diffs?
Indeed, I can remember at least some tests failing due to locale issues.
IIRC, I have fixed some (all?) of them quite long ago.
I'll investigate closer on this issue.
> In any case, checking travis should be a common habit :)
Yes, you're right. It would be nice, though, if an automatic mail could
be sent to the committer in case of failure.
Cheers!
> Thanks
>
> Anatol
>
>> I'll be more careful, though, next time.
>>
>> Cheers!
>>
>>> Cheers
>>>
>>> On 30/08/2016 02:05, Christoph Michael Becker wrote:
>>>> Commit: 207dab585aadd9f320976a0895734d7d9ca7b862
>>>> Author: Christoph M. Becker <cmbecker69@gmx.de> Tue, 30 Aug
>>>> 2016 01:53:27 +0200
>>>> Parents: c7b4cd1a51736b15d095b6b540f17076a0a8433d
>>>> Branches: PHP-5.6 PHP-7.0 PHP-7.1 master
>>>>
>>>> Link:
>>>>
>>>> http://git.php.net/?p=php-src.git;a=commitdiff;h=207dab585aadd9f32097
>>>> 6a0895734d7d9ca7b862
>>>>
>>>>
>>>> Log:
>>>> Fix #71882: Negative ftruncate() on php://memory exhausts memory
>>>>
>>>> We must not pass negative sizes to a size_t parameter.
>>>>
>>>> Bugs:
>>>> https://bugs.php.net/71882
>>>>
>>>> Changed paths:
>>>> M NEWS
>>>> M ext/standard/file.c
>>>> A ext/standard/tests/file/bug71882.phpt
>>>>
>>>>
>>>> Diff:
>>>> diff --git a/NEWS b/NEWS
>>>> index bc3d279..a05fa84 100644
>>>> --- a/NEWS
>>>> +++ b/NEWS
>>>> @@ -48,6 +48,8 @@
>>>> PHP
>>>> NEWS
>>>> . Fixed bug #72278 (getimagesize returning FALSE on valid jpg). (cmb)
>>>> . Fixed bug #65550 (get_browser() incorrectly parses entries with
>>>> "+" sign).
>>>> (cmb)
>>>> + . Fixed bug #71882 (Negative ftruncate() on php://memory exhausts
>>>> memory).
>>>> + (cmb)
>>>>
>>>> - XML:
>>>> . Fixed bug #72085 (SEGV on unknown address zif_xml_parse). (cmb)
>>>> diff --git a/ext/standard/file.c b/ext/standard/file.c index
>>>> d8471ff..d346ed9 100644
>>>> --- a/ext/standard/file.c
>>>> +++ b/ext/standard/file.c
>>>> @@ -1512,6 +1512,11 @@ PHP_NAMED_FUNCTION(php_if_ftruncate)
>>>> RETURN_FALSE;
>>>> }
>>>>
>>>> + if (size < 0) {
>>>> + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Negative size
>>>> + is
>>>> not supported");
>>>> + RETURN_FALSE;
>>>> + }
>>>> +
>>>> PHP_STREAM_TO_ZVAL(stream, &fp);
>>>>
>>>> if (!php_stream_truncate_supported(stream)) { diff --git
>>>> a/ext/standard/tests/file/bug71882.phpt
>>>> b/ext/standard/tests/file/bug71882.phpt
>>>> new file mode 100644
>>>> index 0000000..ae0137b
>>>> --- /dev/null
>>>> +++ b/ext/standard/tests/file/bug71882.phpt
>>>> @@ -0,0 +1,11 @@
>>>> +--TEST--
>>>> +Bug #71882 (Negative ftruncate() on php://memory exhausts memory)
>>>> +--FILE--
>>>> +<?php
>>>> +$fd = fopen("php://memory", "w+");
>>>> +ftruncate($fd, -1);
>>>> +?>
>>>> +==DONE==
>>>> +--EXPECTF--
>>>> +Warning: ftruncate(): Negative size is not supported in
>>>> %s%ebug71882.php on line %d
>>>> +==DONE==
>>>>
>>>>
>>>
>>>
>>
>> --
>> PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit:
>> http://www.php.net/unsub.php
>
>
>