JCLOUDS-1137: Handle TOCTOU during blobMetadata

A similar issue exists when getting a blob payload when a caller
simultaneously removes the blob.
This commit is contained in:
Andrew Gaul 2016-07-11 21:51:52 -07:00
parent 08e78c979e
commit 4874a1eb18
2 changed files with 11 additions and 5 deletions

View File

@ -32,6 +32,7 @@ import static org.jclouds.filesystem.util.Utils.setPublic;
import static org.jclouds.util.Closeables2.closeQuietly;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
@ -389,6 +390,8 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
.contentLength(byteSource.size())
.contentMD5(byteSource.hash(Hashing.md5()).asBytes());
}
} catch (FileNotFoundException fnfe) {
return null;
} catch (IOException e) {
throw Throwables.propagate(e);
}

View File

@ -245,18 +245,21 @@ public final class LocalBlobStore implements BlobStore {
return storageStrategy.blobExists(containerName, key);
}
});
SortedSet<StorageMetadata> contents = newTreeSet(transform(blobBelongingToContainer,
new Function<String, StorageMetadata>() {
SortedSet<StorageMetadata> contents = newTreeSet(FluentIterable.from(blobBelongingToContainer)
.transform(new Function<String, StorageMetadata>() {
@Override
public StorageMetadata apply(String key) {
Blob oldBlob = loadBlob(containerName, key);
checkState(oldBlob != null, "blob " + key + " is not present although it was in the list of "
+ containerName);
if (oldBlob == null) {
return null;
}
checkState(oldBlob.getMetadata() != null, "blob " + containerName + "/" + key + " has no metadata");
MutableBlobMetadata md = BlobStoreUtils.copy(oldBlob.getMetadata());
md.setSize(oldBlob.getMetadata().getSize());
return md;
}
}));
})
.filter(Predicates.<StorageMetadata>notNull()));
String marker = null;
if (options != null) {