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

correct CRC32 verification at big endian CPU

This commit is contained in:
orignal 2015-01-19 14:30:30 -05:00
parent 027c43c99c
commit e09da5cb54

View File

@ -266,9 +266,9 @@ namespace data
s.read ((char *)&compressionMethod, 2); s.read ((char *)&compressionMethod, 2);
compressionMethod = le16toh (compressionMethod); compressionMethod = le16toh (compressionMethod);
s.seekg (4, std::ios::cur); // skip fields we don't care about s.seekg (4, std::ios::cur); // skip fields we don't care about
uint32_t crc32, compressedSize, uncompressedSize; uint32_t compressedSize, uncompressedSize;
s.read ((char *)&crc32, 4); uint8_t crc32[4];
crc32 = le32toh (crc32); s.read ((char *)crc32, 4);
s.read ((char *)&compressedSize, 4); s.read ((char *)&compressedSize, 4);
compressedSize = le32toh (compressedSize); compressedSize = le32toh (compressedSize);
s.read ((char *)&uncompressedSize, 4); s.read ((char *)&uncompressedSize, 4);
@ -292,8 +292,7 @@ namespace data
return numFiles; return numFiles;
} }
s.read ((char *)&crc32, 4); s.read ((char *)crc32, 4);
crc32 = le32toh (crc32);
s.read ((char *)&compressedSize, 4); s.read ((char *)&compressedSize, 4);
compressedSize = le32toh (compressedSize) + 4; // ??? we must consider signature as part of compressed data compressedSize = le32toh (compressedSize) + 4; // ??? we must consider signature as part of compressed data
s.read ((char *)&uncompressedSize, 4); s.read ((char *)&uncompressedSize, 4);
@ -321,7 +320,7 @@ namespace data
{ {
uint8_t * uncompressed = new uint8_t[uncompressedSize]; uint8_t * uncompressed = new uint8_t[uncompressedSize];
decompressor.Get (uncompressed, uncompressedSize); decompressor.Get (uncompressed, uncompressedSize);
if (CryptoPP::CRC32().VerifyDigest ((uint8_t *)&crc32, uncompressed, uncompressedSize)) if (CryptoPP::CRC32().VerifyDigest (crc32, uncompressed, uncompressedSize))
{ {
i2p::data::netdb.AddRouterInfo (uncompressed, uncompressedSize); i2p::data::netdb.AddRouterInfo (uncompressed, uncompressedSize);
numFiles++; numFiles++;