1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-22 08:14:15 +00:00

check for data descriptor flag

This commit is contained in:
orignal 2014-12-12 10:34:50 -05:00
parent 56a95fa9b5
commit 0e935a3511
2 changed files with 17 additions and 9 deletions

View File

@ -149,7 +149,7 @@ namespace data
} }
} }
int ProcessSU3File (const char * filename) int Reseeder::ProcessSU3File (const char * filename)
{ {
std::ifstream s(filename, std::ifstream::binary); std::ifstream s(filename, std::ifstream::binary);
if (s.is_open ()) if (s.is_open ())
@ -162,10 +162,10 @@ namespace data
} }
const char SU3_MAGIC_NUMBER[]="I2Psu3"; const char SU3_MAGIC_NUMBER[]="I2Psu3";
int ProcessSU3Stream (std::istream& s) const uint32_t ZIP_HEADER_SIGNATURE = 0x04034B50;
const uint16_t ZIP_BIT_FLAG_DATA_DESCRIPTOR = 0x0008;
int Reseeder::ProcessSU3Stream (std::istream& s)
{ {
static uint32_t headerSignature = htole32 (0x04034B50);
char magicNumber[7]; char magicNumber[7];
s.read (magicNumber, 7); // magic number and zero byte 6 s.read (magicNumber, 7); // magic number and zero byte 6
if (strcmp (magicNumber, SU3_MAGIC_NUMBER)) if (strcmp (magicNumber, SU3_MAGIC_NUMBER))
@ -217,10 +217,19 @@ namespace data
{ {
uint32_t signature; uint32_t signature;
s.read ((char *)&signature, 4); s.read ((char *)&signature, 4);
if (signature == headerSignature) signature = le32toh (signature);
if (signature == ZIP_HEADER_SIGNATURE)
{ {
// next local file // next local file
s.seekg (4, std::ios::cur); // skip fields we don't care about s.seekg (2, std::ios::cur); // version
uint16_t bitFlag;
s.read ((char *)&bitFlag, 2);
bitFlag = le16toh (bitFlag);
if (bitFlag & ZIP_BIT_FLAG_DATA_DESCRIPTOR)
{
LogPrint (eLogError, "SU3 archives with data descriptors are not supported yet");
return numFiles;
}
uint16_t compressionMethod; uint16_t compressionMethod;
s.read ((char *)&compressionMethod, 2); s.read ((char *)&compressionMethod, 2);
compressionMethod = le16toh (compressionMethod); compressionMethod = le16toh (compressionMethod);

View File

@ -22,10 +22,9 @@ namespace data
private: private:
int ReseedFromSU3 (const std::string& host); int ReseedFromSU3 (const std::string& host);
};
int ProcessSU3File (const char * filename); int ProcessSU3File (const char * filename);
int ProcessSU3Stream (std::istream& s); int ProcessSU3Stream (std::istream& s);
};
} }
} }