|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66777 strftime returns empty string when input fmt string exceeds 1024
Submitted: 2014-02-26 03:55 UTC Modified: 2017-10-24 08:08 UTC
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:
Status: Open Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: csyangchen at hotmail dot com
New email:
PHP Version: OS:


 [2014-02-26 03:55 UTC] csyangchen at hotmail dot com
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) {

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


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-26 08:17 UTC]
-Assigned To: +Assigned To: derick
 [2017-10-24 08:08 UTC]
-Status: Assigned +Status: Open -Assigned To: derick +Assigned To:
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 23 00:01:23 2020 UTC