From 0f0fb8240793e3bb27b10f3219a6051980c66d08 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 6 Dec 2009 02:38:10 +0000 Subject: [PATCH] http_connection gzip fix --- src/gzip.cpp | 2 +- src/http_connection.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gzip.cpp b/src/gzip.cpp index a7c60f261..2058bedaa 100644 --- a/src/gzip.cpp +++ b/src/gzip.cpp @@ -65,7 +65,7 @@ namespace libtorrent const int total_size = size; // The zip header cannot be shorter than 10 bytes - if (size < 10) return -1; + if (size < 10 || buf == 0) return -1; // check the magic header of gzip if ((buffer[0] != GZIP_MAGIC0) || (buffer[1] != GZIP_MAGIC1)) return -1; diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 2f35ed00c..2f3cccaa5 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -484,7 +484,7 @@ void http_connection::callback(error_code const& e, char const* data, int size) if (m_bottled && m_parser.header_finished()) { std::string const& encoding = m_parser.header("content-encoding"); - if (encoding == "gzip" || encoding == "x-gzip") + if ((encoding == "gzip" || encoding == "x-gzip") && size > 0 && data) { std::string error; if (inflate_gzip(data, size, buf, max_bottled_buffer, error))