Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ Compute
Storage
~~~~~~~

- [Local Storage] Prevent source objects from being deleted when
``download_object`` is called with a destination that resolves
to the source file.
(#2201)
[Zhe Chen - @zhechen-cs]

- [Storage] Prevent path traversal when downloading objects to a directory by
using only the object name's basename as the local filename.
(#2206)
Expand Down
2 changes: 2 additions & 0 deletions libcloud/storage/drivers/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ def download_object(

try:
shutil.copy(obj_path, file_path)
except shutil.SameFileError:
return False
except OSError:
if delete_on_failure:
try:
Expand Down
16 changes: 16 additions & 0 deletions libcloud/test/storage/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,22 @@ def test_download_object_and_overwrite(self):
self.remove_tmp_file(tmppath)
os.unlink(destination_path)

def test_download_object_to_source_preserves_object(self):
content = b"preserve this object"
container = self.driver.create_container("same-file")
object_path = os.path.join(self.key, container.name, "object")

for destination_path in (object_path, os.path.dirname(object_path) + os.sep):
with self.subTest(destination_path=destination_path):
obj = self.driver.upload_object_via_stream(iter([content]), container, "object")
result = self.driver.download_object(obj, destination_path, overwrite_existing=True)
self.assertFalse(result)
with open(object_path, "rb") as source:
self.assertEqual(source.read(), content)
self.assertEqual(
self.driver.get_object(container.name, "object").size, len(content)
)

def test_download_object_as_stream_success(self):
tmppath = self.make_tmp_file()
container = self.driver.create_container("test6")
Expand Down
Loading