diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index 637ceed34ae250f679f34a031d0f59c6cc4a6728..77c84490a062c77957f92c65812f4fe8071ebbf5 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -864,6 +864,10 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
         }
         //printf("Fragsize %d\n", asf->packet_frag_size);
     } else {
+        if (rsize > asf->packet_size_left) {
+            av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n");
+            return -1;
+        }
         asf->packet_frag_size = asf->packet_size_left - rsize;
         //printf("Using rest  %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
     }