diff --git a/lib/private/files/stream/encryption.php b/lib/private/files/stream/encryption.php
index fcc9984500dba9bfb92be43dec00d3daa5611a3e..fdfe73d99c53b94214897c0938fe768747f678bc 100644
--- a/lib/private/files/stream/encryption.php
+++ b/lib/private/files/stream/encryption.php
@@ -362,8 +362,11 @@ class Encryption extends Wrapper {
 		$newFilePosition = floor($newPosition / $this->unencryptedBlockSize)
 			* $this->util->getBlockSize() + $this->util->getHeaderSize();
 
+		$oldFilePosition = parent::stream_tell();
 		if (parent::stream_seek($newFilePosition)) {
+			parent::stream_seek($oldFilePosition);
 			$this->flush();
+			parent::stream_seek($newFilePosition);
 			$this->position = $newPosition;
 			$return = true;
 		}