changeset 762:a22aa7bfa108 trunk

[svn] - try to avoid a buffer overflow when detecting an MPEG stream
author nenolod
date Wed, 01 Mar 2006 09:07:09 -0800
parents 363f8644bce7
children 4da914641039
files Plugins/Input/mpg123/mpg123.c
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/Input/mpg123/mpg123.c	Tue Feb 28 14:56:30 2006 -0800
+++ b/Plugins/Input/mpg123/mpg123.c	Wed Mar 01 09:07:09 2006 -0800
@@ -243,16 +243,20 @@
     guchar buf[DET_BUF_SIZE];
     int in_buf, i;
     gboolean ret = FALSE;
+    guint cyc = 0;
 
     if ((file = vfs_fopen(filename, "rb")) == NULL)
         return FALSE;
     if (vfs_fread(tmp, 1, 4, file) != 4)
         goto done;
     head = convert_to_header(tmp);
-    while (!mpg123_head_check(head)) {
+    while (!mpg123_head_check(head) && ++cyc < 5) {
         /*
          * The mpeg-stream can start anywhere in the file,
          * so we check the entire file
+	 *
+	 * Incorrect! We give up past five iterations of this
+	 * code for safety's sake. Buffer overflows suck. --nenolod
          */
         /* Optimize this */
         in_buf = vfs_fread(buf, 1, DET_BUF_SIZE, file);