Bug->Doc #66777 [Opn->Ver]: strftime returns empty string when input fmt string exceeds 1024

From: Date: Fri, 18 Dec 2020 12:24:55 +0000
Subject: Bug->Doc #66777 [Opn->Ver]: 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-18287@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: cmb@php.net Reported by: csyangchen at hotmail dot com Summary: strftime returns empty string when input fmt string exceeds 1024 -Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem Package: Date/time related PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: 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. 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

« previous php.doc.bugs (#18287) next »