加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-Fixed-a-potential-integer-overflow-problem-in-the-jas_get_total_mem_size-function.patch 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
zhangxingrong 提交于 2024-07-08 18:37 . add some upstream patchs
From 175731c70e14e952ba09f7dded1486d30555ba7e Mon Sep 17 00:00:00 2001
From: Michael Adams <mdadams@ece.uvic.ca>
Date: Fri, 17 Nov 2023 06:42:59 -0800
Subject: [PATCH] Fixes #363.
Fixed a potential integer overflow problem in the jas_get_total_mem_size
function (for the Windows platform).
---
src/libjasper/base/jas_malloc.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/libjasper/base/jas_malloc.c b/src/libjasper/base/jas_malloc.c
index 9b540008..7233f649 100644
--- a/src/libjasper/base/jas_malloc.c
+++ b/src/libjasper/base/jas_malloc.c
@@ -661,11 +661,12 @@ size_t jas_get_total_mem_size()
Reference:
https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getphysicallyinstalledsystemmemory
*/
- ULONGLONG size;
- if (!GetPhysicallyInstalledSystemMemory(&size)) {
+ ULONGLONG mem_size_in_kb;
+ if (!GetPhysicallyInstalledSystemMemory(&mem_size_in_kb)) {
return 0;
}
- return 1024 * size;
+ return (mem_size_in_kb < SIZE_MAX / JAS_CAST(size_t, 1024)) ?
+ JAS_CAST(size_t, 1024) * mem_size_in_kb : SIZE_MAX;
#else
return 0;
#endif
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化