diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-06-22 22:24:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-22 22:24:08 -0400 |
commit | 1d2c0ba0bc71e34495accde61f58443f0f18c28c (patch) | |
tree | bee1d24b814007541f6b958481d437d62a90ce9b /components | |
parent | ea108ffc4751f584c20d62b7b9e52ea23be02c2f (diff) | |
parent | 29bdcba1e8e9a17bab978748b2700aefd4513e44 (diff) | |
download | servo-1d2c0ba0bc71e34495accde61f58443f0f18c28c.tar.gz servo-1d2c0ba0bc71e34495accde61f58443f0f18c28c.zip |
Auto merge of #23593 - georgeroman:fix_panic_on_opening_directory, r=Manishearth
Fix panic on opening a directory
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
Continued from https://github.com/servo/servo/pull/23548
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23593)
<!-- Reviewable:end -->
Diffstat (limited to 'components')
-rw-r--r-- | components/net/fetch/methods.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index 07200ce444f..b04244e94a2 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -613,6 +613,14 @@ fn scheme_fetch( } if let Ok(file_path) = url.to_file_path() { if let Ok(file) = File::open(file_path.clone()) { + if let Ok(metadata) = file.metadata() { + if metadata.is_dir() { + return Response::network_error(NetworkError::Internal( + "Opening a directory is not supported".into(), + )); + } + } + // Get range bounds (if any) and try to seek to the requested offset. // If seeking fails, bail out with a NetworkError. let file_size = match file.metadata() { |