Doc #66777 [Ver->Csd]: strftime returns empty string when input fmt string exceeds 1024
| From: | phpdocbot@php.net | Date: | Fri, 18 Dec 2020 12:38:16 +0000 |
| Subject: | Doc #66777 [Ver->Csd]: strftime returns empty string when input fmt string exceeds 1024 | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18288@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: phpdocbot@php.net
Reported by: csyangchen at hotmail dot com
Summary: strftime returns empty string when input fmt string
exceeds 1024
-Status: Verified
+Status: Closed
Type: Documentation Problem
Package: Date/time related
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=45c7531e42f16a43ec69f392499dff6cae93dc12
Log: Fix #66777: strftime returns empty string when input fmt string exceeds 1024
Previous Comments:
------------------------------------------------------------------------
[2020-12-18 12:37:57] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=352122
Log: Fix #66777: strftime returns empty string when input fmt string exceeds 1024
------------------------------------------------------------------------
[2020-12-18 12:24:55] cmb@php.net
This is basically a duplicate of bug #42713; however, that bug
report and the respective fix got it slighty wrong, since the
restriction is on the length of the return value, but not about
the length of the $format parameter.
This bug report is also slightly off, since the length is not
constrained to 256 * 5, but actually to 256 * (2^^4) - 1. It
should be noted that as of PHP 5.5.0 the base size has been
increased from 64 to 256. This is why it's always a good idea the
actually specify the affected PHP version.
Anyhow, this is merely a documentation issue, not a real bug,
since there is no need for larger output.
------------------------------------------------------------------------
[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