mirror of https://gitee.com/bigwinds/arangodb
this addresses an issue described in ES-260, and is a forward-port of… (#8696)
This commit is contained in:
parent
6b9b9b0946
commit
675b006ebc
|
@ -8,6 +8,7 @@
|
|||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
#include "rocksdb/env_encryption.h"
|
||||
#include "util/aligned_buffer.h"
|
||||
|
@ -733,6 +734,8 @@ Status BlockAccessCipherStream::Decrypt(uint64_t fileOffset, char *data, size_t
|
|||
std::string scratch;
|
||||
AllocateScratch(scratch);
|
||||
|
||||
assert(fileOffset < dataSize);
|
||||
|
||||
// Decrypt individual blocks.
|
||||
while (1) {
|
||||
char *block = data;
|
||||
|
@ -756,6 +759,14 @@ Status BlockAccessCipherStream::Decrypt(uint64_t fileOffset, char *data, size_t
|
|||
// Copy decrypted data back to `data`.
|
||||
memmove(data, block + blockOffset, n);
|
||||
}
|
||||
|
||||
// Simply decrementing dataSize by n could cause it to underflow,
|
||||
// which will very likely make it read over the original bounds later
|
||||
assert(dataSize >= n);
|
||||
if (dataSize < n) {
|
||||
return Status::Corruption("Cannot decrypt data at given offset");
|
||||
}
|
||||
|
||||
dataSize -= n;
|
||||
if (dataSize == 0) {
|
||||
return Status::OK();
|
||||
|
@ -882,6 +893,13 @@ Status CTREncryptionProvider::CreateCipherStream(
|
|||
Slice iv;
|
||||
decodeCTRParameters(prefix.data(), blockSize, initialCounter, iv);
|
||||
|
||||
// If the prefix is smaller than twice the block size, we would below read a
|
||||
// very large chunk of the file (and very likely read over the bounds)
|
||||
assert(prefix.size() >= 2 * blockSize);
|
||||
if (prefix.size() < 2 * blockSize) {
|
||||
return Status::Corruption("Unable to read from file " + fname + ": read attempt would read beyond file bounds");
|
||||
}
|
||||
|
||||
// Decrypt the encrypted part of the prefix, starting from block 2 (block 0, 1 with initial counter & IV are unencrypted)
|
||||
CTRCipherStream cipherStream(cipher_, iv.data(), initialCounter);
|
||||
auto status = cipherStream.Decrypt(0, (char*)prefix.data() + (2 * blockSize), prefix.size() - (2 * blockSize));
|
||||
|
|
|
@ -102,7 +102,7 @@ using namespace arangodb::application_features;
|
|||
using namespace arangodb::options;
|
||||
|
||||
namespace arangodb {
|
||||
|
||||
|
||||
std::string const RocksDBEngine::EngineName("rocksdb");
|
||||
std::string const RocksDBEngine::FeatureName("RocksDBEngine");
|
||||
|
||||
|
|
|
@ -346,6 +346,7 @@ class RocksDBEngine final : public StorageEngine {
|
|||
void prepareEnterprise();
|
||||
void startEnterprise();
|
||||
void configureEnterpriseRocksDBOptions(rocksdb::Options& options);
|
||||
void validateJournalFiles() const;
|
||||
|
||||
enterprise::RocksDBEngineEEData _eeData;
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue