mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-09-26 07:35:39 +00:00
Merge pull request #452 from internetarchive/handle-nulls-in-content-length-header
FetchHTTP: Handle null characters in the Content-Length header
This commit is contained in:
@@ -685,8 +685,17 @@ public class FetchHTTP extends Processor implements Lifecycle {
|
||||
|
||||
long contentLength = -1l;
|
||||
Header h = response.getLastHeader("content-length");
|
||||
if (h != null && h.getValue().trim().length()>0) {
|
||||
contentLength = Long.parseLong(h.getValue());
|
||||
if (h != null) {
|
||||
// browsers ignore everything after a null character and some buggy web servers rely on this
|
||||
String contentLengthHeader = StringUtils.substringBefore(h.getValue(), "\0").trim();
|
||||
if (!contentLengthHeader.isEmpty()) {
|
||||
try {
|
||||
contentLength = Long.parseLong(contentLengthHeader);
|
||||
} catch (NumberFormatException e) {
|
||||
cleanup(curi, e, "invalid content-length header", S_CONNECT_LOST);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (!req.request.isAborted()) {
|
||||
|
||||
Reference in New Issue
Block a user