From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 2F1574BD43 for ; Tue, 26 Aug 2025 19:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1756237986; h=date : to : in-reply-to : message-id : references : mime-version : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=Xhcf7ifOOyso5TCM61VZ50gOSLS/GTwWGl5loFaVZAM=; b=blveI0YWkGdCPNHSYaOOJ8fMb8ucPYyo1tEmhF6tv3pKSL+kaByFqDy5hJguwCe8rFmni TcXUswhWteBWEkHBI9oVos6sUvTz8OoJQ6oPsVMEFav4vM7iuV8GBdDctcatRXiUYH2tCeN C5Oy7COY7WeCNXLSOr3V+2bZRZSRuE/bCsX9YJtwAq+EyG/17In+qbFD0nNHv4IuF+seTcW RJpbUIm52ckmns4ccLNoBTfjXa9MpAtAFnMHzMI1paXw/V4motckLwgf9exgTzSBG/Lv0eP C9HLy/suUMbvdawrVzrU/F+fvb7L6d97rezIkBCbyV8bzfrkujpOpaUm5+sA== Received: from [172.18.0.4] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id D2DAB68E73A; Tue, 26 Aug 2025 22:53:06 +0300 (EEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1756237973; b=QI9FxeDOtb6gmzvTYTax0cmToKSNhwy2EJDkCSaUnjMoicjIGNOyj4DQcx2Xevk/qTg0H 6JNQOSdKgGkhAWCmomCoTcJBgaywkohMBABhcCzcREYS5nTlCOLCmSb/KeT8fQlL4yvHyCT BAVsb8U910hhup1kVNweCQi2yNDwltFjtCc5mr/Yv3VZLLa6PqjV/rvxcHxVJWIZI10agEv xBIv2d6mKkLRDQBL1b9UifAky+kk7HY0fWD1hv+n29zMqfPHnFeV+sGvRf5A+eqA9VQueob 5O7mLy9yrEpTXna0c7TgDYXoB3Nv64alI1rIogpx9EzLpfSC/osDV4hTzQOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1756237973; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=3j9p6pO1bm4tk1zx4cFmz4fxVAfqyYAdvg2aMRDlBJg=; b=X1+7J3LjqaQX4/ZxrR+JTJE9/IOZIlCxmiLx6XHjm1Ucd8BaDCPujp+IM89qXAGUSLWso 3Fxq7AqFx8fxZCIzUrC8JPOu3Px/G1bukOUMwMEWLZpGEBZNXBxT4O5z/frL9mq0WfhUKmI kC/dY4H9d4/j67sF1CjFM/GhLNc+TuMWyVUpfyXRiE0T1OMrDAUqmzZIS5cFN0J/5e66kEs pKajhvkqtEiuRe/aT89k1U6tv1/TXP32QIDKPmdQDMqKqS3XD6mw31Im7W8eYa49WWmSy89 csxIPlq8/WWZzm8PdpHe8T8f1hWEaLYG8E/KHudW4nFiNleI2muPZNJLHMZg== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=fail; arc=none; dmarc=none Authentication-Results: ffmpeg.org; dkim=fail; arc=none (Message is not ARC signed); dmarc=none Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 13E5A6802BC for ; Tue, 26 Aug 2025 22:52:38 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B3BD4EBEBD for ; Tue, 26 Aug 2025 21:50:41 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1uHmhTIqLwdr for ; Tue, 26 Aug 2025 21:50:39 +0200 (CEST) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id BA87EEBEBB for ; Tue, 26 Aug 2025 21:50:39 +0200 (CEST) Date: Tue, 26 Aug 2025 21:50:39 +0200 (CEST) To: Nicolas George via ffmpeg-devel In-Reply-To: Message-ID: <829558c0-f800-6070-0d38-92f202c7a092@passwd.hu> References: <20250824203654.4450A68E704@ffbox0-bg.ffmpeg.org> MIME-Version: 1.0 Message-ID-Hash: ZUVOK2I7F2JJ4NEKNCBAEMX7OY5SHBHE X-Message-ID-Hash: ZUVOK2I7F2JJ4NEKNCBAEMX7OY5SHBHE X-MailFrom: SRS0=/Jox=3G=passwd.hu=cus@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] Re: [PATCH] avutil/bprint: fix av_bprint_strftime with %p format string reporting truncated output (PR #20330) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Marton Balint via ffmpeg-devel Cc: Marton Balint Content-Type: text/plain; charset="us-ascii"; format="flowed" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: On Tue, 26 Aug 2025, Nicolas George via ffmpeg-devel wrote: > Marton Balint via ffmpeg-devel (HE12025-08-24): >>> From 4532caf820dcb2bc2cbac3d4e782ad27cf9fd76b Mon Sep 17 00:00:00 2001 >> From: Marton Balint >> Date: Sun, 24 Aug 2025 21:35:41 +0200 >> Subject: [PATCH 2/2] 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 >> --- >> libavutil/bprint.c | 10 +++++++++- >> 1 file changed, 9 insertions(+), 1 deletion(-) >> >> diff --git a/libavutil/bprint.c b/libavutil/bprint.c >> index 932c03ce50..fa244b2e04 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 = 0; > > Why not set it here once and for all? I just thought that for the typical case we can spare an strlen() call this way. > >> >> if (!*fmt) >> return; >> @@ -174,9 +175,16 @@ 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; >> + >> + if (!fmt_len) >> + fmt_len = strlen(fmt); >> + /* A 256x space requirement for output is unlikely, so it is likely empty */ >> + if (room >> 8 > fmt_len) >> + break; >> + > > IIUC, at this point l=0 means either the buffer is too small or the > output is empty, and you distinguish between the cases by checking that > there is plenty of room, 256 chars for any char in the buffer? Yes. > > I think a lower margin should be ok, >>4 or >>5. I'd rather keep it >>8, because strftime format strings can also have width specifiers, so something like "%80c" should work. Obviously this is always going to be a heuristics, but I wanted to be careful and reject only the very unlikely/insane format strings... > > OTOH, I think a comment would be a good idea. There is one, but OK, I will make the existing comment a bit more verbose. > >> /* 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 */ > > Or we could write our own strftime, not localized. Some API users might depend on our strftime functions returning localized strings... Regards, Marton > > Regards, > > -- > Nicolas George > _______________________________________________ > ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org > To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org > _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org