Skip to content

Commit

Permalink
fix DecryptReader to handle stream data correctly (#1400)
Browse files Browse the repository at this point in the history
Signed-off-by: Bala.FA <[email protected]>
  • Loading branch information
balamurugana authored Feb 22, 2024
1 parent 9adaaf2 commit d074764
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions minio/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit d074764

Please sign in to comment.