fixed bug in gunzip
This commit is contained in:
parent
af39c78205
commit
43c41ddfb1
|
@ -46,6 +46,7 @@
|
|||
* fix uTP edge case where udp socket buffer fills up
|
||||
* fix nagle implementation in uTP
|
||||
|
||||
* fixed bug in gunzip
|
||||
* fix to use proxy settings when adding .torrent file from URL
|
||||
* fix resume file issue related to daylight savings time on windows
|
||||
* improve error checking in lazy_bdecode
|
||||
|
|
25
src/gzip.cpp
25
src/gzip.cpp
|
@ -150,6 +150,9 @@ namespace libtorrent
|
|||
// if needed
|
||||
boost::uint32_t destlen = 4096;
|
||||
int ret = 0;
|
||||
boost::uint32_t srclen = size - header_len;
|
||||
in += header_len;
|
||||
|
||||
do
|
||||
{
|
||||
TORRENT_TRY {
|
||||
|
@ -158,15 +161,13 @@ namespace libtorrent
|
|||
error = "out of memory";
|
||||
return true;
|
||||
}
|
||||
|
||||
boost::uint32_t srclen = size - header_len;
|
||||
in += header_len;
|
||||
|
||||
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) // 1: output space exhausted before completing inflate
|
||||
{
|
||||
if (destlen == maximum_size)
|
||||
{
|
||||
|
@ -177,9 +178,14 @@ namespace libtorrent
|
|||
destlen *= 2;
|
||||
if (destlen > maximum_size)
|
||||
destlen = maximum_size;
|
||||
continue;
|
||||
}
|
||||
} while (false);
|
||||
} while (ret == 1);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
error = "error while inflating data";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (destlen > buffer.size())
|
||||
{
|
||||
|
@ -189,11 +195,6 @@ namespace libtorrent
|
|||
|
||||
buffer.resize(destlen);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
error = "error while inflating data";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ feature launcher : none valgrind : composite ;
|
|||
feature.compose <launcher>valgrind : <testing.launcher>"valgrind --tool=memcheck -v --num-callers=20 --read-var-info=yes --track-origins=yes --error-exitcode=222 --suppressions=valgrind_suppressions.txt" <valgrind>on ;
|
||||
|
||||
test-suite libtorrent :
|
||||
[ run test_gzip.cpp ]
|
||||
[ run test_bitfield.cpp ]
|
||||
[ run test_torrent_info.cpp ]
|
||||
[ run test_time.cpp ]
|
||||
|
|
|
@ -99,7 +99,8 @@ EXTRA_DIST = Jamfile \
|
|||
cb.xml \
|
||||
mn.xml \
|
||||
pb.xml \
|
||||
upnp.xml
|
||||
upnp.xml \
|
||||
zeroes.gz
|
||||
|
||||
EXTRA_PROGRAMS = $(test_programs)
|
||||
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2014, Arvid Norberg
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "test.hpp"
|
||||
#include "libtorrent/gzip.hpp"
|
||||
#include "setup_transfer.hpp" // for load_file
|
||||
#include "file.hpp" // for combine_path
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
int test_main()
|
||||
{
|
||||
std::vector<char> zipped;
|
||||
error_code ec;
|
||||
int r = load_file(combine_path("..", "zeroes.gz"), zipped, ec, 1000000);
|
||||
if (ec) fprintf(stderr, "failed to open file: (%d) %s\n", ec.value()
|
||||
, ec.message().c_str());
|
||||
TEST_CHECK(!ec);
|
||||
|
||||
std::vector<char> inflated;
|
||||
std::string error;
|
||||
bool ret = inflate_gzip(&zipped[0], zipped.size(), inflated, 1000000, error);
|
||||
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "failed to unzip\n");
|
||||
}
|
||||
TEST_CHECK(ret == 0);
|
||||
TEST_CHECK(inflated.size() > 0);
|
||||
for (int i = 0; i < inflated.size(); ++i)
|
||||
TEST_EQUAL(inflated[i], 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue