Apache Nutch is an extensible and scalable web crawler
NUTCH-954 Strict application of Content-Length limit for http protocols (Alexis Detreglode via jnioche)
Julien Nioche02a9bfff5db5
diff --git a/CHANGES.txt b/CHANGES.txtindex 097c83fd6..e920fd899 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogRelease 2.0 - Current Development+* NUTCH-954 Strict application of Content-Length limit for http protocols (Alexis Detreglode via jnioche)+* NUTCH-953 Fixed crawl command in Nutch script (Alexis Detreglode via jnioche)* NUTCH-950 DomainURLFilter throws NPE on bogus urls (Alexis Detreglode via jnioche)diff --git a/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java b/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.javaindex eb40d2b28..abf18f950 100644--- a/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java+++ b/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java@@ -223,12 +223,10 @@ public class HttpResponse implements Response {ByteArrayOutputStream out = new ByteArrayOutputStream(Http.BUFFER_SIZE);byte[] bytes = new byte[Http.BUFFER_SIZE];int length = 0; // read content- for (int i = in.read(bytes); i != -1; i = in.read(bytes)) {+ for (int i = in.read(bytes); i != -1 && length + i <= contentLength; i = in.read(bytes)) {out.write(bytes, 0, i);length += i;- if (length >= contentLength)- break;}content = out.toByteArray();}diff --git a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpResponse.java b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpResponse.javaindex 56687ad65..47d0a9f4b 100644--- a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpResponse.java+++ b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpResponse.java@@ -124,7 +124,7 @@ public class HttpResponse implements Response {int totalRead = 0;ByteArrayOutputStream out = new ByteArrayOutputStream();while ((bufferFilled = in.read(buffer, 0, buffer.length)) != -1- && totalRead < contentLength) {+ && totalRead + bufferFilled < contentLength) {totalRead += bufferFilled;out.write(buffer, 0, bufferFilled);}