-
Notifications
You must be signed in to change notification settings - Fork 52
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
Small(?) multipart upload has errors when determining mime type. #3658
Comments
The suggested error handling there is not correct, you would need to catch except botocore.exceptions.ClientError as error:
if error.response["Error"]["Code"] == "InvalidRange":
header = self._client.get_object(Bucket=self.bucket, Key=self.key)["Body"].read()
else:
raise error However, I wonder if that could lead to a DOS in case in some weird situation with partial uploads the first bytes are missing or something. No idea here, but maybe? We can anyway be a bit more defensive: object_head = s3_client.head_object(Bucket=self.bucket, Key=self.key)
object_size = int(response['ContentLength'])
max_bytes = min(2047, object_size)
header = self._client.get_object(
Bucket=self.bucket,
Key=self.key,
Range=f"bytes=0-{max_bytes}",
)["Body"].read() |
Actually, I don't think this explanation makes sense. We have a test with a small file introduced in #3350. |
It is a problem with a zero bytes file. |
Sentry issue:
An error occurred (InvalidRange) when calling the GetObject operation: The requested range is not satisfiable
.The
mimetype_from_file()
uses the boto client to get the initial range, however, it seems that the upload may be less than 2048 bytes long. Not sure why it is a multi-part... I'd expect the multipart part to have a cutoff at a certain size. Need to investigate.A quick fix would be wrapping it in a try-except as follows:
The text was updated successfully, but these errors were encountered: