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 4/4] avcodec/mscc: Don't modify input packet
Date: Mon,  4 Jul 2022 13:02:43 +0200
Message-ID: <DB6PR0101MB221403ED07584A23C51B2CF78FBE9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw)
In-Reply-To: <DB6PR0101MB2214977FAAD46F339A77F2F58FBE9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com>

This packet may not be writable, hence we must not write to it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mscc.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mscc.c b/libavcodec/mscc.c
index ac67ec9c47..3666b881a1 100644
--- a/libavcodec/mscc.c
+++ b/libavcodec/mscc.c
@@ -134,7 +134,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
 {
     MSCCContext *s = avctx->priv_data;
     z_stream *const zstream = &s->zstream.zstream;
-    uint8_t *buf = avpkt->data;
+    const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     GetByteContext gb;
     PutByteContext pb;
@@ -146,12 +146,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    if (avctx->codec_id == AV_CODEC_ID_MSCC) {
-        avpkt->data[2] ^= avpkt->data[0];
-        buf += 2;
-        buf_size -= 2;
-    }
-
     if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
         size_t size;
         const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size);
@@ -172,12 +166,25 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret);
         return AVERROR_UNKNOWN;
     }
-    zstream->next_in   = buf;
-    zstream->avail_in  = buf_size;
     zstream->next_out  = s->decomp_buf;
     zstream->avail_out = s->decomp_size;
+    if (avctx->codec_id == AV_CODEC_ID_MSCC) {
+        const uint8_t start = avpkt->data[2] ^ avpkt->data[0];
+
+        zstream->next_in  = &start;
+        zstream->avail_in = 1;
+        ret = inflate(zstream, Z_NO_FLUSH);
+        if (ret != Z_OK || zstream->avail_in != 0)
+            goto inflate_error;
+
+        buf      += 3;
+        buf_size -= 3;
+    }
+    zstream->next_in   = buf;
+    zstream->avail_in  = buf_size;
     ret = inflate(zstream, Z_FINISH);
     if (ret != Z_STREAM_END) {
+inflate_error:
         av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", ret);
         return AVERROR_UNKNOWN;
     }
-- 
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".

  parent reply	other threads:[~2022-07-04 11:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04 10:58 [FFmpeg-devel] [PATCH 1/4] avformat/(mpeg|mpegts|mxf|sup)enc: Use const uint8_t* to access pkt data Andreas Rheinhardt
2022-07-04 11:02 ` [FFmpeg-devel] [PATCH 2/4] avcodec/dcadec: Treat the input packet's data as const Andreas Rheinhardt
2022-07-04 11:02 ` [FFmpeg-devel] [PATCH 3/4] avcodec/decoders: Use const uint8_t* to access input packet data Andreas Rheinhardt
2022-07-04 11:02 ` Andreas Rheinhardt [this message]
2022-07-04 11:15 ` [FFmpeg-devel] [PATCH 1/4] avformat/(mpeg|mpegts|mxf|sup)enc: Use const uint8_t* to access pkt data Paul B Mahol

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=DB6PR0101MB221403ED07584A23C51B2CF78FBE9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.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