From 5a3786be0d60be35ec12e82287961c801af2f957 Mon Sep 17 00:00:00 2001 From: MouriNaruto Date: Tue, 24 Dec 2024 09:40:09 +0800 Subject: [PATCH] Fix the crash issue for 7-Zip's hash algorithms wrappers I commited before. --- NanaZip.Core/Wrappers/Sha256Wrapper.cpp | 10 +++++++++- NanaZip.Core/Wrappers/Sha512Wrapper.cpp | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/NanaZip.Core/Wrappers/Sha256Wrapper.cpp b/NanaZip.Core/Wrappers/Sha256Wrapper.cpp index 578257bb..f652eb58 100644 --- a/NanaZip.Core/Wrappers/Sha256Wrapper.cpp +++ b/NanaZip.Core/Wrappers/Sha256Wrapper.cpp @@ -10,12 +10,20 @@ #include "Sha256Wrapper.h" +#include + BoolInt Sha256_SetFunction( CSha256* p, unsigned algo) { - UNREFERENCED_PARAMETER(p); UNREFERENCED_PARAMETER(algo); + + if (p) + { + // Workaround for using the uninitialized memory. + std::memset(p, 0, sizeof(CSha256)); + } + // Only return true because it's a wrapper to K7Pal. return True; } diff --git a/NanaZip.Core/Wrappers/Sha512Wrapper.cpp b/NanaZip.Core/Wrappers/Sha512Wrapper.cpp index 4861da14..c7fd023d 100644 --- a/NanaZip.Core/Wrappers/Sha512Wrapper.cpp +++ b/NanaZip.Core/Wrappers/Sha512Wrapper.cpp @@ -10,12 +10,20 @@ #include "Sha512Wrapper.h" +#include + BoolInt Sha512_SetFunction( CSha512* p, unsigned algo) { - UNREFERENCED_PARAMETER(p); UNREFERENCED_PARAMETER(algo); + + if (p) + { + // Workaround for using the uninitialized memory. + std::memset(p, 0, sizeof(CSha512)); + } + // Only return true because it's a wrapper to K7Pal. return True; }