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 2016/12/09 16:48:26 UTC

svn commit: r1773437 - in /httpcomponents/httpcore/trunk/httpcore5-h2/src: main/java/org/apache/hc/core5/http2/hpack/HPackDecoder.java test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java

Author: olegk
Date: Fri Dec  9 16:48:26 2016
New Revision: 1773437

URL: http://svn.apache.org/viewvc?rev=1773437&view=rev
Log:
Fixed bug in HPackDecoder#decodePlainString caused by incorrect string deliniation

Modified:
    httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/hpack/HPackDecoder.java
    httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java

Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/hpack/HPackDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/hpack/HPackDecoder.java?rev=1773437&r1=1773436&r2=1773437&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/hpack/HPackDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/hpack/HPackDecoder.java Fri Dec  9 16:48:26 2016
@@ -120,7 +120,7 @@ public final class HPackDecoder {
             buffer.append(b, off, strLen);
             src.position(off + strLen);
         } else {
-            while (src.hasRemaining()) {
+            for (int i = 0; i < strLen; i++) {
                 buffer.append(src.get());
             }
         }

Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java?rev=1773437&r1=1773436&r2=1773437&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/hpack/TestHPackCoding.java Fri Dec  9 16:48:26 2016
@@ -134,6 +134,31 @@ public class TestHPackCoding {
         Assert.assertFalse("Decoding completed", src.hasRemaining());
     }
 
+    @Test
+    public void testPlainStringDecodingRemainingContent() throws Exception {
+
+        final ByteBuffer src = createByteBuffer(
+                0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x2d, 0x6b, 0x65, 0x79, 0x01, 0x01, 0x01, 0x01);
+
+        final ByteArrayBuffer buffer = new ByteArrayBuffer(16);
+        HPackDecoder.decodePlainString(buffer, src);
+        Assert.assertEquals("custom-key", new String(buffer.array(), 0, buffer.length(), StandardCharsets.US_ASCII));
+        Assert.assertEquals(4, src.remaining());
+    }
+
+    @Test
+    public void testPlainStringDecodingReadOnly() throws Exception {
+
+        final ByteBuffer src = createByteBuffer(
+                0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x2d, 0x6b, 0x65, 0x79, 0x50, 0x50, 0x50, 0x50);
+
+        final ByteBuffer srcRO = src.asReadOnlyBuffer();
+        final ByteArrayBuffer buffer = new ByteArrayBuffer(16);
+        HPackDecoder.decodePlainString(buffer, srcRO);
+        Assert.assertEquals("custom-key", new String(buffer.array(), 0, buffer.length(), StandardCharsets.US_ASCII));
+        Assert.assertEquals(4, srcRO.remaining());
+    }
+
     @Test(expected = HPackException.class)
     public void testPlainStringDecodingTruncated() throws Exception {