diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 06bd8bf1ae881132124a3e8324374f23e03fb90f..4af97c1822438d3c01904197fbb7905760bcf010 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -248,6 +248,8 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
                 }
                 break;
             }
+        } else if (n < 0) {
+            return AVERROR(EIO);
         }
     }
 #endif