Merge pull request #1156 from felfert/master
[mono.git] / mcs / class / corlib / System.Resources / Win32Resources.cs
index 0e7dad2a890a4c9343f6d0790ef924c5adcaef50..ad58ce8823fc9092687e547878d7a6eaffed78f3 100644 (file)
@@ -236,14 +236,8 @@ internal class Win32VersionResource : Win32Resource {
        public string[] WellKnownProperties = {
                "Comments",
                "CompanyName",
-#if !NET_2_0
-               "FileDescription",
-#endif
                "FileVersion",
                "InternalName",
-#if !NET_2_0
-               "LegalCopyright",
-#endif
                "LegalTrademarks",
                "OriginalFilename",
                "ProductName",
@@ -283,21 +277,15 @@ internal class Win32VersionResource : Win32Resource {
 
                properties = new Hashtable ();
 
-#if NET_2_0
                string defaultvalue = compilercontext ? string.Empty : " ";
-#else
-               string defaultvalue = " ";
-#endif
 
                // Well known properties
                foreach (string s in WellKnownProperties)
                        // The value of properties can't be empty
                        properties [s] = defaultvalue;
 
-#if NET_2_0
                LegalCopyright = " ";
                FileDescription = " ";
-#endif
        }
 
        public string Version {
@@ -310,11 +298,7 @@ internal class Win32VersionResource : Win32Resource {
                }
 
                set {
-#if NET_2_0
                        long[] ver = new long [4] { 0, 0, 0, 0 };
-#else
-                       long [] ver = new long [4] { 0, 0xffff, 0xffff, 0xffff };
-#endif
                        if (value != null) {
                                string[] parts = value.Split ('.');
 
@@ -604,26 +588,33 @@ internal class Win32ResFileReader {
 
        int read_int16 () {
                int b1 = res_file.ReadByte ();
-               int b2 = res_file.ReadByte ();
+               if (b1 == -1)
+                       return -1;
 
-               if ((b1 == -1) || (b2 == -1))
+               int b2 = res_file.ReadByte ();
+               if (b2 == -1)
                        return -1;
-               else
-                       return b1 | (b2 << 8);
+
+               return b1 | (b2 << 8);
        }
 
        int read_int32 () {
                int w1 = read_int16 ();
+               if (w1 == -1)
+                       return -1;
                int w2 = read_int16 ();
-
-               if ((w1 == -1) || (w2 == -1))
+               if (w2 == -1)
                        return -1;
+
                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 () {
@@ -664,8 +655,9 @@ internal class Win32ResFileReader {
 
                while (true) {
 
-                       read_padding ();
-
+                       if (!read_padding ())
+                               break;
+                       
                        int data_size = read_int32 ();
 
                        if (data_size == -1)
@@ -677,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 =
@@ -694,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));
                }
@@ -708,6 +702,7 @@ internal class Win32ResFileReader {
 //
 internal class ICONDIRENTRY {
 
+#pragma warning disable 649
        public byte bWidth;
        public byte bHeight;
        public byte bColorCount;
@@ -716,7 +711,7 @@ internal class ICONDIRENTRY {
        public Int16 wBitCount;
        public Int32 dwBytesInRes;
        public Int32 dwImageOffset;
-
+#pragma warning restore 649
        public byte[] image;
 
        public override string ToString () {