Fix EncryptedEnv assert (#5735)

Summary:
Fixes https://github.com/facebook/rocksdb/issues/5734. By reading the code the assert don't quite make sense to me, since `dataSize` and `fileOffset` has no correlation. But my knowledge about `EncryptedEnv` is very limited.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5735

Test Plan:
run `ENCRYPTED_ENV=1 ./db_encryption_test`

Signed-off-by: Yi Wu <yiwu@pingcap.com>

Differential Revision: D17133849

fbshipit-source-id: bb7262d308e5b2503c400b180edc252668df0ef0
main
Yi Wu 5 years ago committed by Facebook Github Bot
parent 43a5cdb58c
commit 83b991922e
  1. 28
      db/db_encryption_test.cc
  2. 2
      env/env_encryption.cc

@ -83,6 +83,34 @@ TEST_F(DBEncryptionTest, CheckEncrypted) {
}
}
TEST_F(DBEncryptionTest, ReadEmptyFile) {
auto defaultEnv = Env::Default();
// create empty file for reading it back in later
auto envOptions = EnvOptions(CurrentOptions());
auto filePath = dbname_ + "/empty.empty";
Status status;
{
std::unique_ptr<WritableFile> writableFile;
status = defaultEnv->NewWritableFile(filePath, &writableFile, envOptions);
ASSERT_OK(status);
}
std::unique_ptr<SequentialFile> seqFile;
status = defaultEnv->NewSequentialFile(filePath, &seqFile, envOptions);
ASSERT_OK(status);
std::string scratch;
Slice data;
// reading back 16 bytes from the empty file shouldn't trigger an assertion.
// it should just work and return an empty string
status = seqFile->Read(16, &data, (char*)scratch.data());
ASSERT_OK(status);
ASSERT_TRUE(data.empty());
}
#endif // ROCKSDB_LITE
} // namespace rocksdb

@ -745,8 +745,6 @@ 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;

Loading…
Cancel
Save