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 7688D476CA for ; Tue, 26 Aug 2025 18:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1756232354; h=date : to : message-id : references : mime-version : in-reply-to : 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=VHg2A8bKEp6Ne25wZZf866tTrp9DiuRdBSaphKU37Dg=; b=ltqBiRuyhlCAuKxpuzcJzyDVyqdjjXsUSkfre2dH+1OOfw/IQckcFrZr4bC/b94Qb9Yu3 NMQzPT78ipb+deJfyv/1apgWqlmRqpPy+5S4ViJI4PINj5Smk8MIR3T+UDu5z5ipbwsvUfA iq0Ng6N2b7M06U7hlqeXSQ1z9fcQjhV0uGGH260lpGmkDSGr88y/zvU8JRVbMLNtUtnzplb gbqjKGrEoNgmQ4YgAfUh/rU5wbigtbZBoR1mDj7Gh5R3oIuPSw48u0cHCrlC35NXO6haHHK HrKdsqaWNQru8AtatevrQlmrJP2IG35QxsSDohHlcNJVozAiFdDvRzb4nxYw== Received: from [172.18.0.4] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 1FDEF68E7A2; Tue, 26 Aug 2025 21:19:14 +0300 (EEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1756232340; b=GZqTK//Io/ZSAKy6CF282T8l0bfyJmKy6PTHWfYQmga48xAdlUt8liVFBp8lYeyXn1Sp1 jbp0uKhu15JA6FahIiWwFy5b1FvDYBH1sDjg/3IxwN7D3o4opxC/AwiXshV2qk9UjOhA7nO f7Z1L3tcg/3C0Ti95XBeukvVS0kQfSEHl7aQ5a/+W2iS6aOjyWy2WoaoYrHxDFl2qyupDih Rb8u/IkYd+SxdyCpfaC8Vcjq6k3DLExiYR/4dhx7vMiJjl+JTkXoIevZL6nl0dmInQ1r/y9 HpROpYG0ZRDreW0e3s3S0hWC2H67jGv0fykjr9lgNaWpXhSi9t/Lq66K8Haw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1756232340; 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=aRLDBdmhOMJReyzfuOkz8SKThc3hHw2RUeBChg0Atwc=; b=pLMhd7mjGj2gp7QUw6JRopp1PtCXDa/0MJ0ybDnaE0AXofiwQKDLHEtfeBY/K1AJloMPz 6CDUzWEaTvU5Nsn9KUUIbZZ6qQU1bzAOg41y7xtzVNU5Hu1E7KT3lY/X/5M7SWav5qmw+by yhqpweqC6O2bngwDZ6oGbeQ0w+Ovy67jkWSTG5Vc9qj/0k2PAKxl6Uscp7rfc9KLb6W5fTP MJVJH/u34N7rkGK14p/Nrp3NTbpsC/wm6ydScvlPKjSGcfx5IrUs7rfBLWaZ+T8wB3DvDYk 4o5c1MCelYCd+Ngf01vl5pcP+TklFOrN63fM7MuNt4i3mgTnuZJ/1Tjlr1qg== 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 nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 96BC968C5E5; Tue, 26 Aug 2025 21:18:42 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 57QIIftT013606 ; Tue, 26 Aug 2025 20:18:42 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id C5D312EFE4; Tue, 26 Aug 2025 20:18:41 +0200 (CEST) Date: Tue, 26 Aug 2025 20:18:41 +0200 To: FFmpeg development discussions and patches Message-ID: References: <20250824203654.4450A68E704@ffbox0-bg.ffmpeg.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250824203654.4450A68E704@ffbox0-bg.ffmpeg.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Tue, 26 Aug 2025 20:18:42 +0200 (CEST) Message-ID-Hash: 6GBM5DQV2TSN2KTHTAPPBGSIFGVJX3MI X-Message-ID-Hash: 6GBM5DQV2TSN2KTHTAPPBGSIFGVJX3MI X-MailFrom: SRS0=3ArC=3G=phare.normalesup.org=george@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: Nicolas George via ffmpeg-devel Cc: Marton Balint , Nicolas George Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: 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? > > 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? I think a lower margin should be ok, >>4 or >>5. OTOH, I think a comment would be a good idea. > /* 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. Regards, -- Nicolas George _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org