php.net |  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
From: csyangchen at hotmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: csyangchen at hotmail dot com
New email:
PHP Version: OS:

 

 [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:
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 11:01:31 2019 UTC