php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66777 strftime returns empty string when input fmt string exceeds 1024
Submitted: 2014-02-26 03:55 UTC Modified: 2020-12-18 12:24 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: csyangchen at hotmail dot com Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 + 9 = ?
Subscribe to this entry?

 
 [2014-02-26 03:55 UTC] 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

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-26 08:17 UTC] krakjoe@php.net
-Assigned To: +Assigned To: derick
 [2017-10-24 08:08 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: derick +Assigned To:
 [2020-12-18 12:24 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2020-12-18 12:24 UTC] 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.
 [2020-12-18 12:37 UTC] 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:38 UTC] phpdocbot@php.net
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
 [2020-12-18 12:38 UTC] phpdocbot@php.net
-Status: Verified +Status: Closed
 [2020-12-18 23:54 UTC] mumumu@php.net
Automatic comment from SVN on behalf of mumumu
Revision: http://svn.php.net/viewvc/?view=revision&revision=352126
Log: Fix #66777: strftime returns empty string when input fmt string exceeds 1024
 [2020-12-18 23:55 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=2e3fdc047da277dab10909927f8b16c89c7fea7a
Log: Fix #66777: strftime returns empty string when input fmt string exceeds 1024
 [2020-12-30 11:58 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=639fab49da17f3a5d7eb3f54468aec94d99546ad
Log: Fix #66777: strftime returns empty string when input fmt string exceeds 1024
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Feb 25 17:01:24 2021 UTC