Merge commit '858864d350320dd807e349bda017026e61a47fe0' into release/1.1
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 12 May 2013 11:19:54 +0000 (13:19 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 12 May 2013 11:19:54 +0000 (13:19 +0200)
* commit '858864d350320dd807e349bda017026e61a47fe0':
  xmv: check audio track parameters validity.
  bmv: check for len being valid in bmv_decode_frame().
  xmv: do not leak memory in the error paths in xmv_read_header()
  matroska: pass the lace size to the matroska_parse_rm_audio

Conflicts:
libavformat/matroskadec.c
libavformat/xmv.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/bmv.c
libavformat/matroskadec.c
libavformat/xmv.c

Simple merge
@@@ -2245,8 -2081,9 +2245,9 @@@ static int matroska_parse_block(Matrosk
               st->codec->codec_id == AV_CODEC_ID_ATRAC3) &&
               st->codec->block_align && track->audio.sub_packet_size) {
  
-             res = matroska_parse_rm_audio(matroska, track, st, data, size,
+             res = matroska_parse_rm_audio(matroska, track, st, data,
+                                           lace_size[n],
 -                                          timecode, duration, pos);
 +                                          timecode, pos);
              if (res)
                  goto end;
  
@@@ -124,6 -126,16 +124,15 @@@ static int xmv_probe(AVProbeData *p
      return 0;
  }
  
 -    av_free(xmv->audio);
 -    av_free(xmv->audio_tracks);
+ static int xmv_read_close(AVFormatContext *s)
+ {
+     XMVDemuxContext *xmv = s->priv_data;
++    av_freep(&xmv->audio);
+     return 0;
+ }
  static int xmv_read_header(AVFormatContext *s)
  {
      XMVDemuxContext *xmv = s->priv_data;
  
      avio_skip(pb, 2); /* Unknown (padding?) */
  
 -    xmv->audio_tracks = av_malloc(xmv->audio_track_count * sizeof(XMVAudioTrack));
 -    if (!xmv->audio_tracks)
 -        return AVERROR(ENOMEM);
 -
      xmv->audio = av_malloc(xmv->audio_track_count * sizeof(XMVAudioPacket));
-     if (!xmv->audio)
-         return AVERROR(ENOMEM);
+     if (!xmv->audio) {
+         ret = AVERROR(ENOMEM);
+         goto fail;
+     }
  
      for (audio_track = 0; audio_track < xmv->audio_track_count; audio_track++) {
 -        XMVAudioTrack  *track  = &xmv->audio_tracks[audio_track];
 -        XMVAudioPacket *packet = &xmv->audio       [audio_track];
 +        XMVAudioPacket *packet = &xmv->audio[audio_track];
          AVStream *ast = NULL;
  
 -        track->compression     = avio_rl16(pb);
 -        track->channels        = avio_rl16(pb);
 -        track->sample_rate     = avio_rl32(pb);
 -        track->bits_per_sample = avio_rl16(pb);
 -        track->flags           = avio_rl16(pb);
 -
 -        track->bit_rate      = track->bits_per_sample *
 -                               track->sample_rate *
 -                               track->channels;
 -        track->block_align   = 36 * track->channels;
 -        track->block_samples = 64;
 -        track->codec_id      = ff_wav_codec_get_id(track->compression,
 -                                                   track->bits_per_sample);
 -
 -        packet->track        = track;
 +        packet->compression     = avio_rl16(pb);
 +        packet->channels        = avio_rl16(pb);
 +        packet->sample_rate     = avio_rl32(pb);
 +        packet->bits_per_sample = avio_rl16(pb);
 +        packet->flags           = avio_rl16(pb);
 +
 +        if (!packet->channels) {
 +            av_log(s, AV_LOG_ERROR, "0 channels\n");
 +            return AVERROR(EINVAL);
 +        }
 +
 +        packet->bit_rate      = packet->bits_per_sample *
 +                                packet->sample_rate *
 +                                packet->channels;
 +        packet->block_align   = 36 * packet->channels;
 +        packet->block_samples = 64;
 +        packet->codec_id      = ff_wav_codec_get_id(packet->compression,
 +                                                    packet->bits_per_sample);
 +
          packet->stream_index = -1;
  
          packet->frame_size  = 0;
  
          /* TODO: ADPCM'd 5.1 sound is encoded in three separate streams.
           *       Those need to be interleaved to a proper 5.1 stream. */
 -        if (track->flags & XMV_AUDIO_ADPCM51)
 +        if (packet->flags & XMV_AUDIO_ADPCM51)
              av_log(s, AV_LOG_WARNING, "Unsupported 5.1 ADPCM audio stream "
 -                                      "(0x%04X)\n", track->flags);
 +                                      "(0x%04X)\n", packet->flags);
  
 -        if (!track->channels || !track->sample_rate) {
++        if (!packet->channels || !packet->sample_rate) {
+             av_log(s, AV_LOG_ERROR, "Invalid parameters for audio track %d.\n",
+                    audio_track);
+             ret = AVERROR_INVALIDDATA;
+             goto fail;
+         }
          ast = avformat_new_stream(s, NULL);
-         if (!ast)
-             return AVERROR(ENOMEM);
+         if (!ast) {
+             ret = AVERROR(ENOMEM);
+             goto fail;
+         }
  
          ast->codec->codec_type            = AVMEDIA_TYPE_AUDIO;
 -        ast->codec->codec_id              = track->codec_id;
 -        ast->codec->codec_tag             = track->compression;
 -        ast->codec->channels              = track->channels;
 -        ast->codec->sample_rate           = track->sample_rate;
 -        ast->codec->bits_per_coded_sample = track->bits_per_sample;
 -        ast->codec->bit_rate              = track->bit_rate;
 -        ast->codec->block_align           = 36 * track->channels;
 +        ast->codec->codec_id              = packet->codec_id;
 +        ast->codec->codec_tag             = packet->compression;
 +        ast->codec->channels              = packet->channels;
 +        ast->codec->sample_rate           = packet->sample_rate;
 +        ast->codec->bits_per_coded_sample = packet->bits_per_sample;
 +        ast->codec->bit_rate              = packet->bit_rate;
 +        ast->codec->block_align           = 36 * packet->channels;
  
 -        avpriv_set_pts_info(ast, 32, track->block_samples, track->sample_rate);
 +        avpriv_set_pts_info(ast, 32, packet->block_samples, packet->sample_rate);
  
          packet->stream_index = ast->index;