diff --git a/libavcodec/roqvideodec.c b/libavcodec/roqvideodec.c
index ef561a32105e28de078eab21bba1314ae60b3214..39233be87c16306aeb1663d263982b8298e2fb1e 100644
--- a/libavcodec/roqvideodec.c
+++ b/libavcodec/roqvideodec.c
@@ -44,7 +44,7 @@ static void roqvideo_decode_frame(RoqContext *ri)
     roq_qcell *qcell;
     int64_t chunk_start;
 
-    while (bytestream2_get_bytes_left(&ri->gb) > 0) {
+    while (bytestream2_get_bytes_left(&ri->gb) >= 8) {
         chunk_id   = bytestream2_get_le16(&ri->gb);
         chunk_size = bytestream2_get_le32(&ri->gb);
         chunk_arg  = bytestream2_get_le16(&ri->gb);