From cd1371a0177f3d496ac93d759d50eab0ef9f2f05 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Thu, 2 Jul 2020 19:16:24 +0900 Subject: [PATCH] Fix GitHub issue #367: Crash when comparing encrypted 7z files --- ArchiveSupport/Merge7z/BuildArc.cmd | 2 +- ArchiveSupport/Merge7z/Merge7z907.cpp | 91 ++++++++++++++++++++++++++--------- DownloadDeps.cmd | 4 +- 3 files changed, 72 insertions(+), 25 deletions(-) diff --git a/ArchiveSupport/Merge7z/BuildArc.cmd b/ArchiveSupport/Merge7z/BuildArc.cmd index 427476def..aa6d5e679 100644 --- a/ArchiveSupport/Merge7z/BuildArc.cmd +++ b/ArchiveSupport/Merge7z/BuildArc.cmd @@ -1,7 +1,7 @@ pushd "%~dp0" setlocal -set MERGE7z_VERSION=1900.1 +set MERGE7z_VERSION=1900.2 set PATH="%ProgramFiles%\7-zip";"%ProgramFiles(x86)%\7-zip";%PATH% set DISTDIR=..\..\Build\Releases diff --git a/ArchiveSupport/Merge7z/Merge7z907.cpp b/ArchiveSupport/Merge7z/Merge7z907.cpp index 1bf18873d..aee9f46ff 100644 --- a/ArchiveSupport/Merge7z/Merge7z907.cpp +++ b/ArchiveSupport/Merge7z/Merge7z907.cpp @@ -33,6 +33,7 @@ DATE: BY: DESCRIPTION: #include "7zip/UI/FileManager/OpenCallback.h" #include "7zip/UI/FileManager/ExtractCallback.h" +#include "7zip/UI/FileManager/resourceGui.h" #include "7zip/UI/Common/ArchiveExtractCallback.h" #include "7zip/UI/GUI/UpdateCallbackGUI.h" @@ -84,6 +85,46 @@ public: } }; +struct CThreadArchiveOpen +{ + UString Path; + CInFileStream* File; + NFile::NFind::CFileInfo FileInfo; + IInArchive* Archive; + CMyComPtr OpenCallback; + COpenArchiveCallback* OpenCallbackSpec; + HRESULT Result; + + void Process() + { + CProgressCloser closer(OpenCallbackSpec->ProgressDialog); + + if COMPLAIN(!NFile::NFind::CFindFile().FindFirst(Path, FileInfo)) + { + Result = ERROR_FILE_NOT_FOUND; + return; + } + if COMPLAIN(!File->Open(Path)) + { + Result = ERROR_OPEN_FAILED; + return; + } + static const UInt64 maxCheckStartPosition = ULLONG_MAX; + if COMPLAIN(Archive->Open(File, &maxCheckStartPosition, OpenCallbackSpec) != S_OK) + { + Result = ERROR_CANT_ACCESS_FILE; + return; + } + Result = ERROR_SUCCESS; + } + + static THREAD_FUNC_DECL MyThreadFunction(void* param) + { + ((CThreadArchiveOpen*)param)->Process(); + return 0; + } +}; + /** * @brief Initialize Inspector */ @@ -98,30 +139,36 @@ Format7zDLL::Interface::Inspector::Inspector(Format7zDLL::Interface *format, LPC void Format7zDLL::Interface::Inspector::Init(HWND hwndParent) { format->GetDefaultName(hwndParent, ustrDefaultName); - COpenArchiveCallback *callbackImpl = new COpenArchiveCallback; - //COpenCallbackImp *callbackImpl = new COpenCallbackImp; - (archive = format->GetInArchive()) -> AddRef(); - (file = new CInFileStream) -> AddRef(); - (callback = callbackImpl) -> AddRef(); - callbackImpl->PasswordIsDefined = false; - callbackImpl->ParentWindow = hwndParent; - /*CMyComBSTR password; - callback->CryptoGetTextPassword(&password);*/ - if COMPLAIN(!NFile::NFind::CFindFile().FindFirst(path, fileInfo)) - { - Complain(ERROR_FILE_NOT_FOUND, path); - } - if COMPLAIN(!file->Open(path)) - { - Complain(ERROR_OPEN_FAILED, path); - } - static const UInt64 maxCheckStartPosition = ULLONG_MAX; - if COMPLAIN(archive->Open(file, &maxCheckStartPosition, callback) != S_OK) + + CThreadArchiveOpen t; + t.OpenCallbackSpec = new COpenArchiveCallback; + t.OpenCallback = t.OpenCallbackSpec; + t.OpenCallbackSpec->PasswordIsDefined = false; + t.OpenCallbackSpec->ParentWindow = hwndParent; + + (archive = format->GetInArchive())->AddRef(); + (file = new CInFileStream)->AddRef(); + t.File = file; + t.Path = path; + t.FileInfo = fileInfo; + t.Archive = archive; + + UString progressTitle = LangString(IDS_OPENNING); + t.OpenCallbackSpec->ProgressDialog.MainWindow = hwndParent; + t.OpenCallbackSpec->ProgressDialog.MainTitle = "7-Zip"; // LangString(IDS_APP_TITLE); + t.OpenCallbackSpec->ProgressDialog.MainAddTitle = progressTitle + L' '; + t.OpenCallbackSpec->ProgressDialog.WaitMode = true; + { - Complain(ERROR_CANT_ACCESS_FILE, path); + NWindows::CThread thread; + thread.Create(CThreadArchiveOpen::MyThreadFunction, &t); + t.OpenCallbackSpec->StartProgressDialog(progressTitle, thread); } - passwordIsDefined = callbackImpl->PasswordIsDefined; - password = callbackImpl->Password; + if (t.Result != ERROR_SUCCESS) + Complain(t.Result, path); + + passwordIsDefined = t.OpenCallbackSpec->PasswordIsDefined; + password = t.OpenCallbackSpec->Password; } /** diff --git a/DownloadDeps.cmd b/DownloadDeps.cmd index 60b92bb90..050c9bd84 100644 --- a/DownloadDeps.cmd +++ b/DownloadDeps.cmd @@ -4,8 +4,8 @@ set downloadsdir=%~dp0\build\WinMergeDownloadDeps set urls_destdirs=^ https://github.com/WinMerge/winmerge/releases/download/winmerge_manual_another_build_tools_v2/winmerge_manual_another_build_tools_v2.zip!Docs\Manual\Tools ^ https://github.com/WinMerge/winmerge/releases/download/ShellExtension-1.17.12.0/ShellExtension-1.17.12.0.zip!Build ^ -https://github.com/WinMerge/winmerge/releases/download/Merge7z1900.1/Merge7z1900.1-win32.zip!Build ^ -https://github.com/WinMerge/winmerge/releases/download/Merge7z1900.1/Merge7z1900.1-x64.zip!Build\X64 ^ +https://github.com/WinMerge/winmerge/releases/download/Merge7z1900.2/Merge7z1900.2-win32.zip!Build ^ +https://github.com/WinMerge/winmerge/releases/download/Merge7z1900.2/Merge7z1900.2-x64.zip!Build\X64 ^ https://github.com/WinMerge/frhed/releases/download/0.10904.2017/frhed-0.10904.2017.4-win32.zip!Build ^ https://github.com/WinMerge/frhed/releases/download/0.10904.2017/frhed-0.10904.2017.4-x64.zip!Build\X64 ^ https://github.com/WinMerge/winimerge/releases/download/1.0.18.0/winimerge-1-0-18-0-exe.zip!Build ^ -- 2.11.0