Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix DecryptReader to handle stream data correctly #1400

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading