[rtmpdump] [PATCH] Fix for rare infinite loop while downloading

Matt Robinson rtmpdump at nerdoftheherd.com
Tue Sep 11 18:37:11 CEST 2012

Fix for an infinite loop on very rare occasions.  The application can 
get into the following state while in the main download loop within the 
Download function in rtmpdump.c:

rtmp->m_read.status == RTMP_READ_EOF
rtmp->m_sb.sb_socket != -1
rtmp->m_sb.sb_timedout == 0

The status of RTMP_READ_EOF causes the call to RTMP_Read to return 
straight away with a value of 0.  This zero value then causes the rest 
of the loop body to be skipped.  However, the values of sb_socket and 
sb_timeout cause the while condition to continue to return true, causing 
an infinite loop.

I'm happy to provide some more information about this issue if that 
would be useful, or if not please find below a patch to prevent this 
from occurring.  Without a fuller understanding of the code I'm not sure 
if this is the right way of solving it, but it is one way...

  rtmpdump.c |    9 ++++++---
  1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/rtmpdump.c b/rtmpdump.c
index e52f7d4..7535da8 100644
--- a/rtmpdump.c
+++ b/rtmpdump.c
@@ -580,13 +580,16 @@ Download(RTMP * rtmp,		// connected RTMP object
-#ifdef _DEBUG
+#ifdef _DEBUG
  	  RTMP_Log(RTMP_LOGDEBUG, "zero read!");
-	}
+	  if(rtmp->m_read.status == RTMP_READ_EOF)
+	    {
+	      break;
+	    }
+	}
    while (!RTMP_ctrlC && nRead > -1 && RTMP_IsConnected(rtmp) && 

More information about the rtmpdump mailing list