diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 516dd41..2b84850 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -546,7 +546,7 @@ static int decode_frame(AVCodecContext *avctx,
     for (;;) {
         if (bytestream2_get_bytes_left(&s->gb) <= 0) {
             av_log(avctx, AV_LOG_ERROR, "No bytes left\n");
-            goto fail;
+            goto exit_loop;
         }
 
         length = bytestream2_get_be32(&s->gb);
