Fix encrypted

This commit is contained in:
kssenii 2022-05-13 13:22:29 +02:00
parent cde5cecc4d
commit 5b9b053c61
2 changed files with 8 additions and 0 deletions

View File

@ -287,6 +287,7 @@ std::unique_ptr<ReadBufferFromFileBase> DiskEncrypted::readFile(
{ {
auto wrapped_path = wrappedPath(path); auto wrapped_path = wrappedPath(path);
auto buffer = delegate->readFile(wrapped_path, settings, read_hint, file_size); auto buffer = delegate->readFile(wrapped_path, settings, read_hint, file_size);
buffer->setReadUntilPosition(FileEncryption::Header::kSize);
if (buffer->eof()) if (buffer->eof())
{ {
/// File is empty, that's a normal case, see DiskEncrypted::truncateFile(). /// File is empty, that's a normal case, see DiskEncrypted::truncateFile().
@ -296,6 +297,7 @@ std::unique_ptr<ReadBufferFromFileBase> DiskEncrypted::readFile(
auto encryption_settings = current_settings.get(); auto encryption_settings = current_settings.get();
FileEncryption::Header header = readHeader(*buffer); FileEncryption::Header header = readHeader(*buffer);
String key = getKey(path, header, *encryption_settings); String key = getKey(path, header, *encryption_settings);
buffer->setReadUntilPosition(0); /// Reset position back.
return std::make_unique<ReadBufferFromEncryptedFile>(settings.local_fs_buffer_size, std::move(buffer), key, header); return std::make_unique<ReadBufferFromEncryptedFile>(settings.local_fs_buffer_size, std::move(buffer), key, header);
} }

View File

@ -142,6 +142,12 @@ void AsynchronousReadIndirectBufferFromRemoteFS::setReadUntilPosition(size_t pos
prefetch_future = {}; prefetch_future = {};
} }
if (position == 0)
{
read_until_position.reset();
return;
}
if (position > read_until_position) if (position > read_until_position)
{ {
read_until_position = position; read_until_position = position;