Repository navigation
Keep server-named downloads inside the temporary directory - #9312
garciadias wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…tory download_and_extract() without filepath now rejects a file name reported by the server that is not a single path component (it contains a path separator, or is empty, '.' or '..'), before anything is downloaded. Callers that need a nested destination pass filepath explicitly. The server is asked for the name once, so the extension check and the destination use the same response. Signed-off-by: R. Garcia-Dias <rafaelagd@gmail.com>
7c00fe0 to
84888ed
Compare
Description
When
download_and_extract(url, output_dir=...)is called withoutfilepath, it downloads the archive into a temporary directory under the file name the server reports (Content-Disposition, or the last part of the URL). That name was joined to the temporary directory unchanged, so a name containing..components or an absolute path resolved outside the temporary directory and the downloaded file was moved there.This PR:
ValueErrorbefore anything is downloaded when it is not: a name containing/or\(for example../a.zip,a/b.zip,/abs/a.zip), and a name that is empty,.or..;realpathcheck that the resolved destination is directly inside the temporary directory;HEADrequests were made).An explicit
filepathbehaves as before, including a nested destination. All built-in callers (MedNISTDataset,DecathlonDataset, the MMAR and TCIA helpers,BundleGen) passfilepath, so their behaviour does not change. The only behaviour change is for a caller that omitsfilepathand downloads from a server whose reported name contains a directory part: it now gets aValueErrorinstead of a file stored under the flattened name.Tests
tests/apps/test_download_remote_filename.py(HTTP mocked, no network):../,../../,..\,sub/archive.zip,sub/..and an absolute name are all rejected with nothing downloaded and nothing written next to the temporary directory; names with no usable base name (..,.,/,//) are rejected; a plain name round trip, an explicit nestedfilepath, and a singleHEADrequest are also covered. 11 of the 13 tests fail ondev; the round trip and explicit-filepathcontrols pass on both.dev.tests/apps/test_download_and_extract.pypasses locally (13 passed).Types of changes