From 83b991922e47e6a54fca7f7e6c413b1c0454adae Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Thu, 5 Sep 2019 17:18:36 -0700 Subject: [PATCH] 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 Differential Revision: D17133849 fbshipit-source-id: bb7262d308e5b2503c400b180edc252668df0ef0 --- db/db_encryption_test.cc | 28 ++++++++++++++++++++++++++++ env/env_encryption.cc | 2 -- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/db/db_encryption_test.cc b/db/db_encryption_test.cc index 4ddc11986..bc7274465 100644 --- a/db/db_encryption_test.cc +++ b/db/db_encryption_test.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; + status = defaultEnv->NewWritableFile(filePath, &writableFile, envOptions); + ASSERT_OK(status); + } + + std::unique_ptr 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 diff --git a/env/env_encryption.cc b/env/env_encryption.cc index 6be2137ed..b7095c0f5 100644 --- a/env/env_encryption.cc +++ b/env/env_encryption.cc @@ -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;