Skip to content

Commit

Permalink
Reseed: append null byte to compressed payloads.
Browse files Browse the repository at this point in the history
  • Loading branch information
anonimal committed Mar 1, 2016
1 parent 1a5af3a commit 8c61f5d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/core/Reseed.cpp
Expand Up @@ -248,11 +248,15 @@ int Reseeder::ProcessSU3Stream(
LogPrint(eLogWarning, "Unexpected size 0. Skipped");
continue;
}
uint8_t* compressed = new uint8_t[compressedSize];
s.read(reinterpret_cast<char *>(compressed), compressedSize);
if (compressionMethod) { // we assume Deflate
std::vector<uint8_t> compressed(compressedSize);
s.read(reinterpret_cast<char *>(compressed.data()), compressed.size());
// TODO(anonimal): don't assume deflate.
if (compressionMethod) {
CryptoPP::Inflator decompressor;
decompressor.Put(compressed, compressedSize);
// For the reasoning behind why we need to append a null byte, see #141.
decompressor.Put(
compressed.data() + '\0',
compressed.size() + 1);
decompressor.MessageEnd();
if (decompressor.MaxRetrievable() <= uncompressedSize) {
uint8_t* uncompressed = new uint8_t[uncompressedSize];
Expand All @@ -277,11 +281,10 @@ int Reseeder::ProcessSU3Stream(
" exceeds ", uncompressedSize, " from header");
return -1;
}
} else { // no compression
i2p::data::netdb.AddRouterInfo(compressed, compressedSize);
} else { // Contained, but not compressed
i2p::data::netdb.AddRouterInfo(compressed.data(), compressed.size());
numFiles++;
}
delete[] compressed;
if (bitFlag & ZIP_BIT_FLAG_DATA_DESCRIPTOR)
// skip data descriptor section if presented (12 = 16 - 4)
s.seekg(12, std::ios::cur);
Expand Down

2 comments on commit 8c61f5d

@noloader
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crypto++ cleared the issue at Commit 60a68714dc3587e9.

The bad code is in 5.6.3 only. It is not present in 5.6.2; and it won't be present in 5.6.4 and above.

I am to blame for the break. My apologies for causing the break.

@anonimal
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noloader No worries! Thanks for clearing that up 😄

Please sign in to comment.