Fix panic on opening a directory

This commit is contained in:
George Roman 2019-06-18 17:01:51 +03:00
parent 97ad913dc2
commit 29bdcba1e8
3 changed files with 17 additions and 2 deletions

View file

@ -615,6 +615,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() {