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 1/9] avformat/matroskaenc: Avoid atoi()
@ 2023-08-11 10:34 Andreas Rheinhardt
  2023-08-11 10:43 ` [FFmpeg-devel] [PATCH 2/9] avformat/matroska: Move ff_matroska_video_stereo_plane to demuxer Andreas Rheinhardt
                   ` (10 more replies)
  0 siblings, 11 replies; 14+ messages in thread
From: Andreas Rheinhardt @ 2023-08-11 10:34 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

It has undefined behaviour in case the value does not fit into an int.
Also stop allowing to override a stream level "alpha_mode" tag
by an AVFormatContext one and properly check that the stereo_mode
number given via a tag is actually in the range 0..14: Negative
values would have been treated as zero before this patch.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/matroskaenc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index e813ef86cf..9bdf087c67 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1592,7 +1592,7 @@ static int mkv_write_stereo_mode(AVFormatContext *s, EbmlWriter *writer,
     // convert metadata into proper side data and add it to the stream
     if ((tag = av_dict_get(st->metadata, "stereo_mode", NULL, 0)) ||
         (tag = av_dict_get( s->metadata, "stereo_mode", NULL, 0))) {
-        int stereo_mode = atoi(tag->value);
+        long stereo_mode = strtol(tag->value, NULL, 0);
 
         for (int i = 0; i < MATROSKA_VIDEO_STEREOMODE_TYPE_NB; i++)
             if (!strcmp(tag->value, ff_matroska_video_stereo_mode[i])){
@@ -1600,7 +1600,7 @@ static int mkv_write_stereo_mode(AVFormatContext *s, EbmlWriter *writer,
                 break;
             }
 
-        if (stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB &&
+        if ((unsigned long)stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB &&
             stereo_mode != 10 && stereo_mode != 12) {
             int ret = ff_mkv_stereo3d_conv(st, stereo_mode);
             if (ret < 0)
@@ -1748,11 +1748,10 @@ static int mkv_write_track_video(AVFormatContext *s, MatroskaMuxContext *mkv,
     if (ret < 0)
         return ret;
 
-    if (((tag = av_dict_get(st->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) ||
-        ((tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) ||
-        (par->format == AV_PIX_FMT_YUVA420P)) {
+    if (par->format == AV_PIX_FMT_YUVA420P ||
+        ((tag = av_dict_get(st->metadata, "alpha_mode", NULL, 0)) ||
+         (tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0))) && strtol(tag->value, NULL, 0))
         ebml_writer_add_uint(&writer, MATROSKA_ID_VIDEOALPHAMODE, 1);
-    }
 
     // write DisplayWidth and DisplayHeight, they contain the size of
     // a single source view and/or the display aspect ratio
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-08-13 22:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-11 10:34 [FFmpeg-devel] [PATCH 1/9] avformat/matroskaenc: Avoid atoi() Andreas Rheinhardt
2023-08-11 10:43 ` [FFmpeg-devel] [PATCH 2/9] avformat/matroska: Move ff_matroska_video_stereo_plane to demuxer Andreas Rheinhardt
2023-08-11 10:43 ` [FFmpeg-devel] [PATCH 3/9] avformat/matroska: Add macro for stereomode<->AVStereo3D correspondence Andreas Rheinhardt
2023-08-11 10:43 ` [FFmpeg-devel] [PATCH 4/9] avformat/matroskaenc: Don't add side-data to input stream Andreas Rheinhardt
2023-08-11 10:43 ` [FFmpeg-devel] [PATCH 5/9] avformat/matroskaenc: Improve message for WebM-incompatible StereoModes Andreas Rheinhardt
2023-08-11 10:43 ` [FFmpeg-devel] [PATCH 6/9] avformat/matroska: Move ff_mkv_stereo3d_conv() to demuxer Andreas Rheinhardt
2023-08-11 10:43 ` [FFmpeg-devel] [PATCH 7/9] avformat/matroskadec: Replace switch with array Andreas Rheinhardt
2023-08-11 10:43 ` [FFmpeg-devel] [PATCH 8/9] avformat/matroskadec: Use named constants instead of their value Andreas Rheinhardt
2023-08-11 13:20   ` Paul B Mahol
2023-08-11 10:43 ` [FFmpeg-devel] [PATCH 9/9] avformat/riffdec: Pass logctx as void* instead of AVFormatContext* Andreas Rheinhardt
2023-08-11 22:58 ` [FFmpeg-devel] [PATCH 10/11] fate/matroska: Add test for stereo 3D Andreas Rheinhardt
2023-08-12 16:27   ` Andreas Rheinhardt
2023-08-11 22:58 ` [FFmpeg-devel] [PATCH 11/11] fate/matroska: Fix requirements of fate-matroska-alac-remux test Andreas Rheinhardt
2023-08-13 23:00 ` [FFmpeg-devel] [PATCH 1/9] avformat/matroskaenc: Avoid atoi() Andreas Rheinhardt

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