Deep copy Blob in LocalBlobStore.getBlob

ByteSourcePayload.openStream is not thread safe and lack of
synchronization can throw ArrayIndexOutOfBoundsExceptions.  Instead
deep copy the underlying Payload.  Fixes gaul/s3proxy#303.
This commit is contained in:
Andrew Gaul 2022-08-01 21:19:15 +09:00 committed by Andrew Gaul
parent 5067897ff5
commit 57a9e7b7cc
1 changed files with 16 additions and 1 deletions

View File

@ -162,7 +162,22 @@ public class TransientStorageStrategy implements LocalStorageStrategy {
@Override
public Blob getBlob(final String containerName, final String blobName) {
Map<String, Blob> map = containerToBlobs.get(containerName);
return map == null ? null : map.get(blobName);
if (map == null) {
return null;
}
Blob blob = map.get(blobName);
if (blob == null) {
return null;
}
// Deep copy Blob to make sure ByteSourcePayload does not share Closer.
Payload payload = blob.getPayload();
MutableContentMetadata md = payload.getContentMetadata();
Blob newBlob = blobFactory.create(BlobStoreUtils.copy(blob.getMetadata()));
Payload newPayload = Payloads.newPayload(payload.getRawContent());
newBlob.setPayload(payload);
HttpUtils.copy(md, newPayload.getContentMetadata());
return newBlob;
}
@Override