Skip to content

Commit

Permalink
Merge pull request #26 from RachelTucker/4_0_fix_buffer_overflow
Browse files Browse the repository at this point in the history
Updated get object to have specifiable buffer stream
  • Loading branch information
rpmoore authored May 17, 2018
2 parents 32929e1 + d25914f commit ca590df
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ds3/ds3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7947,15 +7947,18 @@ def process_response(self, response):


class GetObjectResponse(AbstractResponse):
def __init__(self, response, request, buffer_size=None):
self.buffer_size = buffer_size
super(GetObjectResponse, self).__init__(response, request)

def process_response(self, response):
self.__check_status_codes__([200, 206])
stream = self.request.stream
try:
bytes_read = response.read()
bytes_read = response.read(self.buffer_size)
while bytes_read:
stream.write(bytes_read)
bytes_read = response.read()
bytes_read = response.read(self.buffer_size)
finally:
stream.close()
response.close()
Expand Down Expand Up @@ -11243,10 +11246,10 @@ def get_service(self, request):
raise TypeError('request for get_service should be of type GetServiceRequest but was ' + request.__class__.__name__)
return GetServiceResponse(self.net_client.get_response(request), request)

def get_object(self, request):
def get_object(self, request, buffer_size=1048576):
if not isinstance(request, GetObjectRequest):
raise TypeError('request for get_object should be of type GetObjectRequest but was ' + request.__class__.__name__)
return GetObjectResponse(self.net_client.get_response(request), request)
return GetObjectResponse(self.net_client.get_response(request), request, buffer_size)

def head_bucket(self, request):
if not isinstance(request, HeadBucketRequest):
Expand Down

0 comments on commit ca590df

Please sign in to comment.