Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] libavformat/vorbiscomment.c:rm warning ‘%03d’ directive output may be truncated (PR #20366)
@ 2025-08-29  8:37 caifan via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: caifan via ffmpeg-devel @ 2025-08-29  8:37 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: caifan

PR #20366 opened by caifan
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20366
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20366.patch

warning: ‘%03d’ directive output may be truncated writing between 3 and 10 bytes into a region of size 4 [-Wformat-truncation=]
warning: ‘%02d’ directive output may be truncated writing between 2 and 3 bytes into a region of size between 1 and 7 [-Wformat-truncation=]

Signed-off-by: caifan3 <caifan3@xiaomi.com>


From 08b5aaad4c7ff709c0691c78675a3de681347193 Mon Sep 17 00:00:00 2001
From: caifan3 <caifan3@xiaomi.com>
Date: Fri, 29 Aug 2025 16:21:40 +0800
Subject: [PATCH] =?UTF-8?q?libavformat/vorbiscomment.c:rm=20warning=20?=
 =?UTF-8?q?=E2=80=98%03d=E2=80=99=20directive=20output=20may=20be=20trunca?=
 =?UTF-8?q?ted?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

warning: ‘%03d’ directive output may be truncated writing between 3 and 10 bytes into a region of size 4 [-Wformat-truncation=]
warning: ‘%02d’ directive output may be truncated writing between 2 and 3 bytes into a region of size between 1 and 7 [-Wformat-truncation=]

Signed-off-by: caifan3 <caifan3@xiaomi.com>
---
 libavformat/vorbiscomment.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavformat/vorbiscomment.c b/libavformat/vorbiscomment.c
index abe12fd586..1fc2066785 100644
--- a/libavformat/vorbiscomment.c
+++ b/libavformat/vorbiscomment.c
@@ -93,15 +93,23 @@ int ff_vorbiscomment_write(AVIOContext *pb, const AVDictionary *m,
             AVChapter *chp = chapters[i];
             char chapter_time[13];
             char chapter_number[4];
-            int h, m, s, ms;
+            int h, m, s, ms, ret;
 
             s  = av_rescale(chp->start, chp->time_base.num, chp->time_base.den);
             h  = s / 3600;
             m  = (s / 60) % 60;
             ms = av_rescale_q(chp->start, chp->time_base, av_make_q(   1, 1000)) % 1000;
             s  = s % 60;
-            snprintf(chapter_number, sizeof(chapter_number), "%03d", i);
-            snprintf(chapter_time, sizeof(chapter_time), "%02d:%02d:%02d.%03d", h, m, s, ms);
+            ret = snprintf(chapter_number, sizeof(chapter_number), "%03d", i);
+            if (ret < 0 || ret >= sizeof(chapter_number)) {
+                av_log(NULL, AV_LOG_ERROR, "Chapter number %d too large to format\n", i);
+                return AVERROR(EINVAL);
+            }
+            ret = snprintf(chapter_time, sizeof(chapter_time), "%02d:%02d:%02d.%03d", h, m, s, ms);
+            if (ret < 0 || ret >= sizeof(chapter_time)) {
+                av_log(NULL, AV_LOG_ERROR, "Chapter time %02d:%02d:%02d.%03d too large to format\n", h, m, s, ms);
+                return AVERROR(EINVAL);
+            }
             avio_wl32(pb, 10 + 1 + 12);
             avio_write(pb, "CHAPTER", 7);
             avio_write(pb, chapter_number, 3);
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-08-29  8:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-29  8:37 [FFmpeg-devel] [PATCH] libavformat/vorbiscomment.c:rm warning ‘%03d’ directive output may be truncated (PR #20366) caifan via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git