merged fix from RC_0_16

This commit is contained in:
Arvid Norberg 2014-03-17 03:09:19 +00:00
parent 6ac8b9e006
commit c0b0f3d108
2 changed files with 38 additions and 10 deletions

View File

@ -43,6 +43,7 @@
* fix uTP edge case where udp socket buffer fills up * fix uTP edge case where udp socket buffer fills up
* fix nagle implementation in uTP * fix nagle implementation in uTP
* improve error handling in http gunzip
* fix debug logging for banning web seeds * fix debug logging for banning web seeds
* improve support for de-selected files in full allocation mode * improve support for de-selected files in full allocation mode
* fix dht_bootstrap_alert being posted * fix dht_bootstrap_alert being posted

View File

@ -129,6 +129,7 @@ namespace libtorrent
return total_size - size; return total_size - size;
} }
// TODO: 2 it would be nice to use proper error handling here
bool inflate_gzip( bool inflate_gzip(
char const* in char const* in
, int size , int size
@ -145,21 +146,47 @@ namespace libtorrent
return true; return true;
} }
// start off with one kilobyte and grow // start off with 4 kilobytes and grow
// if needed // if needed
buffer.resize(maximum_size); boost::uint32_t destlen = 4096;
int ret = 0;
do
{
TORRENT_TRY {
buffer.resize(destlen);
} TORRENT_CATCH(std::exception& e) {
error = "out of memory";
return true;
}
boost::uint32_t destlen = buffer.size();
boost::uint32_t srclen = size - header_len; boost::uint32_t srclen = size - header_len;
in += header_len; in += header_len;
int ret = puff((unsigned char*)&buffer[0], &destlen, (unsigned char*)in, &srclen); ret = puff((unsigned char*)&buffer[0], &destlen, (unsigned char*)in, &srclen);
// if the destination buffer wasn't large enough, double its
// size and try again. Unless it's already at its max, in which
// case we fail
if (ret == -1) if (ret == -1)
{
if (destlen == maximum_size)
{ {
error = "inflated data too big"; error = "inflated data too big";
return true; return true;
} }
destlen *= 2;
if (destlen > maximum_size)
destlen = maximum_size;
continue;
}
} while (false);
if (destlen > buffer.size())
{
error = "internal gzip error";
return true;
}
buffer.resize(destlen); buffer.resize(destlen);
if (ret != 0) if (ret != 0)