hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r705886 - in /httpcomponents/oac.hc3x/trunk: release_notes.txt src/java/org/apache/commons/httpclient/ChunkedInputStream.java src/test/org/apache/commons/httpclient/TestStreams.java
Date Sat, 18 Oct 2008 14:29:37 GMT
Author: olegk
Date: Sat Oct 18 07:29:36 2008
New Revision: 705886

URL: http://svn.apache.org/viewvc?rev=705886&view=rev
Log:
[HTTPCLIENT-804: ChunkedInputStream no longer accepts truncated chunks as valid input

Modified:
    httpcomponents/oac.hc3x/trunk/release_notes.txt
    httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/ChunkedInputStream.java
    httpcomponents/oac.hc3x/trunk/src/test/org/apache/commons/httpclient/TestStreams.java

Modified: httpcomponents/oac.hc3x/trunk/release_notes.txt
URL: http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/release_notes.txt?rev=705886&r1=705885&r2=705886&view=diff
==============================================================================
--- httpcomponents/oac.hc3x/trunk/release_notes.txt (original)
+++ httpcomponents/oac.hc3x/trunk/release_notes.txt Sat Oct 18 07:29:36 2008
@@ -1,5 +1,9 @@
 Changes since 3.1 Final
 
+* [HTTPCLIENT-804] - ChunkedInputStream no longer accepts truncated chunks 
+  as valid input.
+           Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * HttpConnection#isResponseAvailable(int) changed to return false if the
   connection is closed instead of throwing java.lang.IllegalStateException
            Contributed by Oleg Kalnichevski <olegk at apache.org>

Modified: httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/ChunkedInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/ChunkedInputStream.java?rev=705886&r1=705885&r2=705886&view=diff
==============================================================================
--- httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/ChunkedInputStream.java
(original)
+++ httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/ChunkedInputStream.java
Sat Oct 18 07:29:36 2008
@@ -148,8 +148,11 @@
                 return -1;
             }
         }
-        pos++;
-        return in.read();
+        int b = in.read();
+        if (b != -1) {
+            pos++;
+        }
+        return b;
     }
 
     /**
@@ -179,9 +182,13 @@
             }
         }
         len = Math.min(len, chunkSize - pos);
-        int count = in.read(b, off, len);
-        pos += count;
-        return count;
+        int bytesRead = in.read(b, off, len);
+        if (bytesRead != -1) {
+            pos += bytesRead;
+            return bytesRead;
+        } else {
+            throw new IOException("Truncated chunk");
+        }
     }
 
     /**

Modified: httpcomponents/oac.hc3x/trunk/src/test/org/apache/commons/httpclient/TestStreams.java
URL: http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/test/org/apache/commons/httpclient/TestStreams.java?rev=705886&r1=705885&r2=705886&view=diff
==============================================================================
--- httpcomponents/oac.hc3x/trunk/src/test/org/apache/commons/httpclient/TestStreams.java
(original)
+++ httpcomponents/oac.hc3x/trunk/src/test/org/apache/commons/httpclient/TestStreams.java
Sat Oct 18 07:29:36 2008
@@ -112,6 +112,23 @@
         }
     }
 
+    public void testCorruptChunkedInputStream2() throws IOException {
+        //truncated chunk
+        String corrupInput = "3\r\n11";
+        HttpMethod method = new FakeHttpMethod();
+
+        InputStream in = new ChunkedInputStream(new ByteArrayInputStream(
+            EncodingUtil.getBytes(corrupInput, CONTENT_CHARSET)), method);
+        byte[] buffer = new byte[300];
+        assertEquals(2, in.read(buffer));
+        try {
+            in.read(buffer);
+            fail("Should have thrown exception");
+        } catch(IOException e) {
+            /* expected exception */
+        }
+    }
+
     public void testEmptyChunkedInputStream() throws IOException {
         String input = "0\r\n";
         HttpMethod method = new FakeHttpMethod();



Mime
View raw message