From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3B2B04014F for ; Tue, 4 Apr 2023 14:44:07 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6398E68B102; Tue, 4 Apr 2023 17:44:04 +0300 (EEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AABF668AE36 for ; Tue, 4 Apr 2023 17:43:57 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id BBCF16000D for ; Tue, 4 Apr 2023 14:43:56 +0000 (UTC) Date: Tue, 4 Apr 2023 16:43:55 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20230404144355.GU1164690@pb2> References: <09775b73ab48e425f3b557aaa8d5847643ebe9b7.camel@haerdin.se> <0b6c3856-082c-cb33-e07c-3adf0502b93c@mediaarea.net> <20230401143739.GD1164690@pb2> <85c1e58e-cc90-5814-cba5-d91201dec993@mediaarea.net> <20230401154301.GF1164690@pb2> <71eaedd7-d771-50a7-ed13-3733b8c2187f@mediaarea.net> <20230402200740.GK1164690@pb2> <7291a984-856c-3cd4-483f-f55f13af6be2@mediaarea.net> MIME-Version: 1.0 In-Reply-To: <7291a984-856c-3cd4-483f-f55f13af6be2@mediaarea.net> Subject: Re: [FFmpeg-devel] avformat/mxfenc: SMPTE RDD 48:2018 Amd 1:2022 (FFV1 in MXF) support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: multipart/mixed; boundary="===============3292367468690299509==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============3292367468690299509== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gn1ylXQ+YRNuZICZ" Content-Disposition: inline --gn1ylXQ+YRNuZICZ Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Apr 03, 2023 at 12:07:06AM +0200, Jerome Martinez wrote: > On 02/04/2023 22:07, Michael Niedermayer wrote: > > On Sat, Apr 01, 2023 at 07:11:45PM +0200, Jerome Martinez wrote: > > [...] > > > mxfenc.c | 10 ++++++---- > > > 1 file changed, 6 insertions(+), 4 deletions(-) > > > 2b3a2cc619fcaf2dd1da7aa4b566b390eced62a3 0001-avformat-mxfenc-replac= e-ffv1-version-related-assert-.patch > > > From 65f6fba9434fa9ab4b5d2b91c3f930c1e3cb4bef Mon Sep 17 00:00:00 20= 01 > > > From: Jerome Martinez > > > Date: Sat, 1 Apr 2023 19:04:25 +0200 > > > Subject: [PATCH] avformat/mxfenc: replace ffv1 version related assert= by error > > > message > > >=20 > > > --- > > > libavformat/mxfenc.c | 10 ++++++---- > > > 1 file changed, 6 insertions(+), 4 deletions(-) > > >=20 > > > diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c > > > index 9eba208ffb..0a1ae5353c 100644 > > > --- a/libavformat/mxfenc.c > > > +++ b/libavformat/mxfenc.c > > > @@ -2489,8 +2489,8 @@ static int mxf_parse_ffv1_frame(AVFormatContext= *s, AVStream *st, AVPacket *pkt) > > > ff_init_range_decoder(&c, st->codecpar->extradata, st->code= cpar->extradata_size); > > > ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); > > > v =3D get_ffv1_unsigned_symbol(&c, state); > > > - av_assert0(v >=3D 2); > > > - if (v > 4) { > > > + if (v < 2) { > > > + av_log(s, AV_LOG_ERROR, "Invalid version in ffv1 global = header\n"); > > > return 0; > > > } > > should this not also fail with v > 4 as before ? >=20 > I preferred during the change to copy the code in ffv1dec.c for more > coherency, and ffv1dec.c considers version 5 in ver01 header as invalid a= nd > version 5 with extra metadata as legit. > Actually, a bigger issue is that ffv1dec.c accepts version 5 as if it can > decode it, e.g. with hacked ffv1 stream having version 5: >=20 > $ ./ffmpeg -hide_banner -loglevel error -i level5_like_level1.mkv -f null > /dev/null 2> >(grep -i=A0 "version") > [ffv1 @ 0x7fffc04c81c0] invalid version 5 in ver01 header > $ mediainfo --Details=3D1 level5_like_level3.mkv | grep "version" > 1B1=A0=A0=A0=A0=A0=A0=A0 version:=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 5 (0x00000005) - > Error=3DFFV1-HEADER-version-LATERVERSION:1 > $ ./ffmpeg -hide_banner -loglevel error -i level5_like_level3.mkv -f null > /dev/null && echo $? > 0 >=20 > It works only because my hacked file is a version 4 in reality but it sho= uld > be rejected for when we have a version 5 not compatible with version 4. > I suggest to keep the previous patch as is for coherency with ffv1dec.c t= hen > add the new attached patch that add a check on ffv1 version > 4 for both > ffv1dec.c and mxfenc.c; for ffv1dec.c I also check micro_version for vers= ion > 4 because FFV1 spec hints that micro_version before the one flagged as > stable may be incompatible with previous micro_versions. > With the additional patch: > $ ./ffmpeg -hide_banner -loglevel error -i level5_like_level3.mkv -f null > /dev/null > [ffv1 @ 0x7fffc290e640] unsupported version 5 > Error while opening decoder for input stream #0:0 : Not yet implemented in > FFmpeg, patches welcome > $ ./ffmpeg -hide_banner -loglevel error -i level4.3.mkv -f null /dev/null > [ffv1 @ 0x7fffc5b27640] unsupported version 4 micro_version 3 > Error while opening decoder for input stream #0:0 : Not yet implemented in > FFmpeg, patches welcome > $ ./ffmpeg -hide_banner -loglevel error -i level5_like_level3.mkv -r 25 -= c:v > copy -f mxf /dev/null > [ffv1 @ 0x7fffe422bf00] unsupported version 5 > [mxf @ 0x7fffda8b4080] unsupported ffv1 version 5 > [out#0/mxf @ 0x7fffd34470c0] Error muxing a packet >=20 > J=E9r=F4me >=20 > libavcodec/ffv1dec.c | 10 ++++++++++ > libavformat/mxfenc.c | 4 ++++ > 2 files changed, 14 insertions(+) > 14eb2ae57e1918a903d379640e466bdcb5a73a41 0001-avcodec-ffv1dec-reject-uns= upported-ffv1-versions.patch > From 4434ebddb53524f52346b4fbb1126489d8864810 Mon Sep 17 00:00:00 2001 > From: Jerome Martinez > Date: Mon, 3 Apr 2023 00:04:53 +0200 > Subject: [PATCH] avcodec/ffv1dec: reject unsupported ffv1 versions >=20 > And add similar check in libavformat/mxfenc > --- > libavcodec/ffv1dec.c | 10 ++++++++++ > libavformat/mxfenc.c | 4 ++++ > 2 files changed, 14 insertions(+) >=20 > diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c > index 180d24e695..7aaee7ec5e 100644 > --- a/libavcodec/ffv1dec.c > +++ b/libavcodec/ffv1dec.c > @@ -439,11 +439,21 @@ static int read_extra_header(FFV1Context *f) > av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header= \n"); > return AVERROR_INVALIDDATA; > } > + if (f->version > 4) { > + av_log(f->avctx, AV_LOG_ERROR, "unsupported version %d\n", > + f->version); > + return AVERROR_PATCHWELCOME; > + } > if (f->version > 2) { > c->bytestream_end -=3D 4; > f->micro_version =3D get_symbol(c, state, 0); > if (f->micro_version < 0) > return AVERROR_INVALIDDATA; > + if (f->version =3D=3D 4 && f->micro_version > 2) { > + av_log(f->avctx, AV_LOG_ERROR, "unsupported version 4 micro_= version %d\n", > + f->micro_version); > + return AVERROR_PATCHWELCOME; > + } > } > f->ac =3D get_symbol(c, state, 0); you do not know if the decoder will have any problem with these files > =20 > diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c > index 0a1ae5353c..df5bb55ad8 100644 > --- a/libavformat/mxfenc.c > +++ b/libavformat/mxfenc.c > @@ -2493,6 +2493,10 @@ static int mxf_parse_ffv1_frame(AVFormatContext *s= , AVStream *st, AVPacket *pkt) > av_log(s, AV_LOG_ERROR, "Invalid version in ffv1 global head= er\n"); > return 0; > } > + if (v > 4) { > + av_log(s, AV_LOG_ERROR, "unsupported ffv1 version %d\n", v); > + return 0; > + } > sc->micro_version =3D get_ffv1_unsigned_symbol(&c, state); > } else { > uint8_t keystate =3D 128; mxfenc change is ok thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The misfortune of the wise is better than the prosperity of the fool. -- Epicurus --gn1ylXQ+YRNuZICZ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZCw3pwAKCRBhHseHBAsP q1CDAKCW5mGnXYoue2L/3N7t4yHeWrSLJgCeP0hDccn6xwTSED5piF2te1MKKMs= =A58V -----END PGP SIGNATURE----- --gn1ylXQ+YRNuZICZ-- --===============3292367468690299509== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============3292367468690299509==--