From ed2b537cbdab358b5bab6a39d34f67972129583e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 26 Aug 2016 16:39:04 +0200 Subject: net.http.parser: Fix missing buffer length adjustment when parsing chunked streams --- net/http/parser.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'net') diff --git a/net/http/parser.lua b/net/http/parser.lua index fabbddad..493ff3a9 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -150,6 +150,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) elseif buflen - chunk_start - 2 >= chunk_size then -- we have a chunk packet.body = packet.body..buf:sub(chunk_start, chunk_start + (chunk_size-1)); buf = buf:sub(chunk_start + chunk_size + 2); + buflen = buflen - (chunk_start + chunk_size + 2 - 1); chunk_size, chunk_start = nil, nil; else -- Partial chunk remaining break; -- cgit v1.2.3 From a206b98c0ebebc15626b55c83e66e64cfab7c673 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 26 Aug 2016 16:42:14 +0200 Subject: net.http.parser: Don't collapse buffer when expecting a chunk and not enough data has been received --- net/http/parser.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'net') diff --git a/net/http/parser.lua b/net/http/parser.lua index 493ff3a9..96d32ec8 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -134,6 +134,9 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) if state then -- read body if client then if chunked then + if chunk_start and buflen - chunk_start - 2 < chunk_size then + return; + end -- not enough data if buftable then buf, buftable = t_concat(buf), false; end if not buf:find("\r\n", nil, true) then return; -- cgit v1.2.3