OSDN Git Service

Fix crash when comparing Alternate Data Streams like file.zip:Zone.Identifier:$DATA...
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 4 Mar 2023 00:26:34 +0000 (09:26 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 4 Mar 2023 00:26:34 +0000 (09:26 +0900)
Externals/poco/Foundation/src/File_WIN32U.cpp
Src/MainFrm.cpp
Src/TFile.h

index c48ae06..3df4990 100644 (file)
@@ -298,7 +298,22 @@ void FileImpl::copyToImpl(const std::string& path, int options) const
        std::wstring upath;
        convertPath(path, upath);
        if (CopyFileW(_upath.c_str(), upath.c_str(), (options & OPT_FAIL_ON_OVERWRITE_IMPL) != 0) == 0)
-               handleLastErrorImpl(_path);
+       {
+               // CopyFileW() function cannot copy Alternate Data Streams
+               FileHandle fhIn(_path, _upath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
+               FileHandle fhOut(path, upath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 
+                       ((options & OPT_FAIL_ON_OVERWRITE_IMPL) != 0) ? CREATE_NEW : OPEN_ALWAYS);
+               char buf[65536];
+               DWORD dwRead = sizeof(buf), dwWritten = 0;
+               while (dwRead == sizeof(buf))
+               {
+                       if (!ReadFile(fhIn.get(), buf, sizeof(buf), &dwRead, nullptr))
+                               handleLastErrorImpl(_path);
+                       if (!WriteFile(fhOut.get(), buf, dwRead, &dwWritten, nullptr))
+                               handleLastErrorImpl(_path);
+               }
+               SetEndOfFile(fhOut.get());
+       }
 }
 
 
index fc723b3..cb11eca 100644 (file)
@@ -2833,7 +2833,15 @@ bool CMainFrame::DoSelfCompare(UINT nID, const String& file, const String strDes
        else
        {
                copiedFile = wTemp->Create(_T("self-compare_"), ext);
-               TFile(file).copyTo(copiedFile);
+               try
+               {
+                       TFile(file).copyTo(copiedFile);
+               }
+               catch (Poco::FileException& e)
+               {
+                       
+                       LogErrorStringUTF8(e.displayText());
+               }
        }
        m_tempFiles.push_back(wTemp);
 
index a33b9dd..b20b096 100644 (file)
@@ -2,6 +2,7 @@
 
 #define POCO_NO_UNWINDOWS 1
 #include <Poco/File.h>
+#include <Poco/Exception.h>
 #include "UnicodeString.h"
 #include "unicoder.h"