Browse Source

handle compression method field

pull/117/head
orignal 10 years ago
parent
commit
9ce56eb95f
  1. 20
      Reseed.cpp

20
Reseed.cpp

@ -217,7 +217,11 @@ namespace data
if (signature == headerSignature) if (signature == headerSignature)
{ {
// next local file // next local file
s.seekg (14, std::ios::cur); // skip field we don't care about s.seekg (4, std::ios::cur); // skip fields we don't care about
uint16_t compressionMethod;
s.read ((char *)&compressionMethod, 2);
compressionMethod = le16toh (compressionMethod);
s.seekg (8, std::ios::cur); // skip fields we don't care about
uint32_t compressedSize, uncompressedSize; uint32_t compressedSize, uncompressedSize;
s.read ((char *)&compressedSize, 4); s.read ((char *)&compressedSize, 4);
compressedSize = le32toh (compressedSize); compressedSize = le32toh (compressedSize);
@ -225,9 +229,9 @@ namespace data
uncompressedSize = le32toh (uncompressedSize); uncompressedSize = le32toh (uncompressedSize);
uint16_t fileNameLength, extraFieldLength; uint16_t fileNameLength, extraFieldLength;
s.read ((char *)&fileNameLength, 2); s.read ((char *)&fileNameLength, 2);
fileNameLength = le32toh (fileNameLength); fileNameLength = le16toh (fileNameLength);
s.read ((char *)&extraFieldLength, 2); s.read ((char *)&extraFieldLength, 2);
extraFieldLength = le32toh (extraFieldLength); extraFieldLength = le16toh (extraFieldLength);
char localFileName[255]; char localFileName[255];
s.read (localFileName, fileNameLength); s.read (localFileName, fileNameLength);
localFileName[fileNameLength] = 0; localFileName[fileNameLength] = 0;
@ -236,9 +240,10 @@ namespace data
uint8_t * compressed = new uint8_t[compressedSize]; uint8_t * compressed = new uint8_t[compressedSize];
s.read ((char *)compressed, compressedSize); s.read ((char *)compressed, compressedSize);
if (compressionMethod) // we assume Deflate
{
CryptoPP::Inflator decompressor; CryptoPP::Inflator decompressor;
decompressor.Put (compressed, compressedSize); decompressor.Put (compressed, compressedSize);
delete[] compressed;
size_t len = decompressor.MaxRetrievable (); size_t len = decompressor.MaxRetrievable ();
if (len <= uncompressedSize) if (len <= uncompressedSize)
{ {
@ -251,6 +256,13 @@ namespace data
else else
LogPrint (eLogError, "Actual uncompressed size ", decompressor.MaxRetrievable (), " exceed ", uncompressedSize, " from header"); LogPrint (eLogError, "Actual uncompressed size ", decompressor.MaxRetrievable (), " exceed ", uncompressedSize, " from header");
} }
else // no compression
{
i2p::data::netdb.AddRouterInfo (compressed, compressedSize);
numFiles++;
}
delete[] compressed;
}
else else
break; // no more files break; // no more files
size_t end = s.tellg (); size_t end = s.tellg ();

Loading…
Cancel
Save