History

avformat/movenc: fix writing dOps atoms

Don't blindly copy all bytes in extradata past ChannelMappingFamily. Instead check if ChannelMappingFamily is not 0 and then only write the correct amount of bytes from ChannelMappingTable, as defined in the spec[1]. Fixes part of ticket #9190. [1] https://opus-codec.org/docs/opus_in_isobmff.html#4.3.2

James Almer committed 5 years ago

Commit bc010611 parent 55d667d1 file · +13 −2Browse files

Unified · Split

libavformat/movenc.c+13−2
@@ -797,6 +797,7 @@ static int mov_write_dfla_tag(AVIOContext *pb, MOVTrack *track) · 796 unmodified lines
797797 static int mov_write_dops_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track)
798798 {
799799 int64_t pos = avio_tell(pb);
800+ int channels, channel_map;
800801 avio_wb32(pb, 0);
801802 ffio_wfourcc(pb, "dOps");
802803 avio_w8(pb, 0); /* Version */
@@ -807,12 +808,22 @@ static int mov_write_dops_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra · 4 unmodified lines
807808 /* extradata contains an Ogg OpusHead, other than byte-ordering and
808809 OpusHead's preceeding magic/version, OpusSpecificBox is currently
809810 identical. */
810− avio_w8(pb, AV_RB8(track->par->extradata + 9)); /* OuputChannelCount */
811+ channels = AV_RB8(track->par->extradata + 9);
812+ channel_map = AV_RB8(track->par->extradata + 18);
813+
814+ avio_w8(pb, channels); /* OuputChannelCount */
811815 avio_wb16(pb, AV_RL16(track->par->extradata + 10)); /* PreSkip */
812816 avio_wb32(pb, AV_RL32(track->par->extradata + 12)); /* InputSampleRate */
813817 avio_wb16(pb, AV_RL16(track->par->extradata + 16)); /* OutputGain */
818+ avio_w8(pb, channel_map); /* ChannelMappingFamily */
814819 /* Write the rest of the header out without byte-swapping. */
815− avio_write(pb, track->par->extradata + 18, track->par->extradata_size - 18);
820+ if (channel_map) {
821+ if (track->par->extradata_size < 21 + channels) {
822+ av_log(s, AV_LOG_ERROR, "invalid extradata size\n");
823+ return AVERROR_INVALIDDATA;
824+ }
825+ avio_write(pb, track->par->extradata + 19, 2 + channels); /* ChannelMappingTable */
826+ }
816827
817828 return update_size(pb, pos);
818829 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t