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 2017/05/09 20:02:36 UTC
[07/34] httpcomponents-core git commit: Code consistency: tolerate
lone LF at the end of the chunk
Code consistency: tolerate lone LF at the end of the chunk
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.3.x@1565592 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/82017984
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/82017984
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/82017984
Branch: refs/heads/4.3.x
Commit: 820179842f08c64fffa2ae452f5f32e05f287778
Parents: ad88d9f
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Fri Feb 7 09:19:14 2014 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Fri Feb 7 09:19:14 2014 +0000
----------------------------------------------------------------------
.../http/impl/nio/codecs/ChunkDecoder.java | 25 ++++++++++----------
.../http/impl/nio/codecs/TestChunkDecoder.java | 24 ++++++++++++++++++-
2 files changed, 36 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/82017984/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
index 31637e8..a7ccda8 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
@@ -41,7 +41,6 @@ import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.message.BufferedHeader;
import org.apache.http.nio.reactor.SessionInputBuffer;
-import org.apache.http.protocol.HTTP;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
@@ -84,22 +83,24 @@ public class ChunkDecoder extends AbstractContentDecoder {
}
private void readChunkHead() throws IOException {
- if (this.endOfChunk) {
- if (this.buffer.length() < 2) {
- return;
- }
- final int cr = this.buffer.read();
- final int lf = this.buffer.read();
- if (cr != HTTP.CR || lf != HTTP.LF) {
- throw new MalformedChunkCodingException("CRLF expected at end of chunk");
- }
- this.endOfChunk = false;
- }
if (this.lineBuf == null) {
this.lineBuf = new CharArrayBuffer(32);
} else {
this.lineBuf.clear();
}
+ if (this.endOfChunk) {
+ if (this.buffer.readLine(this.lineBuf, this.endOfStream)) {
+ if (!this.lineBuf.isEmpty()) {
+ throw new MalformedChunkCodingException("CRLF expected at end of chunk");
+ }
+ } else {
+ if (this.buffer.length() > 2) {
+ throw new MalformedChunkCodingException("CRLF expected at end of chunk");
+ }
+ return;
+ }
+ this.endOfChunk = false;
+ }
if (this.buffer.readLine(this.lineBuf, this.endOfStream)) {
int separator = this.lineBuf.indexOf(';');
if (separator < 0) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/82017984/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java b/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
index 008b1e8..3087da3 100644
--- a/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
+++ b/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
@@ -143,6 +143,28 @@ public class TestChunkDecoder {
}
@Test
+ public void testMalformedChunk() throws Exception {
+ final String s = "5\r\n01234----------------------------------------------------------" +
+ "-----------------------------------------------------------------------------" +
+ "-----------------------------------------------------------------------------";
+ final ReadableByteChannel channel = new ReadableByteChannelMock(
+ new String[] {s}, Consts.ASCII);
+
+ final SessionInputBuffer inbuf = new SessionInputBufferImpl(32, 32, Consts.ASCII);
+ final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
+ final ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
+
+ final ByteBuffer dst = ByteBuffer.allocate(1024);
+
+ try {
+ decoder.read(dst);
+ Assert.fail("MalformedChunkCodingException should have been thrown");
+ } catch (final MalformedChunkCodingException ex) {
+ // expected
+ }
+ }
+
+ @Test
public void testIncompleteChunkDecoding() throws Exception {
final String[] chunks = {
"10;",
@@ -211,7 +233,7 @@ public class TestChunkDecoder {
@Test
public void testMalformedChunkEndingDecoding() throws Exception {
- final String s = "5\r\n01234\r\n5\r\n56789\n\r6\r\nabcdef\r\n0\r\n\r\n";
+ final String s = "5\r\n01234\r\n5\r\n56789\r\r6\r\nabcdef\r\n0\r\n\r\n";
final ReadableByteChannel channel = new ReadableByteChannelMock(
new String[] {s}, Consts.ASCII);