1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avcodec/mscc: Don't modify input packet

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

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-07-04 12:18:23 +02:00
parent 930e560da3
commit 8cfb44cd2e

View File

@ -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;
}