diff --git a/consio.cpp b/consio.cpp index f30f4d0..fa35d61 100644 --- a/consio.cpp +++ b/consio.cpp @@ -171,18 +171,33 @@ static void GetPasswordText(wchar *Str,uint MaxLength) { #ifdef _WIN_ALL HANDLE hConIn=GetStdHandle(STD_INPUT_HANDLE); - HANDLE hConOut=GetStdHandle(STD_OUTPUT_HANDLE); - DWORD ConInMode,ConOutMode; - DWORD Read=0; + DWORD ConInMode; GetConsoleMode(hConIn,&ConInMode); - GetConsoleMode(hConOut,&ConOutMode); - SetConsoleMode(hConIn,ENABLE_LINE_INPUT); - SetConsoleMode(hConOut,ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT); + SetConsoleMode(hConIn,ENABLE_LINE_INPUT); // Remove ENABLE_ECHO_INPUT. + // We prefer ReadConsole to ReadFile, so we can read Unicode input. + DWORD Read=0; ReadConsole(hConIn,Str,MaxLength-1,&Read,NULL); Str[Read]=0; SetConsoleMode(hConIn,ConInMode); - SetConsoleMode(hConOut,ConOutMode); + + // If entered password is longer than MAXPASSWORD and truncated, + // read its unread part anyway, so it isn't read later as the second + // password for -p switch. Low level FlushConsoleInputBuffer doesn't help + // for high level ReadConsole, which in line input mode seems to store + // the rest of string in its own internal buffer. + if (wcschr(Str,'\r')==NULL) // If '\r' is missing, the password was truncated. + while (true) + { + wchar Trail[64]; + DWORD TrailRead=0; + // Use ASIZE(Trail)-1 to reserve the space for trailing 0. + ReadConsole(hConIn,Trail,ASIZE(Trail)-1,&TrailRead,NULL); + Trail[TrailRead]=0; + if (TrailRead==0 || wcschr(Trail,'\r')!=NULL) + break; + } + #else char StrA[MAXPASSWORD*4]; // "*4" for multibyte UTF-8 characters. #if defined(_EMX) || defined (__VMS) @@ -267,6 +282,7 @@ bool getwstr(wchar *str,size_t n) Array StrA(n*4); // Up to 4 UTF-8 characters per wchar_t. File SrcFile; SrcFile.SetHandleType(FILE_HANDLESTD); + SrcFile.SetLineInputMode(true); int ReadSize=SrcFile.Read(&StrA[0],StrA.Size()-1); if (ReadSize<=0) { diff --git a/dll.rc b/dll.rc index dd596f2..7c399f2 100644 --- a/dll.rc +++ b/dll.rc @@ -2,8 +2,8 @@ #include VS_VERSION_INFO VERSIONINFO -FILEVERSION 6, 10, 2, 318 -PRODUCTVERSION 6, 10, 2, 318 +FILEVERSION 6, 12, 100, 489 +PRODUCTVERSION 6, 12, 100, 489 FILEOS VOS__WINDOWS32 FILETYPE VFT_APP { @@ -14,9 +14,9 @@ FILETYPE VFT_APP VALUE "CompanyName", "Alexander Roshal\0" VALUE "ProductName", "RAR decompression library\0" VALUE "FileDescription", "RAR decompression library\0" - VALUE "FileVersion", "6.10.2\0" - VALUE "ProductVersion", "6.10.2\0" - VALUE "LegalCopyright", "Copyright © Alexander Roshal 1993-2021\0" + VALUE "FileVersion", "6.12.0\0" + VALUE "ProductVersion", "6.12.0\0" + VALUE "LegalCopyright", "Copyright © Alexander Roshal 1993-2022\0" VALUE "OriginalFilename", "Unrar.dll\0" } } diff --git a/extract.cpp b/extract.cpp index 61fc582..dc109b9 100644 --- a/extract.cpp +++ b/extract.cpp @@ -49,8 +49,7 @@ void CmdExtract::DoExtract() if (Code!=EXTRACT_ARC_REPEAT) break; } - if (FindFile::FastFind(ArcName,&FD)) - DataIO.ProcessedArcSize+=FD.Size; + DataIO.ProcessedArcSize+=DataIO.LastArcSize; } // Clean user entered password. Not really required, just for extra safety. @@ -82,7 +81,7 @@ void CmdExtract::DoExtract() void CmdExtract::ExtractArchiveInit(Archive &Arc) { - DataIO.UnpArcSize=Arc.IsSeekable() ? Arc.FileLength() : 0; + DataIO.AdjustTotalArcSize(&Arc); FileCount=0; MatchedArgs=0; @@ -230,14 +229,11 @@ EXTRACT_ARC_CODE CmdExtract::ExtractArchive() if (Repeat) { // If we started extraction from not first volume and need to - // restart it from first, we must correct DataIO.TotalArcSize - // for correct total progress display. We subtract the size - // of current volume and all volumes after it and add the size - // of new (first) volume. - FindData OldArc,NewArc; - if (FindFile::FastFind(Arc.FileName,&OldArc) && - FindFile::FastFind(ArcName,&NewArc)) - DataIO.TotalArcSize-=VolumeSetSize+OldArc.Size-NewArc.Size; + // restart it from first, we must set DataIO.TotalArcSize to size + // of new first volume to display the total progress correctly. + FindData NewArc; + if (FindFile::FastFind(ArcName,&NewArc)) + DataIO.TotalArcSize=NewArc.Size; return EXTRACT_ARC_REPEAT; } else @@ -652,7 +648,7 @@ bool CmdExtract::ExtractCurrentFile(Archive &Arc,size_t HeaderSize,bool &Repeat) uint64 Preallocated=0; if (!TestMode && !Arc.BrokenHeader && Arc.FileHead.UnpSize>1000000 && - Arc.FileHead.PackSize*1024>Arc.FileHead.UnpSize && + Arc.FileHead.PackSize*1024>Arc.FileHead.UnpSize && Arc.IsSeekable() && (Arc.FileHead.UnpSize<100000000 || Arc.FileLength()>Arc.FileHead.PackSize)) { CurFile.Prealloc(Arc.FileHead.UnpSize); @@ -670,8 +666,11 @@ bool CmdExtract::ExtractCurrentFile(Archive &Arc,size_t HeaderSize,bool &Repeat) if (Type==FSREDIR_HARDLINK || Type==FSREDIR_FILECOPY) { + wchar RedirName[NM]; + ConvertPath(Arc.FileHead.RedirName,RedirName,ASIZE(RedirName)); + wchar NameExisting[NM]; - ExtrPrepareName(Arc,Arc.FileHead.RedirName,NameExisting,ASIZE(NameExisting)); + ExtrPrepareName(Arc,RedirName,NameExisting,ASIZE(NameExisting)); if (FileCreateMode && *NameExisting!=0) // *NameExisting can be 0 in case of excessive -ap switch. if (Type==FSREDIR_HARDLINK) LinkSuccess=ExtractHardlink(Cmd,DestFileName,NameExisting,ASIZE(NameExisting)); diff --git a/file.cpp b/file.cpp index 216bc89..e7b584d 100644 --- a/file.cpp +++ b/file.cpp @@ -7,6 +7,7 @@ File::File() NewFile=false; LastWrite=false; HandleType=FILE_HANDLENORMAL; + LineInput=false; SkipClose=false; ErrorType=FILE_SUCCESS; OpenShared=false; @@ -420,13 +421,17 @@ int File::Read(void *Data,size_t Size) } TotalRead+=ReadSize; // If ReadSize is -1, TotalRead is also set to -1 here. - if (HandleType==FILE_HANDLESTD && ReadSize>0 && (uint)ReadSize0 && (uint)ReadSize +#include +#pragma comment(lib, "wbemuuid.lib") + +static bool WMI_IsWindows10() +{ + IWbemLocator *pLoc = NULL; + + HRESULT hres = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER, + IID_IWbemLocator,(LPVOID *)&pLoc); + + if (FAILED(hres)) + return false; + + IWbemServices *pSvc = NULL; + + hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"),NULL,NULL,0,NULL,0,0,&pSvc); + + if (FAILED(hres)) + { + pLoc->Release(); + return false; + } + + hres = CoSetProxyBlanket(pSvc,RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,NULL, + RPC_C_AUTHN_LEVEL_CALL,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE); + + if (FAILED(hres)) + { + pSvc->Release(); + pLoc->Release(); + return false; + } + + IEnumWbemClassObject *pEnumerator = NULL; + hres = pSvc->ExecQuery(bstr_t("WQL"), bstr_t("SELECT * FROM Win32_OperatingSystem"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + + if (FAILED(hres)) + { + pSvc->Release(); + pLoc->Release(); + return false; + } + + IWbemClassObject *pclsObj = NULL; + ULONG uReturn = 0; + + bool Win10=false; + while (pEnumerator!=NULL) + { + HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + if (uReturn==0) + break; + + VARIANT vtProp; + + hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0); + Win10|=wcsstr(vtProp.bstrVal,L"Windows 10")!=NULL; + VariantClear(&vtProp); + + pclsObj->Release(); + } + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + + return Win10; +} + + +// Replace it with actual check when available. +bool IsWindows11OrGreater() +{ + static bool IsSet=false,IsWin11=false; + if (!IsSet) + { + OSVERSIONINFO WinVer; + WinVer.dwOSVersionInfoSize=sizeof(WinVer); + GetVersionEx(&WinVer); + IsWin11=WinVer.dwMajorVersion>10 || + WinVer.dwMajorVersion==10 && WinVer.dwBuildNumber >= 22000 && !WMI_IsWindows10(); + IsSet=true; + } + return IsWin11; +} diff --git a/isnt.hpp b/isnt.hpp index 85790da..fed0b51 100644 --- a/isnt.hpp +++ b/isnt.hpp @@ -10,4 +10,7 @@ enum WINNT_VERSION { DWORD WinNT(); +// Replace it with actual check when available. +bool IsWindows11OrGreater(); + #endif diff --git a/list.cpp b/list.cpp index 3a99ab0..e5052c0 100644 --- a/list.cpp +++ b/list.cpp @@ -377,15 +377,16 @@ void ListFileHeader(Archive &Arc,FileHeader &hd,bool &TitleShown,bool Verbose,bo { mprintf(L"\n%12ls: ",L"Unix owner"); if (*hd.UnixOwnerName!=0) - mprintf(L"%ls:",GetWide(hd.UnixOwnerName)); + mprintf(L"%ls",GetWide(hd.UnixOwnerName)); + else + if (hd.UnixOwnerNumeric) + mprintf(L"#%d",hd.UnixOwnerID); + mprintf(L":"); if (*hd.UnixGroupName!=0) mprintf(L"%ls",GetWide(hd.UnixGroupName)); - if ((*hd.UnixOwnerName!=0 || *hd.UnixGroupName!=0) && (hd.UnixOwnerNumeric || hd.UnixGroupNumeric)) - mprintf(L" "); - if (hd.UnixOwnerNumeric) - mprintf(L"#%d:",hd.UnixOwnerID); - if (hd.UnixGroupNumeric) - mprintf(L"#%d:",hd.UnixGroupID); + else + if (hd.UnixGroupNumeric) + mprintf(L"#%d",hd.UnixGroupID); } mprintf(L"\n"); diff --git a/makefile b/makefile index 214f87e..ace156c 100644 --- a/makefile +++ b/makefile @@ -123,7 +123,7 @@ UNRAR_OBJ=filestr.o recvol.o rs.o scantree.o qopen.o LIB_OBJ=filestr.o scantree.o dll.o qopen.o OBJECTS=rar.o strlist.o strfn.o pathfn.o smallfn.o global.o file.o filefn.o filcreat.o \ - archive.o arcread.o unicode.o system.o isnt.o crypt.o crc.o rawread.o encname.o \ + archive.o arcread.o unicode.o system.o crypt.o crc.o rawread.o encname.o \ resource.o match.o timefn.o rdwrfn.o consio.o options.o errhnd.o rarvm.o secpassword.o \ rijndael.o getbits.o sha1.o sha256.o blake2s.o hash.o extinfo.o extract.o volume.o \ list.o find.o unpack.o headers.o threadpool.o rs16.o cmddata.o ui.o diff --git a/pathfn.cpp b/pathfn.cpp index 3e32128..983bd74 100644 --- a/pathfn.cpp +++ b/pathfn.cpp @@ -1044,7 +1044,9 @@ void MakeNameCompatible(wchar *Name,size_t MaxSize) else if (Devices[J][K]==0) { - MatchFound=s[K]==0 || s[K]=='.' || IsPathDiv(s[K]); + // Names like aux.txt are accessible without \\?\ prefix + // since Windows 11. Pure aux is still prohibited. + MatchFound=s[K]==0 || s[K]=='.' && !IsWindows11OrGreater() || IsPathDiv(s[K]); break; } else diff --git a/rdwrfn.cpp b/rdwrfn.cpp index 12984fb..5e13ae6 100644 --- a/rdwrfn.cpp +++ b/rdwrfn.cpp @@ -16,6 +16,7 @@ void ComprDataIO::Init() UnpackFromMemory=false; UnpackToMemory=false; UnpPackedSize=0; + UnpPackedLeft=0; ShowProgress=true; TestMode=false; SkipUnpCRC=false; @@ -35,7 +36,9 @@ void ComprDataIO::Init() SubHead=NULL; SubHeadPos=NULL; CurrentCommand=0; - ProcessedArcSize=TotalArcSize=0; + ProcessedArcSize=0; + LastArcSize=0; + TotalArcSize=0; } @@ -75,10 +78,10 @@ int ComprDataIO::UnpRead(byte *Addr,size_t Count) } else { - size_t SizeToRead=((int64)Count>UnpPackedSize) ? (size_t)UnpPackedSize:Count; + size_t SizeToRead=((int64)Count>UnpPackedLeft) ? (size_t)UnpPackedLeft:Count; if (SizeToRead > 0) { - if (UnpVolume && Decryption && (int64)Count>UnpPackedSize) + if (UnpVolume && Decryption && (int64)Count>UnpPackedLeft) { // We need aligned blocks for decryption and we want "Keep broken // files" to work efficiently with missing encrypted volumes. @@ -109,7 +112,7 @@ int ComprDataIO::UnpRead(byte *Addr,size_t Count) ReadAddr+=ReadSize; Count-=ReadSize; #endif - UnpPackedSize-=ReadSize; + UnpPackedLeft-=ReadSize; // Do not ask for next volume if we read something from current volume. // If next volume is missing, we need to process all data from current @@ -118,7 +121,7 @@ int ComprDataIO::UnpRead(byte *Addr,size_t Count) // we ask for next volume also if we have non-aligned encryption block. // Since we adjust data size for decryption earlier above, // it does not hurt "Keep broken files" mode efficiency. - if (UnpVolume && UnpPackedSize == 0 && + if (UnpVolume && UnpPackedLeft == 0 && (ReadSize==0 || Decryption && (TotalRead & CRYPT_BLOCK_MASK) != 0) ) { #ifndef NOVOLUME @@ -134,7 +137,7 @@ int ComprDataIO::UnpRead(byte *Addr,size_t Count) } Archive *SrcArc=(Archive *)SrcFile; if (SrcArc!=NULL) - ShowUnpRead(SrcArc->CurBlockPos+CurUnpRead,UnpArcSize); + ShowUnpRead(SrcArc->NextBlockPos-UnpPackedSize+CurUnpRead,TotalArcSize); if (ReadSize!=-1) { ReadSize=TotalRead; @@ -197,12 +200,8 @@ void ComprDataIO::ShowUnpRead(int64 ArcPos,int64 ArcSize) { if (ShowProgress && SrcFile!=NULL) { - if (TotalArcSize!=0) - { - // important when processing several archives or multivolume archive - ArcSize=TotalArcSize; - ArcPos+=ProcessedArcSize; - } + // Important when processing several archives or multivolume archive. + ArcPos+=ProcessedArcSize; Archive *SrcArc=(Archive *)SrcFile; RAROptions *Cmd=SrcArc->GetRAROptions(); @@ -286,3 +285,38 @@ void ComprDataIO::SetUnpackToMemory(byte *Addr,uint Size) UnpackToMemoryAddr=Addr; UnpackToMemorySize=Size; } + + +// Extraction progress is based on the position in archive and we adjust +// the total archives size here, so trailing blocks do not prevent progress +// reaching 100% at the end of extraction. Alternatively we could print "100%" +// after completing the entire archive extraction, but then we would need +// to take into account possible messages like the checksum error after +// last file percent progress. +void ComprDataIO::AdjustTotalArcSize(Archive *Arc) +{ + // If we know a position of QO or RR blocks, use them to adjust the total + // packed size to beginning of these blocks. Earlier we already calculated + // the total size based on entire archive sizes. We also set LastArcSize + // to start of first trailing block, to add it later to ProcessedArcSize. + int64 ArcLength=Arc->IsSeekable() ? Arc->FileLength() : 0; + if (Arc->MainHead.QOpenOffset!=0) // QO is always preceding RR record. + LastArcSize=Arc->MainHead.QOpenOffset; + else + if (Arc->MainHead.RROffset!=0) + LastArcSize=Arc->MainHead.RROffset; + else + { + // If neither QO nor RR are found, exclude the approximate size of + // end of archive block. + // We select EndBlock to be larger than typical 8 bytes HEAD_ENDARC, + // but to not exceed the smallest 22 bytes HEAD_FILE with 1 byte file + // name, so we do not have two files with 100% at the end of archive. + const uint EndBlock=23; + + if (ArcLength>EndBlock) + LastArcSize=ArcLength-EndBlock; + } + + TotalArcSize-=ArcLength-LastArcSize; +} diff --git a/rdwrfn.hpp b/rdwrfn.hpp index fc38fd3..3060a0f 100644 --- a/rdwrfn.hpp +++ b/rdwrfn.hpp @@ -1,6 +1,7 @@ #ifndef _RAR_DATAIO_ #define _RAR_DATAIO_ +class Archive; class CmdAdd; class Unpack; class ArcFileSearch; @@ -29,6 +30,7 @@ class ComprDataIO byte *UnpWrAddr; int64 UnpPackedSize; + int64 UnpPackedLeft; bool ShowProgress; bool TestMode; @@ -61,7 +63,7 @@ class ComprDataIO void UnpWrite(byte *Addr,size_t Count); void EnableShowProgress(bool Show) {ShowProgress=Show;} void GetUnpackedData(byte **Data,size_t *Size); - void SetPackedSizeToRead(int64 Size) {UnpPackedSize=Size;} + void SetPackedSizeToRead(int64 Size) {UnpPackedSize=UnpPackedLeft=Size;} void SetTestMode(bool Mode) {TestMode=Mode;} void SetSkipUnpCRC(bool Skip) {SkipUnpCRC=Skip;} void SetNoFileHeader(bool Mode) {NoFileHeader=Mode;} @@ -74,12 +76,12 @@ class ComprDataIO void SetCmt13Encryption(); void SetUnpackToMemory(byte *Addr,uint Size); void SetCurrentCommand(wchar Cmd) {CurrentCommand=Cmd;} + void AdjustTotalArcSize(Archive *Arc); bool PackVolume; bool UnpVolume; bool NextVolumeMissing; - int64 UnpArcSize; int64 CurPackRead,CurPackWrite,CurUnpRead,CurUnpWrite; @@ -87,6 +89,9 @@ class ComprDataIO // Used to calculate the total operation progress. int64 ProcessedArcSize; + // Last extracted archive size up to QO or RR block. + int64 LastArcSize; + int64 TotalArcSize; DataHash PackedDataHash; // Packed write and unpack read hash. diff --git a/ulinks.cpp b/ulinks.cpp index d198f2e..af6ef36 100644 --- a/ulinks.cpp +++ b/ulinks.cpp @@ -50,6 +50,26 @@ static bool IsFullPath(const char *PathA) // Unix ASCII version. } +// For security purpose we prefer to be sure that CharToWide completed +// successfully and even if it truncated a string for some reason, +// it didn't affect the number of path related characters we analyze +// in IsRelativeSymlinkSafe later. +// This check is likely to be excessive, but let's keep it anyway. +static bool SafeCharToWide(const char *Src,wchar *Dest,size_t DestSize) +{ + if (!CharToWide(Src,Dest,DestSize) || *Dest==0) + return false; + uint SrcChars=0,DestChars=0; + for (uint I=0;Src[I]!=0;I++) + if (Src[I]=='/' || Src[I]=='.') + SrcChars++; + for (uint I=0;Dest[I]!=0;I++) + if (Dest[I]=='/' || Dest[I]=='.') + DestChars++; + return SrcChars==DestChars; +} + + bool ExtractUnixLink30(CommandData *Cmd,ComprDataIO &DataIO,Archive &Arc,const wchar *LinkName) { char Target[NM]; @@ -72,12 +92,12 @@ bool ExtractUnixLink30(CommandData *Cmd,ComprDataIO &DataIO,Archive &Arc,const w return true; wchar TargetW[NM]; - CharToWide(Target,TargetW,ASIZE(TargetW)); - // Check for *TargetW==0 to catch CharToWide failure. + if (!SafeCharToWide(Target,TargetW,ASIZE(TargetW))) + return false; // Use Arc.FileHead.FileName instead of LinkName, since LinkName // can include the destination path as a prefix, which can // confuse IsRelativeSymlinkSafe algorithm. - if (!Cmd->AbsoluteLinks && (*TargetW==0 || IsFullPath(TargetW) || + if (!Cmd->AbsoluteLinks && (IsFullPath(TargetW) || !IsRelativeSymlinkSafe(Cmd,Arc.FileHead.FileName,LinkName,TargetW))) return false; return UnixSymlink(Cmd,Target,LinkName,&Arc.FileHead.mtime,&Arc.FileHead.atime); @@ -100,11 +120,17 @@ bool ExtractUnixLink50(CommandData *Cmd,const wchar *Name,FileHeader *hd) return false; DosSlashToUnix(Target,Target,ASIZE(Target)); } + + wchar TargetW[NM]; + if (!SafeCharToWide(Target,TargetW,ASIZE(TargetW))) + return false; // Use hd->FileName instead of LinkName, since LinkName can include // the destination path as a prefix, which can confuse // IsRelativeSymlinkSafe algorithm. - if (!Cmd->AbsoluteLinks && (IsFullPath(Target) || - !IsRelativeSymlinkSafe(Cmd,hd->FileName,Name,hd->RedirName))) + // 2022.05.04: Use TargetW instead of previously used hd->RedirName + // for security reason. + if (!Cmd->AbsoluteLinks && (IsFullPath(TargetW) || + !IsRelativeSymlinkSafe(Cmd,hd->FileName,Name,TargetW))) return false; return UnixSymlink(Cmd,Target,Name,&hd->mtime,&hd->atime); } diff --git a/unpack.hpp b/unpack.hpp index 75dadb0..30a9a2e 100644 --- a/unpack.hpp +++ b/unpack.hpp @@ -23,8 +23,8 @@ // allocation. Must be equal or larger than MAX_ANALYZE_SIZE. #define MAX_FILTER_BLOCK_SIZE 0x400000 -// Write data in 4 MB or smaller blocks. Must not exceed PACK_MAX_WRITE, -// so we keep a number of buffered filters in unpacker reasonable. +// Write data in 4 MB or smaller blocks. Must not exceed PACK_MAX_READ, +// so we keep the number of buffered filters in unpacker reasonable. #define UNPACK_MAX_WRITE 0x400000 // Decode compressed bit fields to alphabet numbers. diff --git a/version.hpp b/version.hpp index 0b62c1f..4807c9c 100644 --- a/version.hpp +++ b/version.hpp @@ -1,6 +1,6 @@ #define RARVER_MAJOR 6 -#define RARVER_MINOR 10 -#define RARVER_BETA 2 -#define RARVER_DAY 15 -#define RARVER_MONTH 11 -#define RARVER_YEAR 2021 +#define RARVER_MINOR 12 +#define RARVER_BETA 0 +#define RARVER_DAY 4 +#define RARVER_MONTH 5 +#define RARVER_YEAR 2022 diff --git a/volume.cpp b/volume.cpp index 1a5f1d0..917851d 100644 --- a/volume.cpp +++ b/volume.cpp @@ -25,10 +25,12 @@ bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName,wchar Comma uiMsg(UIERROR_CHECKSUMPACKED, Arc.FileName, hd->FileName); } + bool PrevVolEncrypted=Arc.Encrypted; + int64 PosBeforeClose=Arc.Tell(); if (DataIO!=NULL) - DataIO->ProcessedArcSize+=Arc.FileLength(); + DataIO->ProcessedArcSize+=DataIO->LastArcSize; Arc.Close(); @@ -44,15 +46,18 @@ bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName,wchar Comma bool FailedOpen=false; // No more next volume open attempts if true. #if !defined(SILENT) - if (Cmd->VolumePause) - { - // If next volume can't be opened exclusively, it might be still - // downloading, so in -vp mode user may prefer to pause until completion - // even if volume is exist. FMF_OPENEXCLUSIVE works in Windows only. - File TestOpen; - if (!TestOpen.Open(NextName,FMF_OPENEXCLUSIVE) && !uiAskNextVolume(NextName,ASIZE(NextName))) - FailedOpen=true; - } + // In -vp mode we force the pause before next volume even if it is present + // and even if we are on the hard disk. It is important when user does not + // want to process partially downloaded volumes preliminary. + // 2022.01.11: In WinRAR 6.10 beta versions we tried to ignore VolumePause + // if we could open the next volume with FMF_OPENEXCLUSIVE. But another + // developer asked us to return the previous behavior and always prompt + // for confirmation. They want to control when unrar continues, because + // the next file might not be fully decoded yet. They write chunks of data + // and then close the file again until the next chunk comes in. + + if (Cmd->VolumePause && !uiAskNextVolume(NextName,ASIZE(NextName))) + FailedOpen=true; #endif uint OpenMode = Cmd->OpenShared ? FMF_OPENSHARED : 0; @@ -132,6 +137,16 @@ bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName,wchar Comma return false; #endif + if (Arc.Encrypted!=PrevVolEncrypted) + { + // There is no legitimate reason for encrypted header state to be + // changed in the middle of volume sequence. So we abort here to prevent + // replacing an encrypted header volume to unencrypted and adding + // unexpected files by third party to encrypted extraction. + uiMsg(UIERROR_BADARCHIVE,Arc.FileName); + ErrHandler.Exit(RARX_FATAL); + } + if (SplitHeader) Arc.SearchBlock(HeaderType); else @@ -156,10 +171,9 @@ bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName,wchar Comma DataIO->UnpVolume=hd->SplitAfter; DataIO->SetPackedSizeToRead(hd->PackSize); } -#ifdef SFX_MODULE - DataIO->UnpArcSize=Arc.FileLength(); -#endif - + + DataIO->AdjustTotalArcSize(&Arc); + // Reset the size of packed data read from current volume. It is used // to display the total progress and preceding volumes are already // compensated with ProcessedArcSize, so we need to reset this variable.