diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index c283b9c0c37cb4bd74b33a8b76496b5f040580a0..9ee1ded541d45f40812c71d9b22ee693b065b884 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -182,6 +182,7 @@ static int parse_picture_segment(AVCodecContext *avctx,
 
         memcpy(ctx->picture.rle + ctx->picture.rle_data_len, buf, buf_size);
         ctx->picture.rle_data_len += buf_size;
+        ctx->picture.rle_remaining_len -= buf_size;
 
         return 0;
     }