You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2008/10/07 21:33:57 UTC

svn commit: r702599 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java

Author: olegk
Date: Tue Oct  7 12:33:57 2008
New Revision: 702599

URL: http://svn.apache.org/viewvc?rev=702599&view=rev
Log:
HTTPCORE-173: Tolerate missing closing chunk if the chunk coded content is terminated by the end of stream (EOF) condition


Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java
    httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=702599&r1=702598&r2=702599&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Tue Oct  7 12:33:57 2008
@@ -1,6 +1,10 @@
 Changes since 4.0 Beta 2
 -------------------
 
+* [HTTPCORE-173] Tolerate missing closing chunk if the chunk coded content 
+  is terminated by the end of stream (EOF) condition.
+  Contributed by Oleg Kalnichevski <olegk at apache.org> 
+
 * [HTTPCORE-174] Position is incremented twice in ContentLengthInputStream#skip(long) 
   Contributed by Ildar Safarov <ildar.safarov at gmail.com> 
 

Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java?rev=702599&r1=702598&r2=702599&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java (original)
+++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java Tue Oct  7 12:33:57 2008
@@ -219,8 +219,7 @@
         this.buffer.clear();
         int i = this.in.readLine(this.buffer);
         if (i == -1) {
-            throw new MalformedChunkCodingException(
-                    "Chunked stream ended unexpectedly");
+            return 0;
         }
         int separator = this.buffer.indexOf(';');
         if (separator < 0) {

Modified: httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java?rev=702599&r1=702598&r2=702599&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java (original)
+++ httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java Tue Oct  7 12:33:57 2008
@@ -205,6 +205,17 @@
         }
     }
 
+    // Missing closing chunk
+    public void testChunkedInputStreamNoClosingChunk() throws IOException {
+        String s = "5\r\n01234\r\n";
+        ChunkedInputStream in = new ChunkedInputStream(
+                new SessionInputBufferMockup(
+                        EncodingUtils.getBytes(s, CONTENT_CHARSET)));
+        byte[] tmp = new byte[5];
+        assertEquals(5, in.read(tmp));
+        assertEquals(-1, in.read());
+    }
+
     // Missing \r\n at the end of the first chunk
     public void testCorruptChunkedInputStreamMissingCRLF() throws IOException {
         String s = "5\r\n012345\r\n56789\r\n0\r\n";
@@ -238,18 +249,6 @@
         }
     }
 
-    // Missing closing chunk
-    public void testCorruptChunkedInputStreamNoClosingChunk() throws IOException {
-        InputStream in = new ChunkedInputStream(
-                new SessionInputBufferMockup(new byte[] {}));
-        try {
-            in.read();
-            fail("MalformedChunkCodingException should have been thrown");
-        } catch(MalformedChunkCodingException e) {
-            /* expected exception */
-        }
-    }
-
     // Invalid chunk size
     public void testCorruptChunkedInputStreamInvalidSize() throws IOException {
         String s = "whatever\r\n01234\r\n5\r\n56789\r\n0\r\n";



Re: svn commit: r702599

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2008-10-07 at 20:51 +0100, sebb wrote:

...

> >
> >  Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java
> >  URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java?rev=702599&r1=702598&r2=702599&view=diff
> >  ==============================================================================
> >  --- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java (original)
> >  +++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java Tue Oct  7 12:33:57 2008
> >  @@ -219,8 +219,7 @@
> >          this.buffer.clear();
> >          int i = this.in.readLine(this.buffer);
> >          if (i == -1) {
> >  -            throw new MalformedChunkCodingException(
> >  -                    "Chunked stream ended unexpectedly");
> 
> Perhaps log a message here, as it is non-standard?
> 
> >  +            return 0;
> >          }
> >          int separator = this.buffer.indexOf(';');
> >          if (separator < 0) {
> >

HttpCore (for better or worse) does not have a dependency on a logging
toolkit. One possibility would be introducing a strict / lenient flag
and throwing MalformedChunkCodingException in the strict mode. However,
this cannot be done without breaking API compatibility with Android, not
until the 4.0.1 release. Besides, as it turned out the non-blocking
chunk content decoder in HttpCore NIO has always been lenient about the
missing closing chunk. At the very least, both implementations, blocking
and non-blocking, are consistent now.

I think it is a fairly harmless protocol violation, which probably can
be tolerated, as it should not result in any data corruption. 

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: svn commit: r702599 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java

Posted by sebb <se...@gmail.com>.
On 07/10/2008, olegk@apache.org <ol...@apache.org> wrote:
> Author: olegk
>  Date: Tue Oct  7 12:33:57 2008
>  New Revision: 702599
>
>  URL: http://svn.apache.org/viewvc?rev=702599&view=rev
>  Log:
>  HTTPCORE-173: Tolerate missing closing chunk if the chunk coded content is terminated by the end of stream (EOF) condition
>
>
>  Modified:
>     httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
>     httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java
>     httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java
>
>  Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
>  URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=702599&r1=702598&r2=702599&view=diff
>  ==============================================================================
>  --- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
>  +++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Tue Oct  7 12:33:57 2008
>  @@ -1,6 +1,10 @@
>   Changes since 4.0 Beta 2
>   -------------------
>
>  +* [HTTPCORE-173] Tolerate missing closing chunk if the chunk coded content
>  +  is terminated by the end of stream (EOF) condition.
>  +  Contributed by Oleg Kalnichevski <olegk at apache.org>
>  +
>   * [HTTPCORE-174] Position is incremented twice in ContentLengthInputStream#skip(long)
>    Contributed by Ildar Safarov <ildar.safarov at gmail.com>
>
>
>  Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java
>  URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java?rev=702599&r1=702598&r2=702599&view=diff
>  ==============================================================================
>  --- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java (original)
>  +++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java Tue Oct  7 12:33:57 2008
>  @@ -219,8 +219,7 @@
>          this.buffer.clear();
>          int i = this.in.readLine(this.buffer);
>          if (i == -1) {
>  -            throw new MalformedChunkCodingException(
>  -                    "Chunked stream ended unexpectedly");

Perhaps log a message here, as it is non-standard?

>  +            return 0;
>          }
>          int separator = this.buffer.indexOf(';');
>          if (separator < 0) {
>
>  Modified: httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java
>  URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java?rev=702599&r1=702598&r2=702599&view=diff
>  ==============================================================================
>  --- httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java (original)
>  +++ httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/impl/io/TestChunkCoding.java Tue Oct  7 12:33:57 2008
>  @@ -205,6 +205,17 @@
>          }
>      }
>
>  +    // Missing closing chunk
>  +    public void testChunkedInputStreamNoClosingChunk() throws IOException {
>  +        String s = "5\r\n01234\r\n";
>  +        ChunkedInputStream in = new ChunkedInputStream(
>  +                new SessionInputBufferMockup(
>  +                        EncodingUtils.getBytes(s, CONTENT_CHARSET)));
>  +        byte[] tmp = new byte[5];
>  +        assertEquals(5, in.read(tmp));
>  +        assertEquals(-1, in.read());
>  +    }
>  +
>      // Missing \r\n at the end of the first chunk
>      public void testCorruptChunkedInputStreamMissingCRLF() throws IOException {
>          String s = "5\r\n012345\r\n56789\r\n0\r\n";
>  @@ -238,18 +249,6 @@
>          }
>      }
>
>  -    // Missing closing chunk
>  -    public void testCorruptChunkedInputStreamNoClosingChunk() throws IOException {
>  -        InputStream in = new ChunkedInputStream(
>  -                new SessionInputBufferMockup(new byte[] {}));
>  -        try {
>  -            in.read();
>  -            fail("MalformedChunkCodingException should have been thrown");
>  -        } catch(MalformedChunkCodingException e) {
>  -            /* expected exception */
>  -        }
>  -    }
>  -
>      // Invalid chunk size
>      public void testCorruptChunkedInputStreamInvalidSize() throws IOException {
>          String s = "whatever\r\n01234\r\n5\r\n56789\r\n0\r\n";
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org