From: "Sebastian Dröge" <slomo@coaxion.net> To: ffmpeg-devel@ffmpeg.org Cc: "Sebastian Dröge" <sebastian@centricular.com> Subject: [FFmpeg-devel] [PATCH v2] avformat/mov: Correctly read EIA608 packets if multiple boxes or non-field 1 data is present Date: Wed, 7 Jun 2023 15:09:33 +0300 Message-ID: <20230607120933.776663-1-slomo@coaxion.net> (raw) In-Reply-To: <20230515093944.623728-1-slomo@coaxion.net> From: Sebastian Dröge <sebastian@centricular.com> The payload of EIA608 samples in MOV is one or more cdat or cdt2 boxes. cdat contains EIA608 byte pairs for field 1, cdt2 for field 2. Previously any box following the first was treated as EIA608 byte pairs instead of parsing them correctly, and all data was handled as field 1. --- Changes compared to v1: - Skip over unknown boxes instead of erroring out, as required by the spec. - Calculate write_size correctly. libavformat/mov.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 9fdeef057e..341b42228d 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -8868,22 +8868,43 @@ static int mov_change_extradata(MOVStreamContext *sc, AVPacket *pkt) static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size) { - int new_size, ret; + const uint32_t cdat_fourcc = AV_RL32("cdat"); + const uint32_t cdt2_fourcc = AV_RL32("cdt2"); + int new_size, write_size, ret; if (size <= 8) return AVERROR_INVALIDDATA; + new_size = ((size - 8) / 2) * 3; ret = av_new_packet(pkt, new_size); if (ret < 0) return ret; - avio_skip(pb, 8); - for (int j = 0; j < new_size; j += 3) { - pkt->data[j] = 0xFC; - pkt->data[j+1] = avio_r8(pb); - pkt->data[j+2] = avio_r8(pb); + write_size = 0; + while (size > 8) { + uint32_t box_size = avio_rb32(pb); + uint32_t box_fourcc = avio_rl32(pb); + + if (box_size <= 8 || (box_size & 1) != 0 || box_size > size) + return AVERROR_INVALIDDATA; + if (box_fourcc != cdat_fourcc && box_fourcc != cdt2_fourcc) { + avio_skip(pb, box_size - 8); + size -= box_size; + continue; + } + + for (int j = 8; j < box_size; j += 2) { + pkt->data[write_size] = box_fourcc == cdat_fourcc ? 0xFC : 0xFF; + pkt->data[write_size+1] = avio_r8(pb); + pkt->data[write_size+2] = avio_r8(pb); + write_size += 3; + } + + size -= box_size; } + av_shrink_packet(pkt, write_size); + return 0; } -- 2.40.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".
next prev parent reply other threads:[~2023-06-07 12:10 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-15 9:39 [FFmpeg-devel] [PATCH] " Sebastian Dröge 2023-06-07 12:09 ` Sebastian Dröge [this message] 2023-06-07 14:26 ` [FFmpeg-devel] [PATCH v3] " Sebastian Dröge
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=20230607120933.776663-1-slomo@coaxion.net \ --to=slomo@coaxion.net \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=sebastian@centricular.com \ /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