Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 1/9] avformat/matroskaenc: Avoid atoi()
Date: Fri, 11 Aug 2023 12:34:32 +0200
Message-ID: <AS8P250MB07441DD2024A768DE773EEFA8F10A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)

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".

             reply	other threads:[~2023-08-11 10:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-11 10:34 Andreas Rheinhardt [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AS8P250MB07441DD2024A768DE773EEFA8F10A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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