From d074764ddcbf3e90fdbb4acc1ea700e8435fe72e Mon Sep 17 00:00:00 2001 From: Bala FA Date: Thu, 22 Feb 2024 14:26:55 +0530 Subject: [PATCH] fix DecryptReader to handle stream data correctly (#1400) Signed-off-by: Bala.FA --- minio/crypto.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/minio/crypto.py b/minio/crypto.py index 29e717359..93fc5fb20 100644 --- a/minio/crypto.py +++ b/minio/crypto.py @@ -217,11 +217,12 @@ def _read(self) -> bytes: if len(self._chunk) == 0: return self._chunk - if len(self._chunk) < _MAX_CHUNK_SIZE: - return self._decrypt(self._chunk, True) - - payload = self._chunk[:_MAX_CHUNK_SIZE] - self._chunk = self._chunk[_MAX_CHUNK_SIZE:] + length = _MAX_CHUNK_SIZE + if len(self._chunk) < length: + length = len(self._chunk) + stop = True + payload = self._chunk[:length] + self._chunk = self._chunk[length:] return self._decrypt(payload, stop) def stream(self, num_bytes=32*1024): @@ -231,14 +232,14 @@ def stream(self, num_bytes=32*1024): """ while True: data = self._read() + if not data: + break while data: result = data if num_bytes < len(data): result = data[:num_bytes] data = data[len(result):] yield result - else: - break def decrypt(response: BaseHTTPResponse, secret_key: str) -> bytes: