summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorJeff Downs <heydowns@borg.com>2007-12-14 06:25:23 +0000
committerJeff Downs <heydowns@borg.com>2007-12-14 06:25:23 +0000
commitaeb59e839f97e88dd0b5f0b2a4422a9ee75321e5 (patch)
tree3d39f15dfdbc8670f24df0d4740b3a604600bf51 /libavcodec
parent41f7e2d11d2dca23842ee89d530ca9fa15cec9d8 (diff)
Ensure that our total reference frame count does not exceed the SPS
max frame count, which is limited to less than the size of the reference buffers, thereby preventing overflow. Part of fix for issue 281. Originally committed as revision 11216 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/h264.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index f34bf2c5e2..ee00f2166a 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -3612,6 +3612,29 @@ static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
s->current_picture_ptr->reference |= s->picture_structure;
}
+ if (h->sps.ref_frame_count &&
+ h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count){
+
+ /* We have too many reference frames, probably due to corrupted
+ * stream. Need to discard one frame. Prevents overrun of the
+ * short_ref and long_ref buffers.
+ */
+ av_log(h->s.avctx, AV_LOG_ERROR,
+ "number of reference frames exceeds max (probably "
+ "corrupt input), discarding one\n");
+
+ if (h->long_ref_count) {
+ for (i = 0; i < 16; ++i)
+ if (h->long_ref[i])
+ break;
+
+ assert(i < 16);
+ remove_long_at_index(h, i);
+ } else {
+ remove_short_at_index(h, h->short_ref_count - 1);
+ }
+ }
+
print_short_term(h);
print_long_term(h);
return 0;