Bug #66777 [Asn->Opn]: strftime returns empty string when input fmt string exceeds 1024
| From: | kalle@php.net | Date: | Tue, 24 Oct 2017 08:08:52 +0000 |
| Subject: | Bug #66777 [Asn->Opn]: strftime returns empty string when input fmt string exceeds 1024 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212227@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66777&edit=1
ID: 66777
Updated by: kalle@php.net
Reported by: csyangchen at hotmail dot com
Summary: strftime returns empty string when input fmt string
exceeds 1024
-Status: Assigned
+Status: Open
Type: Bug
Package: Date/time related
PHP Version: Irrelevant
-Assigned To: derick
+Assigned To:
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2014-02-26 03:55:44] csyangchen at hotmail dot com
Description:
------------
strftime returns empty string when input fmt string exceeds 1024
due to the undocumented code logic in 'ext/date/php_date.c' php_strftime
...
int max_reallocs = 5;
size_t buf_len = 256, real_len;
...
buf = (char *) emalloc(buf_len);
while ((real_len=strftime(buf, buf_len, format, &ta))==buf_len || real_len==0) {
buf_len *= 2;
buf = (char *) erealloc(buf, buf_len);
if (!--max_reallocs) {
break;
}
}
...
the logic to abort reallocation after 5 times is undocumented.
thus we can have at most 256 * 5 = 1024 size string.
Test script:
---------------
echo strftime(str_repeat('x', 1024));
Expected result:
----------------
should output 1024 occurrences of 'x'
Actual result:
--------------
empty string
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66777&edit=1