2010-03-01 Miguel de Icaza <miguel@novell.com>
authorMiguel de Icaza <miguel@gnome.org>
Mon, 1 Mar 2010 19:34:39 +0000 (19:34 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 1 Mar 2010 19:34:39 +0000 (19:34 -0000)
* Win32Resources.cs: Prevent infinite loops if the resource that
we are reading is invalid.   Fixes the mscorlib part of #327500

svn path=/trunk/mcs/; revision=152739

mcs/class/corlib/System.Resources/ChangeLog
mcs/class/corlib/System.Resources/Win32Resources.cs

index 60c704d3d438cf166db83fca3bbf296c450edbef..4b0fe5e655905f39911a7c54ba0d7e73bfd301d8 100644 (file)
@@ -1,3 +1,8 @@
+2010-03-01  Miguel de Icaza  <miguel@novell.com>
+
+       * Win32Resources.cs: Prevent infinite loops if the resource that
+       we are reading is invalid.   Fixes the mscorlib part of #327500
+
 2009-11-01  Sebastien Pouliot  <sebastien@ximian.com>
 
        * ResourceManager.cs (GetResourceFilePath): Don't use 
index 9aaa1268af57b3074f84cdb3c7833c6a41e891f2..ad58ce8823fc9092687e547878d7a6eaffed78f3 100644 (file)
@@ -609,9 +609,12 @@ internal class Win32ResFileReader {
                return w1 | (w2 << 16);
        }
 
-       private void read_padding () {
-               while ((res_file.Position % 4) != 0)
-                       read_int16 ();
+       private bool read_padding () {
+               while ((res_file.Position % 4) != 0){
+                       if (read_int16 () == -1)
+                               return false;
+               }
+               return true;
        }
 
        NameOrId read_ordinal () {
@@ -652,8 +655,9 @@ internal class Win32ResFileReader {
 
                while (true) {
 
-                       read_padding ();
-
+                       if (!read_padding ())
+                               break;
+                       
                        int data_size = read_int32 ();
 
                        if (data_size == -1)
@@ -665,8 +669,9 @@ internal class Win32ResFileReader {
                        NameOrId type = read_ordinal ();
                        NameOrId name = read_ordinal ();
 
-                       read_padding ();
-
+                       if (!read_padding ())
+                               break;
+                       
                        //int data_version = 
                        read_int32 ();
                        //int memory_flags =
@@ -682,7 +687,8 @@ internal class Win32ResFileReader {
                                continue;
 
                        byte[] data = new byte [data_size];
-                       res_file.Read (data, 0, data_size);
+                       if (res_file.Read (data, 0, data_size) != data_size)
+                               break;
 
                        resources.Add (new Win32EncodedResource (type, name, language_id, data));
                }