修复http文件下载指定目录时mmap导致崩溃的bug (#4213)
Some checks are pending
Android / build (push) Waiting to run
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Docker / build (push) Waiting to run
Linux / build (push) Waiting to run
macOS / build (push) Waiting to run
Windows / build (push) Waiting to run

在`HttpBody.cpp`中,`getSharedMmap`函数直接尝试对所有路径进行mmap操作,没有进行文件类型检查
This commit is contained in:
ibranch7 2025-04-09 21:35:28 +08:00 committed by GitHub
parent 026e74d624
commit 56fe66da7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -194,6 +194,13 @@ static std::shared_ptr<char> getSharedMmap(const string &file_path, int64_t &fil
}
HttpFileBody::HttpFileBody(const string &file_path, bool use_mmap) {
// 判断是否为目录避免对目录进行mmap操作导致程序崩溃。
if (File::is_dir(file_path)) {
_read_to = -1;
return;
}
if (use_mmap ) {
_map_addr = getSharedMmap(file_path, _read_to);
}