From 0e935a35114347fc8f189e7716b5dde719c156e2 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 12 Dec 2014 10:34:50 -0500 Subject: [PATCH] check for data descriptor flag --- Reseed.cpp | 21 +++++++++++++++------ Reseed.h | 5 ++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Reseed.cpp b/Reseed.cpp index 057db441..54c58652 100644 --- a/Reseed.cpp +++ b/Reseed.cpp @@ -149,7 +149,7 @@ namespace data } } - int ProcessSU3File (const char * filename) + int Reseeder::ProcessSU3File (const char * filename) { std::ifstream s(filename, std::ifstream::binary); if (s.is_open ()) @@ -162,10 +162,10 @@ namespace data } 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]; s.read (magicNumber, 7); // magic number and zero byte 6 if (strcmp (magicNumber, SU3_MAGIC_NUMBER)) @@ -217,10 +217,19 @@ namespace data { uint32_t signature; s.read ((char *)&signature, 4); - if (signature == headerSignature) + signature = le32toh (signature); + if (signature == ZIP_HEADER_SIGNATURE) { // 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; s.read ((char *)&compressionMethod, 2); compressionMethod = le16toh (compressionMethod); diff --git a/Reseed.h b/Reseed.h index 97257fab..7b6cdf8f 100644 --- a/Reseed.h +++ b/Reseed.h @@ -22,10 +22,9 @@ namespace data private: int ReseedFromSU3 (const std::string& host); + int ProcessSU3File (const char * filename); + int ProcessSU3Stream (std::istream& s); }; - - int ProcessSU3File (const char * filename); - int ProcessSU3Stream (std::istream& s); } }