Skip to content

Commit

Permalink
Deep copy Blob in LocalBlobStore.getBlob
Browse files Browse the repository at this point in the history
ByteSourcePayload.openStream is not thread safe and lack of
synchronization can throw ArrayIndexOutOfBoundsExceptions.  Instead
deep copy the underlying Payload.  Fixes gaul/s3proxy#303.
  • Loading branch information
gaul committed Aug 1, 2022
1 parent 16926b0 commit b1fc2d2
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,22 @@ public Iterable<String> getBlobKeysInsideContainer(final String containerName, S
@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
Expand Down

0 comments on commit b1fc2d2

Please sign in to comment.