From patchwork Mon Jul 11 21:44:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 36737 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:6da0:b0:8b:e47:9dbf with SMTP id wl32csp1621933pzb; Mon, 11 Jul 2022 14:44:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vlyZ1yHrML1n6os8Id8gnh+OP6TnEQT3SSG7rQkdkfERKKry/EIJq2cjjK6z9/2VRhA9PI X-Received: by 2002:a05:6402:3311:b0:43a:8714:d486 with SMTP id e17-20020a056402331100b0043a8714d486mr27390180eda.136.1657575875359; Mon, 11 Jul 2022 14:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657575875; cv=none; d=google.com; s=arc-20160816; b=zpNMFj73XGm4aD83b8kLE5JR77qMTAqAjz5h8AKCK8MPI9EifAEH/Xp6ufRw6SS9BT OBcPKwc+0ewUMlE4HEVuqDmhbf7gj1y7Oz3qY1FpYkts7daldXL/ZAHrKPQNE2r+IVcK mqiHiqevbUGYhrmr5J7K+Y4/uhDKnSjOQoNCksUra+JnwBD28i8EaUDBxLO5PevA1VKZ FrfbydJOMCJCh6gJQzQOh5L4uDQNS58gPwauTMSx+EOqHqlfyt/epGGhBBIib6bwJMKX FIwQkFur/iyiDTYIcE7mQeHx2jdrCL3tfA1xpJisnrnRh6Pjqi/hpuaaIA452LLc0zPX hx1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=Ihuqd7Jdh2w7rLIr9jgpyCh/OwGKJS4dd6F50bZRiCc=; b=fPClF9mE/etobRfKOhUnn9OSha+8H8j36+AVDSd5vK02r96yR8UG55W0+xImdctSfm LlVvAl0FBEkuUiDaVzLHlJbg8AyOkZfwwpJcLpWO4zHauzbaqqz5gYtruMJnnLKT3bzR 1RcEePvQH3zmEvAO8D2ql1m7d+tOPOusx6LiwT49huBrRhReyczvyqBCncH5YJeJMGNr kQCN20Yqg2XEiBF2SPxuJbhVw0UQpF+7FbgJgu6ygVZWdmFiuRbT77TTtqk9McJjq3QH ZrIub5p+9a1KjfhNkCibQ5hrlrWoi9V2+VE9LyLuKKV6U3wbWd/GbNaZYDmtjOK2CRdb E+Pw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q22-20020a1709060f9600b00726508419d9si10018416ejj.929.2022.07.11.14.44.34; Mon, 11 Jul 2022 14:44:35 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 82C5168B812; Tue, 12 Jul 2022 00:44:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at01-3.mx.upcmail.net (vie01a-dmta-at01-3.mx.upcmail.net [62.179.121.147]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B754868B6CB for ; Tue, 12 Jul 2022 00:44:19 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1oB1CU-004IEB-L6 for ffmpeg-devel@ffmpeg.org; Mon, 11 Jul 2022 23:44:18 +0200 Received: from ren-mail-psmtp-mg02. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id B1C1o4B5j8s8UB1CUoIWSP; Mon, 11 Jul 2022 23:44:18 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg02. with ESMTP id B1CTo4r0o8eSWB1CTo0tDv; Mon, 11 Jul 2022 23:44:17 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.4 cv=KKE5sHJo c=1 sm=1 tr=0 ts=62cc99b2 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=apDY_-TS-0WpMiO9mhMA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 11 Jul 2022 23:44:15 +0200 Message-Id: <20220711214417.12286-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfC/UGQfaXzFgiYawD8uWLADiAGI+BhJYeWOUURav5IrhCiVXUPWgo24jTB3FrshRDrvZZrSKMV+IMrlZq81vOVHZE5qBUQ2WLAOUrA8SKs3GS4Hx65wz xGxyw7PXv8DAEvGVA898Fl/ou/m1zhzdKnoSrJve9mYiP4GttQX7L08LnHFvFCFXsISpgfHJf4ptOQ== Subject: [FFmpeg-devel] [PATCH 1/3] avformat/mxfdec: SMPTE RDD 48:2018 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: jIQPh/R9ws2A Signed-off-by: Michael Niedermayer --- libavformat/mxf.c | 3 +++ libavformat/mxf.h | 1 + libavformat/mxfdec.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/libavformat/mxf.c b/libavformat/mxf.c index 36d662b58c..8ef928b8fc 100644 --- a/libavformat/mxf.c +++ b/libavformat/mxf.c @@ -66,6 +66,9 @@ const MXFCodecUL ff_mxf_codec_uls[] = { { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x02,0x01 }, 16, AV_CODEC_ID_V210 }, /* V210 */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0E,0x04,0x02,0x01,0x02,0x11,0x00,0x00 }, 14, AV_CODEC_ID_PRORES }, /* Avid MC7 ProRes */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x06,0x00,0x00 }, 14, AV_CODEC_ID_PRORES }, /* Apple ProRes */ + { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x01,0x00 }, 15, AV_CODEC_ID_FFV1 }, /*FFV1 V0 */ + { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x02,0x00 }, 15, AV_CODEC_ID_FFV1 }, /*FFV1 V1 */ + { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x09,0x04,0x00 }, 15, AV_CODEC_ID_FFV1 }, /*FFV1 V3 */ /* SoundEssenceCompression */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x03,0x04,0x02,0x02,0x02,0x03,0x03,0x01,0x00 }, 14, AV_CODEC_ID_AAC }, /* MPEG-2 AAC ADTS (legacy) */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, 13, AV_CODEC_ID_PCM_S16LE }, /* uncompressed */ diff --git a/libavformat/mxf.h b/libavformat/mxf.h index 4d9f5119a3..2561605ce5 100644 --- a/libavformat/mxf.h +++ b/libavformat/mxf.h @@ -54,6 +54,7 @@ enum MXFMetadataSetType { AudioChannelLabelSubDescriptor, SoundfieldGroupLabelSubDescriptor, GroupOfSoundfieldGroupsLabelSubDescriptor, + FFV1SubDescriptor, }; enum MXFFrameLayout { diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 400941c348..c4d9d6ed93 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -237,6 +237,12 @@ typedef struct MXFMCASubDescriptor { char *language; } MXFMCASubDescriptor; +typedef struct MXFFFV1SubDescriptor { + MXFMetadataSet meta; + uint8_t *extradata; + int extradata_size; +} MXFFFV1SubDescriptor; + typedef struct MXFIndexTableSegment { MXFMetadataSet meta; int edit_unit_byte_count; @@ -337,6 +343,7 @@ static const uint8_t mxf_crypto_source_container_ul[] = { 0x06,0x0e,0x2b,0x static const uint8_t mxf_encrypted_triplet_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 }; static const uint8_t mxf_encrypted_essence_container[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 }; static const uint8_t mxf_sony_mpeg4_extradata[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 }; +static const uint8_t mxf_ffv1_extradata[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x04,0x01,0x06,0x0c,0x01,0x00,0x00,0x00 }; static const uint8_t mxf_avid_project_name[] = { 0xa5,0xfb,0x7b,0x25,0xf6,0x15,0x94,0xb9,0x62,0xfc,0x37,0x17,0x49,0x2d,0x42,0xbf }; static const uint8_t mxf_jp2k_rsiz[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x01,0x00,0x00,0x00 }; static const uint8_t mxf_indirect_value_utf16le[] = { 0x4c,0x00,0x02,0x10,0x01,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01 }; @@ -377,6 +384,9 @@ static void mxf_free_metadataset(MXFMetadataSet **ctx, int freectx) av_freep(&((MXFDescriptor *)*ctx)->file_descriptors_refs); av_freep(&((MXFDescriptor *)*ctx)->sub_descriptors_refs); break; + case FFV1SubDescriptor: + av_freep(&((MXFFFV1SubDescriptor *)*ctx)->extradata); + break; case AudioChannelLabelSubDescriptor: case SoundfieldGroupLabelSubDescriptor: case GroupOfSoundfieldGroupsLabelSubDescriptor: @@ -1473,6 +1483,25 @@ static int mxf_read_mca_sub_descriptor(void *arg, AVIOContext *pb, int tag, int return 0; } +static int mxf_read_ffv1_sub_descriptor(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) +{ + MXFFFV1SubDescriptor *ffv1_sub_descriptor = arg; + + if (IS_KLV_KEY(uid, mxf_ffv1_extradata)) { + if (ffv1_sub_descriptor->extradata) + av_log(NULL, AV_LOG_WARNING, "Duplicate ffv1_extradata\n"); + av_free(ffv1_sub_descriptor->extradata); + ffv1_sub_descriptor->extradata_size = 0; + ffv1_sub_descriptor->extradata = av_malloc(size); + if (!ffv1_sub_descriptor->extradata) + return AVERROR(ENOMEM); + ffv1_sub_descriptor->extradata_size = size; + avio_read(pb, ffv1_sub_descriptor->extradata, size); + } + + return 0; +} + static int mxf_read_indirect_value(void *arg, AVIOContext *pb, int size) { MXFTaggedValue *tagged_value = arg; @@ -1554,6 +1583,7 @@ static const MXFCodecUL mxf_picture_essence_container_uls[] = { { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x1c,0x01,0x00 }, 14, AV_CODEC_ID_PRORES, NULL, 14 }, /* ProRes */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, 14, AV_CODEC_ID_MPEG2VIDEO, NULL, 15 }, /* MPEG-ES */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x01,0x04,0x01 }, 14, AV_CODEC_ID_MPEG2VIDEO, NULL, 15, D10D11Wrap }, /* SMPTE D-10 mapping */ + { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0d,0x0d,0x01,0x03,0x01,0x02,0x23,0x01,0x00 }, 14, AV_CODEC_ID_FFV1, NULL, 14 }, { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x02,0x41,0x01 }, 14, AV_CODEC_ID_DVVIDEO, NULL, 15 }, /* DV 625 25mbps */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0d,0x01,0x03,0x01,0x02,0x05,0x00,0x00 }, 14, AV_CODEC_ID_RAWVIDEO, NULL, 15, RawVWrap }, /* uncompressed picture */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0a,0x0e,0x0f,0x03,0x01,0x02,0x20,0x01,0x01 }, 15, AV_CODEC_ID_HQ_HQA }, @@ -2444,6 +2474,21 @@ static MXFMCASubDescriptor *find_mca_link_id(MXFContext *mxf, enum MXFMetadataSe return NULL; } +static void parse_ffv1_sub_descriptor(MXFContext *mxf, MXFTrack *source_track, MXFDescriptor *descriptor, AVStream *st) +{ + for (int i = 0; i < descriptor->sub_descriptors_count; i++) { + MXFFFV1SubDescriptor *ffv1_sub_descriptor = mxf_resolve_strong_ref(mxf, &descriptor->sub_descriptors_refs[i], FFV1SubDescriptor); + if (ffv1_sub_descriptor == NULL) + continue; + + descriptor->extradata = ffv1_sub_descriptor->extradata; + descriptor->extradata_size = ffv1_sub_descriptor->extradata_size; + ffv1_sub_descriptor->extradata = NULL; + ffv1_sub_descriptor->extradata_size = 0; + break; + } +} + static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescriptor *descriptor, AVStream *st) { uint64_t routing[FF_SANE_NB_CHANNELS] = {0}; @@ -2972,6 +3017,8 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) st->codecpar->codec_id = AV_CODEC_ID_EIA_608; } } + if (!descriptor->extradata) + parse_ffv1_sub_descriptor(mxf, source_track, descriptor, st); if (descriptor->extradata) { if (!ff_alloc_extradata(st->codecpar, descriptor->extradata_size)) { memcpy(st->codecpar->extradata, descriptor->extradata, descriptor->extradata_size); @@ -3159,6 +3206,7 @@ static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = { { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x6b,0x00 }, mxf_read_mca_sub_descriptor, sizeof(MXFMCASubDescriptor), AudioChannelLabelSubDescriptor }, { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x6c,0x00 }, mxf_read_mca_sub_descriptor, sizeof(MXFMCASubDescriptor), SoundfieldGroupLabelSubDescriptor }, { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x6d,0x00 }, mxf_read_mca_sub_descriptor, sizeof(MXFMCASubDescriptor), GroupOfSoundfieldGroupsLabelSubDescriptor }, + { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x81,0x03 }, mxf_read_ffv1_sub_descriptor, sizeof(MXFFFV1SubDescriptor), FFV1SubDescriptor }, { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 }, mxf_read_track, sizeof(MXFTrack), Track }, /* Static Track */ { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 }, mxf_read_track, sizeof(MXFTrack), Track }, /* Generic Track */ { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x14,0x00 }, mxf_read_timecode_component, sizeof(MXFTimecodeComponent), TimecodeComponent }, From patchwork Mon Jul 11 21:44:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 36738 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:6da0:b0:8b:e47:9dbf with SMTP id wl32csp1622250pzb; Mon, 11 Jul 2022 14:45:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uDE7WmMpHuX2TuYYMU1uFQis4cScU3f9325SoayOS0OC0jSgfY0oSvHepLc4DSvvFNs4Ez X-Received: by 2002:a17:907:271a:b0:72b:4ef4:2d8e with SMTP id w26-20020a170907271a00b0072b4ef42d8emr8995320ejk.634.1657575928548; Mon, 11 Jul 2022 14:45:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657575928; cv=none; d=google.com; s=arc-20160816; b=pZgMFn2zc3+r7eqznHCWbPvsPvijeB1Uge1ugd6NOQZKolkWT3Qb1AciCqI9eBwNaM I36SWoJGb9FG7OFA56iPRm8cuIRODnsbC1F5DyhjtCkJ1F6jAsLr0VL7n9piWoAKBbHS ZcOQMqAR4vj1cn2wOfimrHxIewoN/KYB5qlKfJtGmTzYEmcizc/rrF8pNfbAhScRnTH0 ev7sXeQSR3maCApIgsoj5wn5fVdJU0z/VaB3zfAMw2PsmkdPXtI/fvbUGZi8BaTfiQps HncfvXXBohvPiF5p7xpFyTSLINroj61Gn+kvyJezkdEBPlADZIy4rW9FUsJdVLwYGg3U 604w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=wSbOuvnkBNI8E/LOpi3v6XGpdI1JChw5mqsEykhcBuY=; b=tk+7vTiKvdZb9vgpCahrdqrDnaJ2Hvq98yghcmti+we+338XbPZeLs1oN1N3WqRVaE ENeG+vRc9iwLg3GLu7jhGurC4mCpPueOaiZWGeWaEBL4YI7UqLHzXZ3RPNXQUgDVnv/0 ZIeXAvfLW4HHCLg7lC1oX6Mc7nVpHxUDO5FlN2Ud9R2IHAHm1zOcSgzjWB89rXW8e5mo Y1PGvGXLSWB824RMyQJ3DW2mQ+5pXzxj4GIHRFUrylbzfHBWdWl+qZ/9h3eDdxh09/Ln 31/9ApsYw4J2aI0AdU8LcbwSq0zn9qM5TLGF28vNzcpEJJwH1jxfAMSoMIF80L1yMtpN ov+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ci12-20020a170906c34c00b00710ac087dd5si10236284ejb.699.2022.07.11.14.45.27; Mon, 11 Jul 2022 14:45:28 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 928E768B810; Tue, 12 Jul 2022 00:45:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at03-3.mx.upcmail.net (vie01a-dmta-at03-3.mx.upcmail.net [62.179.121.153]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 180D068B72B for ; Tue, 12 Jul 2022 00:45:19 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1oB1DS-00Gmdy-2l for ffmpeg-devel@ffmpeg.org; Mon, 11 Jul 2022 23:45:18 +0200 Received: from ren-mail-psmtp-mg01. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id B1DSo4D2m8s8UB1DSoIWcp; Mon, 11 Jul 2022 23:45:18 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg01. with ESMTP id B1CUoPWHyOPqFB1CUoR1r0; Mon, 11 Jul 2022 23:44:18 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.4 cv=OcX7sjfY c=1 sm=1 tr=0 ts=62cc99b2 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=6mIMkX5pS-G3LCW_aCcA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 11 Jul 2022 23:44:16 +0200 Message-Id: <20220711214417.12286-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220711214417.12286-1-michael@niedermayer.cc> References: <20220711214417.12286-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfMmitmN2ajv387QEUdx5iuf6iFqj+9Ph5VeOSuDpUXcSu6zCoveL6HDbDwXIvAw4vRxyAp01R7FtTsLzFjPi/GUVdQNXMZrOSnN6CTLiRpBZoo22E0Zn jYf1jdWBdx3sTMjEqgf9mKaH1fuWXI6OPP/GqAGsafKHEVRUFV+mS9r5rZOq9Um0/ENu68PMXThsTw== Subject: [FFmpeg-devel] [PATCH 2/3] avformat/mpc8: Check and propagate more errors 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: m++AhkqndTkL Fixes: Timeout Fixes: 48846/clusterfuzz-testcase-minimized-ffmpeg_dem_MPC8_fuzzer-5278532493770752 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mpc8.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c index 2822a08b55..95a1529c5d 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -135,37 +135,40 @@ static void mpc8_get_chunk_header(AVIOContext *pb, int *tag, int64_t *size) *size += pos; } -static void mpc8_parse_seektable(AVFormatContext *s, int64_t off) +static int mpc8_parse_seektable(AVFormatContext *s, int64_t off) { MPCContext *c = s->priv_data; int tag; int64_t size, pos, ppos[2]; uint8_t *buf; int i, t, seekd, ret; + int64_t ret64; GetBitContext gb; if (s->nb_streams == 0) { av_log(s, AV_LOG_ERROR, "No stream added before parsing seek table\n"); - return; + return AVERROR_INVALIDDATA; } - avio_seek(s->pb, off, SEEK_SET); + ret64 = avio_seek(s->pb, off, SEEK_SET); + if (ret64 < 0) + return AVERROR_INVALIDDATA; mpc8_get_chunk_header(s->pb, &tag, &size); - if(tag != TAG_SEEKTABLE){ + if(tag != TAG_SEEKTABLE || avio_feof(s->pb)){ av_log(s, AV_LOG_ERROR, "No seek table at given position\n"); - return; + return AVERROR_INVALIDDATA; } if (size > INT_MAX/10 || size<=0) { av_log(s, AV_LOG_ERROR, "Bad seek table size\n"); - return; + return AVERROR_INVALIDDATA; } if(!(buf = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE))) - return; + return AVERROR(ENOMEM); ret = avio_read(s->pb, buf, size); if (ret != size) { av_log(s, AV_LOG_ERROR, "seek table truncated\n"); av_free(buf); - return; + return AVERROR_INVALIDDATA; } memset(buf+size, 0, AV_INPUT_BUFFER_PADDING_SIZE); @@ -174,14 +177,14 @@ static void mpc8_parse_seektable(AVFormatContext *s, int64_t off) if(size > UINT_MAX/4 || size > c->samples/1152){ av_log(s, AV_LOG_ERROR, "Seek table is too big\n"); av_free(buf); - return; + return AVERROR_INVALIDDATA; } seekd = get_bits(&gb, 4); for(i = 0; i < 2; i++){ pos = gb_get_v(&gb); if (av_sat_add64(pos, c->header_pos) != pos + (uint64_t)c->header_pos) { av_free(buf); - return; + return AVERROR_INVALIDDATA; } pos += c->header_pos; @@ -191,7 +194,7 @@ static void mpc8_parse_seektable(AVFormatContext *s, int64_t off) for(; i < size; i++){ if (get_bits_left(&gb) < 13) { av_free(buf); - return; + return AVERROR_INVALIDDATA; } t = get_unary(&gb, 1, 33) << 12; t += get_bits(&gb, 12); @@ -203,26 +206,31 @@ static void mpc8_parse_seektable(AVFormatContext *s, int64_t off) ppos[0] = pos; } av_free(buf); + return 0; } -static void mpc8_handle_chunk(AVFormatContext *s, int tag, int64_t chunk_pos, int64_t size) +static int mpc8_handle_chunk(AVFormatContext *s, int tag, int64_t chunk_pos, int64_t size) { AVIOContext *pb = s->pb; int64_t pos, off; + int ret; switch(tag){ case TAG_SEEKTBLOFF: pos = avio_tell(pb); off = ffio_read_varlen(pb); if (pos > INT64_MAX - size || off < 0 || off > INT64_MAX - chunk_pos) - return; + return AVERROR_INVALIDDATA; pos += size; - mpc8_parse_seektable(s, chunk_pos + off); + ret = mpc8_parse_seektable(s, chunk_pos + off); + if (ret < 0) + return AVERROR_INVALIDDATA; avio_seek(pb, pos, SEEK_SET); break; default: avio_skip(pb, size); } + return 0; } static int mpc8_read_header(AVFormatContext *s) @@ -249,7 +257,9 @@ static int mpc8_read_header(AVFormatContext *s) } if(tag == TAG_STREAMHDR) break; - mpc8_handle_chunk(s, tag, pos, size); + ret = mpc8_handle_chunk(s, tag, pos, size); + if (ret < 0) + return ret; } if(tag != TAG_STREAMHDR){ av_log(s, AV_LOG_ERROR, "Stream header not found\n"); From patchwork Mon Jul 11 21:44:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 36736 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:6da0:b0:8b:e47:9dbf with SMTP id wl32csp1621908pzb; Mon, 11 Jul 2022 14:44:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1urV09Mlw5mqsoa2oPL7rLdRGSGZKsgdPPyJVN5K15rGI61GxFPC2/c44tTjjzt6wtYkh4A X-Received: by 2002:a05:6402:26c8:b0:43a:c404:a553 with SMTP id x8-20020a05640226c800b0043ac404a553mr18360394edd.53.1657575867780; Mon, 11 Jul 2022 14:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657575867; cv=none; d=google.com; s=arc-20160816; b=eugzuzSoMsQERNBP21mHvoz0aiHRjH+PyuCWvHLUBhhUku57CYHwxnQJc7JyZgG3Y8 ibsTxzOXpXRwF56NM6+r0SHvhcFM/Fulp6CPBBSfzdzpefPXiljJcTRcbbkUTWCTa+Nb Hz0sQlBLJS7b7B3coF9DJV7X2+UPylQq9EFWnvtbs5rlcULr7NXSKRj1vodpssSUktY4 ByTpbHATZDXAY7De+6HSuIllCtLDA5qDXx4eJ4pKDZ/oPr8dTjxDbRwh63ETdcB1UvhR jSB3acKlxz76xS4rZRhjDZKJbXVm4jXinPkMqwhmvsPk4BMQUECzk9VfPKaYQFkIjPDi NReA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=eI5dhuQWLn/fCk4QFHgyrKrl90uXmKoNnT2rsa6lGj4=; b=UQtd0/M8f8qSYm5ycDOGLnlw84gQE3RQdpbVr9Fe2Hl3MXyEPOMmCZ5WOJrhFVzvd0 Hz61MbrCAgN2tEvQD4goY5Xq2elcOeEV+Vh+HWrdCQ5TlPuavsaLlTbAyqXM4o/Rw0C2 MyDY5xRwX89HZ5KpVa4QrY3Lex9FE5m1mpU9Twf+a8r1OgbT/LOQmPhHOAP6RGCcX9N+ aEyZv9ppMml0WFjZGFgLvLjUyG6wykiogPooyitLYcVItSrH+pGblpbvYrfomK56oAv8 vKCRJlIJrxpIOnWwlmNdKRfbGjW6NyVt4KkZvahZJLZImsAanytkVCTTfdWa8CPqWbXQ QTjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g15-20020a1709065d0f00b0072b1433b2e7si4791478ejt.300.2022.07.11.14.44.27; Mon, 11 Jul 2022 14:44:27 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6BF1A68B62B; Tue, 12 Jul 2022 00:44:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-at02-1.mx.upcmail.net (vie01a-dmta-at02-1.mx.upcmail.net [62.179.121.148]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B4DAF68B62B for ; Tue, 12 Jul 2022 00:44:19 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at02.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1oB1CU-0004Fe-Tv for ffmpeg-devel@ffmpeg.org; Mon, 11 Jul 2022 23:44:18 +0200 Received: from ren-mail-psmtp-mg02. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id B1C1o4B5j8s8UB1CUoIWSR; Mon, 11 Jul 2022 23:44:18 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg02. with ESMTP id B1CUo4r1C8eSWB1CUo0tDz; Mon, 11 Jul 2022 23:44:18 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.4 cv=KKE5sHJo c=1 sm=1 tr=0 ts=62cc99b2 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=s7QeBKBQBO-7t3_pSA0A:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 11 Jul 2022 23:44:17 +0200 Message-Id: <20220711214417.12286-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220711214417.12286-1-michael@niedermayer.cc> References: <20220711214417.12286-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfC/UGQfaXzFgiYawD8uWLADiAGI+BhJYeWOUURav5IrhCiVXUPWgo24jTB3FrshRDrvZZrSKMV+IMrlZq81vOVHZE5qBUQ2WLAOUrA8SKs3GS4Hx65wz xGxyw7PXv8DAEvGVA898Fl/ou/m1zhzdKnoSrJve9mYiP4GttQX7L08LnHFvFCFXsISpgfHJf4ptOQ== Subject: [FFmpeg-devel] [PATCH 3/3] tools/target_dec_fuzzer: Adjust threshold for ANM 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: zZSXsczVKA6x Fixes: Timeout Fixes: 48923/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ANM_fuzzer-6391662321991680 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- tools/target_dec_fuzzer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c index f44cc6f857..3ba87b7f1c 100644 --- a/tools/target_dec_fuzzer.c +++ b/tools/target_dec_fuzzer.c @@ -209,6 +209,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { maxsamples = maxsamples_per_frame * maxiteration; switch (c->p.id) { case AV_CODEC_ID_AGM: maxpixels /= 1024; break; + case AV_CODEC_ID_ANM: maxpixels /= 1024; break; case AV_CODEC_ID_ARBC: maxpixels /= 1024; break; case AV_CODEC_ID_ARGO: maxpixels /= 1024; break; case AV_CODEC_ID_BINKVIDEO: maxpixels /= 32; break;