diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 4fcdb75bce35f2ba68f12aefa4b876d05d52ae4a..fd70b0f23149b3fbe1b9c16e92921fe5e2fb86c5 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -8059,7 +8059,8 @@ static int h264_parse(AVCodecParserContext *s,
             return buf_size;
         }
 
-        if(next<0){
+        if(next<0 && next != END_NOT_FOUND){
+            assert(pc->last_index + next >= 0 );
             find_frame_end(h, &pc->buffer[pc->last_index + next], -next); //update state
         }
     }