The branch, master has been updated via 2296a9c1bc0636c9ccf5217a49d87d29638ea65a (commit) via 50e94aadb2d624407c46c988857a767dce5020b7 (commit) from 16d32a1c1d040d1b444ec476901d7458e1620301 (commit)
- Log ----------------------------------------------------------------- commit 2296a9c1bc0636c9ccf5217a49d87d29638ea65a Author: Marton Balint <c...@passwd.hu> AuthorDate: Sun Aug 24 21:35:41 2025 +0200 Commit: Marton Balint <c...@passwd.hu> CommitDate: Sun Aug 31 09:37:59 2025 +0200 avutil/bprint: fix av_bprint_strftime with %p format string reporting truncated output strftime returns 0 in case of an empty output (e.g. %p format string with some locales), there is no way to distinguish this from a buffer-too-small error condition. So we must use some heuristics to handle this case, and not consume INT_MAX RAM and falsely report a truncated output. Signed-off-by: Marton Balint <c...@passwd.hu> diff --git a/libavutil/bprint.c b/libavutil/bprint.c index ac07a17326..11e0f08774 100644 --- a/libavutil/bprint.c +++ b/libavutil/bprint.c @@ -167,6 +167,7 @@ void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm) { unsigned room; size_t l; + size_t fmt_len = strlen(fmt); if (!*fmt) return; @@ -174,9 +175,18 @@ void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm) room = av_bprint_room(buf); if (room && (l = strftime(buf->str + buf->len, room, fmt, tm))) break; + + /* Due to the limitations of strftime() it is not possible to know if + * the output buffer is too small or the output is empty. + * However, a 256x output space requirement compared to the format + * string length is so unlikely we can safely assume empty output. This + * allows supporting possibly empty format strings like "%p". */ + if (room >> 8 > fmt_len) + break; + /* strftime does not tell us how much room it would need: let us retry with twice as much until the buffer is large enough */ - room = !room ? strlen(fmt) + 1 : + room = !room ? fmt_len + 1 : room <= INT_MAX / 2 ? room * 2 : INT_MAX; if (av_bprint_alloc(buf, room)) { /* impossible to grow, try to manage something useful anyway */ commit 50e94aadb2d624407c46c988857a767dce5020b7 Author: Marton Balint <c...@passwd.hu> AuthorDate: Sun Aug 24 21:42:54 2025 +0200 Commit: Marton Balint <c...@passwd.hu> CommitDate: Sun Aug 31 09:37:59 2025 +0200 avutil/bprint: make av_bprintf use av_vbprintf No reason to duplicate the code. Signed-off-by: Marton Balint <c...@passwd.hu> diff --git a/libavutil/bprint.c b/libavutil/bprint.c index 4e9571715c..ac07a17326 100644 --- a/libavutil/bprint.c +++ b/libavutil/bprint.c @@ -96,17 +96,17 @@ void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size) *buf->str = 0; } -void av_bprintf(AVBPrint *buf, const char *fmt, ...) +void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg) { unsigned room; char *dst; - va_list vl; int extra_len; + va_list vl; while (1) { room = av_bprint_room(buf); dst = room ? buf->str + buf->len : NULL; - va_start(vl, fmt); + va_copy(vl, vl_arg); extra_len = vsnprintf(dst, room, fmt, vl); va_end(vl); if (extra_len <= 0) @@ -119,27 +119,12 @@ void av_bprintf(AVBPrint *buf, const char *fmt, ...) av_bprint_grow(buf, extra_len); } -void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg) +void av_bprintf(AVBPrint *buf, const char *fmt, ...) { - unsigned room; - char *dst; - int extra_len; va_list vl; - - while (1) { - room = av_bprint_room(buf); - dst = room ? buf->str + buf->len : NULL; - va_copy(vl, vl_arg); - extra_len = vsnprintf(dst, room, fmt, vl); - va_end(vl); - if (extra_len <= 0) - return; - if (extra_len < room) - break; - if (av_bprint_alloc(buf, extra_len)) - break; - } - av_bprint_grow(buf, extra_len); + va_start(vl, fmt); + av_vbprintf(buf, fmt, vl); + va_end(vl); } void av_bprint_chars(AVBPrint *buf, char c, unsigned n) ----------------------------------------------------------------------- Summary of changes: libavutil/bprint.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) hooks/post-receive -- _______________________________________________ ffmpeg-cvslog mailing list -- ffmpeg-cvslog@ffmpeg.org To unsubscribe send an email to ffmpeg-cvslog-le...@ffmpeg.org