Web lists-archives.com

[MPlayer-dev-eng] [PATCH] Fix incomplete loading of playlists of certain sizes




Hi,

the bug this patches fixes appears when you have playlist files of a
size larger than the buffer size used by playtreeparser.c but smaller
than the buffer size used by stream.c.
What happens is that the whole playlist file is read by stream.c in and
put in the stream buffer by stream_fill_buffer() and stream->eof is set
to true. However, playtreeparser.c only fills it's own buffer and then
upon seeing stream->eof being true, treats the playlist as ended even
tho the stream buffer still contains data.

My solution is not to use stream->eof at all but instead react to
stream_read() returning == 0 as a marker for when the stream has ended

Regards, Joel Klinghed

Index: playtreeparser.c
===================================================================
--- playtreeparser.c	(revision 37379)
+++ playtreeparser.c	(working copy)
@@ -74,7 +74,7 @@
     p->iter = p->buffer;
   }
 
-  if(p->stream->eof && (p->buffer_end == 0 || p->iter[0] == '\0'))
+  if(p->eof && (p->buffer_end == 0 || p->iter[0] == '\0'))
     return NULL;
 
   assert(p->buffer_end < p->buffer_size);
@@ -96,7 +96,7 @@
       resize = 0;
     }
 
-    if(p->buffer_size - p->buffer_end > 1 && ! p->stream->eof) {
+    if(p->buffer_size - p->buffer_end > 1 && ! p->eof) {
       r = stream_read(p->stream,p->buffer + p->buffer_end,p->buffer_size - p->buffer_end - 1);
       if(r > 0) {
 	p->buffer_end += r;
@@ -104,13 +104,14 @@
 	p->buffer[p->buffer_end] = '\0';
 	while(strlen(p->buffer + p->buffer_end - r) != r)
 	  p->buffer[p->buffer_end - r + strlen(p->buffer + p->buffer_end - r)] = '\n';
-      }
+      } else if(r == 0 && stream_eof(p->stream))
+	p->eof = 1;
       assert(!p->buffer[p->buffer_end]);
     }
 
     end = strchr(p->iter,'\n');
     if(!end) {
-      if(p->stream->eof) {
+      if(p->eof) {
 	end = p->buffer + p->buffer_end;
 	break;
       }
Index: playtreeparser.h
===================================================================
--- playtreeparser.h	(revision 37379)
+++ playtreeparser.h	(working copy)
@@ -36,7 +36,7 @@
   struct stream *stream;
   char *buffer,*iter,*line;
   int buffer_size , buffer_end;
-  int deep,keep;
+  int deep,keep,eof;
 } play_tree_parser_t;
 
 /// Create a new parser.
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng