2010-04-20 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 20 Apr 2010 15:54:28 +0000 (15:54 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 20 Apr 2010 15:54:28 +0000 (15:54 -0000)
* ChunkStream.cs: ignore chunk extensions when reading the chunk
size. Fixes bug #597556.

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

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/ChunkStream.cs

index 0a5c8946fbfb743b40b623e6eca0e3498d3623df..8439feee2a55ea4f172cb6961209066f99ca77aa 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-20 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * ChunkStream.cs: ignore chunk extensions when reading the chunk
+       size. Fixes bug #597556.
+
 2010-04-15 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * HttpWebRequest.cs: set content length to -1 on redirect. Reset
index 3e4c08f193010c04dfb05cfa6932b09e72b7f320..0edb422370b1d6c7e5d81bde4d48970bd4191cae 100644 (file)
@@ -230,8 +230,9 @@ namespace System.Net
                                        ThrowProtocolViolation ("Missing \\n");
 
                                try {
-                                       if (saved.Length > 0)
-                                               chunkSize = Int32.Parse (saved.ToString (), NumberStyles.HexNumber);
+                                       if (saved.Length > 0) {
+                                               chunkSize = Int32.Parse (RemoveChunkExtension (saved.ToString ()), NumberStyles.HexNumber);
+                                       }
                                } catch (Exception) {
                                        ThrowProtocolViolation ("Cannot parse chunk size.");
                                }
@@ -241,7 +242,7 @@ namespace System.Net
 
                        chunkRead = 0;
                        try {
-                               chunkSize = Int32.Parse (saved.ToString (), NumberStyles.HexNumber);
+                               chunkSize = Int32.Parse (RemoveChunkExtension (saved.ToString ()), NumberStyles.HexNumber);
                        } catch (Exception) {
                                ThrowProtocolViolation ("Cannot parse chunk size.");
                        }
@@ -254,6 +255,14 @@ namespace System.Net
                        return State.Body;
                }
 
+               static string RemoveChunkExtension (string input)
+               {
+                       int idx = input.IndexOf (';');
+                       if (idx == -1)
+                               return input;
+                       return input.Substring (0, idx);
+               }
+
                State ReadCRLF (byte [] buffer, ref int offset, int size)
                {
                        if (!sawCR) {
@@ -302,12 +311,14 @@ namespace System.Net
                                if (st > 0) {
                                        saved.Append (stString.Substring (0, saved.Length == 0? st-2: st));
                                        st = 0;
+                                       if (saved.Length > 4196)
+                                               ThrowProtocolViolation ("Error reading trailer (too long).");
                                }
                        }
 
                        if (st < 4) {
                                trailerState = st;
-                               if (offset <  size)
+                               if (offset < size)
                                        ThrowProtocolViolation ("Error reading trailer.");
 
                                return State.Trailer;