From 56fe66da7cb61044c4ca93f504101ea52787a6c5 Mon Sep 17 00:00:00 2001 From: ibranch7 <62053118+ibranch7@users.noreply.github.com> Date: Wed, 9 Apr 2025 21:35:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhttp=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=8C=87=E5=AE=9A=E7=9B=AE=E5=BD=95=E6=97=B6?= =?UTF-8?q?mmap=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83=E7=9A=84bug=20(#4213)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在`HttpBody.cpp`中,`getSharedMmap`函数直接尝试对所有路径进行mmap操作,没有进行文件类型检查 --- src/Http/HttpBody.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Http/HttpBody.cpp b/src/Http/HttpBody.cpp index b73538c7..018e3618 100644 --- a/src/Http/HttpBody.cpp +++ b/src/Http/HttpBody.cpp @@ -194,6 +194,13 @@ static std::shared_ptr 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); }