aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Eugen Hoyos <cehoyos@ag.or.at>2011-11-08 10:35:14 +0100
committerCarl Eugen Hoyos <cehoyos@ag.or.at>2011-11-08 10:35:14 +0100
commit4d7c71c36467331f1e0c0f17af9f371d33308a9c (patch)
tree9a0abce5245b3ffaef479b88b29b66587e72ee53
parent8a3f976498cc096644b95ade7240a73e17d3a042 (diff)
downloadandroid_external_ffmpeg-4d7c71c36467331f1e0c0f17af9f371d33308a9c.tar.gz
android_external_ffmpeg-4d7c71c36467331f1e0c0f17af9f371d33308a9c.tar.bz2
android_external_ffmpeg-4d7c71c36467331f1e0c0f17af9f371d33308a9c.zip
Check for OOM after av_mallocz() in ff_interleave_add_packet().
Fixes a crash with the sample from Ubuntu bug #869125.
-rw-r--r--libavformat/audiointerleave.c13
-rw-r--r--libavformat/internal.h3
-rw-r--r--libavformat/utils.c11
3 files changed, 20 insertions, 7 deletions
diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index 844112fcf5..922f4a5880 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -113,10 +113,13 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt
}
av_fifo_generic_write(aic->fifo, pkt->data, pkt->size, NULL);
} else {
+ int ret;
// rewrite pts and dts to be decoded time line position
pkt->pts = pkt->dts = aic->dts;
aic->dts += pkt->duration;
- ff_interleave_add_packet(s, pkt, compare_ts);
+ ret = ff_interleave_add_packet(s, pkt, compare_ts);
+ if (ret < 0)
+ return ret;
}
pkt = NULL;
}
@@ -125,8 +128,12 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt
AVStream *st = s->streams[i];
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
AVPacket new_pkt;
- while (ff_interleave_new_audio_packet(s, &new_pkt, i, flush))
- ff_interleave_add_packet(s, &new_pkt, compare_ts);
+ int ret;
+ while (ff_interleave_new_audio_packet(s, &new_pkt, i, flush)) {
+ ret = ff_interleave_add_packet(s, &new_pkt, compare_ts);
+ if (ret < 0)
+ return ret;
+ }
}
}
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 582a2c8fe1..f15940cf4e 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -71,8 +71,9 @@ void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i
/**
* Add packet to AVFormatContext->packet_buffer list, determining its
* interleaved position using compare() function argument.
+ * @return 0, or < 0 on error
*/
-void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
+int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
int (*compare)(AVFormatContext *, AVPacket *, AVPacket *));
void ff_read_frame_flush(AVFormatContext *s);
diff --git a/libavformat/utils.c b/libavformat/utils.c
index f32f2384ed..1d84cc6710 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3262,12 +3262,14 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
return ret;
}
-void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
+int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
{
AVPacketList **next_point, *this_pktl;
this_pktl = av_mallocz(sizeof(AVPacketList));
+ if (!this_pktl)
+ return AVERROR(ENOMEM);
this_pktl->pkt= *pkt;
pkt->destruct= NULL; // do not free original but only the copy
av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-alloced memory
@@ -3296,6 +3298,7 @@ next_non_null:
s->streams[pkt->stream_index]->last_in_packet_buffer=
*next_point= this_pktl;
+ return 0;
}
static int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
@@ -3314,10 +3317,12 @@ int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk
AVPacketList *pktl;
int stream_count=0, noninterleaved_count=0;
int64_t delta_dts_max = 0;
- int i;
+ int i, ret;
if(pkt){
- ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts);
+ ret = ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts);
+ if (ret < 0)
+ return ret;
}
for(i=0; i < s->nb_streams; i++) {