Skip to content

Commit

Permalink
Fixes #363.
Browse files Browse the repository at this point in the history
Fixed a potential integer overflow problem in the jas_get_total_mem_size
function (for the Windows platform).
  • Loading branch information
mdadams committed Nov 17, 2023
1 parent abf85ca commit 175731c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/libjasper/base/jas_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 175731c

Please sign in to comment.