From: <sv...@op...> - 2024-06-08 21:18:53
|
Author: sagamusix Date: Sat Jun 8 23:18:41 2024 New Revision: 20975 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20975 Log: Merged revision(s) 20974 from trunk/OpenMPT: [Var] unrar: Update to v7.0.9. ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/include/unrar/OpenMPT.txt branches/OpenMPT-1.31/include/unrar/arccmt.cpp branches/OpenMPT-1.31/include/unrar/arcread.cpp branches/OpenMPT-1.31/include/unrar/cmddata.cpp branches/OpenMPT-1.31/include/unrar/crypt.cpp branches/OpenMPT-1.31/include/unrar/crypt.hpp branches/OpenMPT-1.31/include/unrar/crypt5.cpp branches/OpenMPT-1.31/include/unrar/extract.cpp branches/OpenMPT-1.31/include/unrar/filefn.cpp branches/OpenMPT-1.31/include/unrar/isnt.cpp branches/OpenMPT-1.31/include/unrar/options.hpp branches/OpenMPT-1.31/include/unrar/os.hpp branches/OpenMPT-1.31/include/unrar/rdwrfn.cpp branches/OpenMPT-1.31/include/unrar/rdwrfn.hpp branches/OpenMPT-1.31/include/unrar/rijndael.cpp branches/OpenMPT-1.31/include/unrar/unpack15.cpp branches/OpenMPT-1.31/include/unrar/version.hpp Modified: branches/OpenMPT-1.31/include/unrar/OpenMPT.txt ============================================================================== --- branches/OpenMPT-1.31/include/unrar/OpenMPT.txt Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/OpenMPT.txt Sat Jun 8 23:18:41 2024 (r20975) @@ -1,4 +1,4 @@ -This folder is based on https://rarlab.com/rar/unrarsrc-7.0.7.tar.gz +This folder is based on https://rarlab.com/rar/unrarsrc-7.0.9.tar.gz All modifications to existing files have been done in a manner so that no existing lines were edited; only new lines were added. Modified: branches/OpenMPT-1.31/include/unrar/arccmt.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/arccmt.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/arccmt.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -101,9 +101,8 @@ // 4x memory for OEM to UTF-8 output here. OemToCharBuffA((char *)UnpData,(char *)UnpData,(DWORD)UnpDataSize); #endif -// CmtData.resize(UnpDataSize+1); - CharToWide((const char *)UnpData,CmtData); -// CmtData.resize(wcslen(CmtData->data())); + std::string UnpStr((char*)UnpData,UnpDataSize); + CharToWide(UnpStr,CmtData); } } } Modified: branches/OpenMPT-1.31/include/unrar/arcread.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/arcread.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/arcread.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -122,7 +122,7 @@ void Archive::UnkEncVerMsg(const std::wstring &Name,const std::wstring &Info) { uiMsg(UIERROR_UNKNOWNENCMETHOD,FileName,Name,Info); - ErrHandler.SetErrorCode(RARX_WARNING); + ErrHandler.SetErrorCode(RARX_FATAL); } @@ -587,10 +587,10 @@ RequestArcPassword(CheckPwd.IsSet() ? &CheckPwd:NULL); byte PswCheck[SIZE_PSWCHECK]; - HeadersCrypt.SetCryptKeys(false,CRYPT_RAR50,&Cmd->Password,CryptHead.Salt,HeadersInitV,CryptHead.Lg2Count,NULL,PswCheck); + bool EncSet=HeadersCrypt.SetCryptKeys(false,CRYPT_RAR50,&Cmd->Password,CryptHead.Salt,HeadersInitV,CryptHead.Lg2Count,NULL,PswCheck); // Verify password validity. If header is damaged, we cannot rely on // password check value, because it can be damaged too. - if (CryptHead.UsePswCheck && !BrokenHeader && + if (EncSet && CryptHead.UsePswCheck && !BrokenHeader && memcmp(PswCheck,CryptHead.PswCheck,SIZE_PSWCHECK)!=0) { if (GlobalPassword) // For -p<pwd> or Ctrl+P. @@ -1050,35 +1050,38 @@ hd->Lg2Count=Raw->Get1(); if (hd->Lg2Count>CRYPT5_KDF_LG2_COUNT_MAX) UnkEncVerMsg(hd->FileName,L"xc" + std::to_wstring(hd->Lg2Count)); - Raw->GetB(hd->Salt,SIZE_SALT50); - Raw->GetB(hd->InitV,SIZE_INITV); - if (hd->UsePswCheck) + else { - Raw->GetB(hd->PswCheck,SIZE_PSWCHECK); - - // It is important to know if password check data is valid. - // If it is damaged and header CRC32 fails to detect it, - // archiver would refuse to decompress a possibly valid file. - // Since we want to be sure distinguishing a wrong password - // or corrupt file data, we use 64-bit password check data - // and to control its validity we use 32 bits of password - // check data SHA-256 additionally to 32-bit header CRC32. - byte csum[SIZE_PSWCHECK_CSUM]; - Raw->GetB(csum,SIZE_PSWCHECK_CSUM); - - byte Digest[SHA256_DIGEST_SIZE]; - sha256_get(hd->PswCheck, SIZE_PSWCHECK, Digest); - - hd->UsePswCheck=memcmp(csum,Digest,SIZE_PSWCHECK_CSUM)==0; - - // RAR 5.21 and earlier set PswCheck field in service records to 0 - // even if UsePswCheck was present. - if (bb->HeaderType==HEAD_SERVICE && memcmp(hd->PswCheck,"\0\0\0\0\0\0\0\0",SIZE_PSWCHECK)==0) - hd->UsePswCheck=0; + Raw->GetB(hd->Salt,SIZE_SALT50); + Raw->GetB(hd->InitV,SIZE_INITV); + if (hd->UsePswCheck) + { + Raw->GetB(hd->PswCheck,SIZE_PSWCHECK); + + // It is important to know if password check data is valid. + // If it is damaged and header CRC32 fails to detect it, + // archiver would refuse to decompress a possibly valid file. + // Since we want to be sure distinguishing a wrong password + // or corrupt file data, we use 64-bit password check data + // and to control its validity we use 32 bits of password + // check data SHA-256 additionally to 32-bit header CRC32. + byte csum[SIZE_PSWCHECK_CSUM]; + Raw->GetB(csum,SIZE_PSWCHECK_CSUM); + + byte Digest[SHA256_DIGEST_SIZE]; + sha256_get(hd->PswCheck, SIZE_PSWCHECK, Digest); + + hd->UsePswCheck=memcmp(csum,Digest,SIZE_PSWCHECK_CSUM)==0; + + // RAR 5.21 and earlier set PswCheck field in service records to 0 + // even if UsePswCheck was present. + if (bb->HeaderType==HEAD_SERVICE && memcmp(hd->PswCheck,"\0\0\0\0\0\0\0\0",SIZE_PSWCHECK)==0) + hd->UsePswCheck=0; + } + hd->SaltSet=true; + hd->CryptMethod=CRYPT_RAR50; + hd->Encrypted=true; } - hd->SaltSet=true; - hd->CryptMethod=CRYPT_RAR50; - hd->Encrypted=true; } } break; Modified: branches/OpenMPT-1.31/include/unrar/cmddata.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/cmddata.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/cmddata.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -426,7 +426,7 @@ break; case '4': // Convert slashes here than before every comparison. - SlashToNative(Switch+3,ArcPath); + SlashToNative(Switch+3,ExclArcPath); break; default: BadSwitch(Switch); Modified: branches/OpenMPT-1.31/include/unrar/crypt.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/crypt.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/crypt.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -60,6 +60,8 @@ WideToChar(PwdW,PwdA,ASIZE(PwdA)); PwdA[Min(MAXPASSWORD_RAR,MAXPASSWORD)-1]=0; // For compatibility with existing archives. + bool Success=true; + switch(Method) { #ifndef SFX_MODULE @@ -77,12 +79,12 @@ SetKey30(Encrypt,Password,PwdW,Salt); break; case CRYPT_RAR50: - SetKey50(Encrypt,Password,PwdW,Salt,InitV,Lg2Cnt,HashKey,PswCheck); + Success=SetKey50(Encrypt,Password,PwdW,Salt,InitV,Lg2Cnt,HashKey,PswCheck); break; } cleandata(PwdA,sizeof(PwdA)); cleandata(PwdW,sizeof(PwdW)); - return true; + return Success; } Modified: branches/OpenMPT-1.31/include/unrar/crypt.hpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/crypt.hpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/crypt.hpp Sat Jun 8 23:18:41 2024 (r20975) @@ -79,7 +79,7 @@ void DecryptBlock20(byte *Buf); void SetKey30(bool Encrypt,SecPassword *Password,const wchar *PwdW,const byte *Salt); - void SetKey50(bool Encrypt,SecPassword *Password,const wchar *PwdW,const byte *Salt,const byte *InitV,uint Lg2Cnt,byte *HashKey,byte *PswCheck); + bool SetKey50(bool Encrypt,SecPassword *Password,const wchar *PwdW,const byte *Salt,const byte *InitV,uint Lg2Cnt,byte *HashKey,byte *PswCheck); KDF3CacheItem KDF3Cache[4]; uint KDF3CachePos; Modified: branches/OpenMPT-1.31/include/unrar/crypt5.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/crypt5.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/crypt5.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -128,20 +128,12 @@ } -void CryptData::SetKey50(bool Encrypt,SecPassword *Password,const wchar *PwdW, +bool CryptData::SetKey50(bool Encrypt,SecPassword *Password,const wchar *PwdW, const byte *Salt,const byte *InitV,uint Lg2Cnt,byte *HashKey, byte *PswCheck) { if (Lg2Cnt>CRYPT5_KDF_LG2_COUNT_MAX) - { - // Initialize these fields to prevent uninitialized data access warnings - // by analyzing tools when accessing returned data. - if (HashKey!=nullptr) - memset(HashKey,0,SHA256_DIGEST_SIZE); - if (PswCheck!=nullptr) - memset(PswCheck,0,SIZE_PSWCHECK); - return; - } + return false; byte Key[32],PswCheckValue[SHA256_DIGEST_SIZE],HashKeyValue[SHA256_DIGEST_SIZE]; bool Found=false; @@ -194,6 +186,7 @@ rin.Init(Encrypt, Key, 256, InitV); cleandata(Key,sizeof(Key)); + return true; } Modified: branches/OpenMPT-1.31/include/unrar/extract.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/extract.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/extract.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -586,14 +586,14 @@ #endif byte PswCheck[SIZE_PSWCHECK]; - DataIO.SetEncryption(false,Arc.FileHead.CryptMethod,&FilePassword, - Arc.FileHead.SaltSet ? Arc.FileHead.Salt:NULL, + bool EncSet=DataIO.SetEncryption(false,Arc.FileHead.CryptMethod, + &FilePassword,Arc.FileHead.SaltSet ? Arc.FileHead.Salt:nullptr, Arc.FileHead.InitV,Arc.FileHead.Lg2Count, Arc.FileHead.HashKey,PswCheck); // If header is damaged, we cannot rely on password check value, // because it can be damaged too. - if (Arc.FileHead.UsePswCheck && !Arc.BrokenHeader && + if (EncSet && Arc.FileHead.UsePswCheck && !Arc.BrokenHeader && memcmp(Arc.FileHead.PswCheck,PswCheck,SIZE_PSWCHECK)!=0) { if (GlobalPassword) // For -p<pwd> or Ctrl+P to avoid the infinite loop. @@ -968,7 +968,7 @@ if (SetTimeAndSize) { - // We could preallocate more space that really written to broken file + // We could preallocate more space than really written to broken file // or file with crafted header. if (Preallocated>0 && (BrokenFile || DataIO.CurUnpWrite!=Preallocated)) CurFile.Truncate(); Modified: branches/OpenMPT-1.31/include/unrar/filefn.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/filefn.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/filefn.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -239,8 +239,9 @@ { #if defined(_UNIX) && defined(S_ISFIFO) && defined(S_ISSOCK) && defined(S_ISCHR) return S_ISFIFO(Attr) || S_ISSOCK(Attr) || S_ISCHR(Attr); -#endif +#else return false; +#endif } Modified: branches/OpenMPT-1.31/include/unrar/isnt.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/isnt.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/isnt.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -40,7 +40,7 @@ IWbemServices *pSvc = NULL; - hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"),NULL,NULL,NULL,NULL,0,0,&pSvc); + hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"),NULL,NULL,NULL,0,NULL,NULL,&pSvc); if (FAILED(hres)) { Modified: branches/OpenMPT-1.31/include/unrar/options.hpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/options.hpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/options.hpp Sat Jun 8 23:18:41 2024 (r20975) @@ -33,7 +33,7 @@ RECURSE_NONE=0, // no recurse switches RECURSE_DISABLE, // switch -r- RECURSE_ALWAYS, // switch -r - RECURSE_WILDCARDS, // switch -r0 + RECURSE_WILDCARDS // switch -r0 }; enum OVERWRITE_MODE Modified: branches/OpenMPT-1.31/include/unrar/os.hpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/os.hpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/os.hpp Sat Jun 8 23:18:41 2024 (r20975) @@ -11,6 +11,7 @@ #include <new> #include <string> #include <vector> +#include <deque> #include <memory> // For automatic pointers. @@ -215,6 +216,10 @@ #endif #endif +#ifdef __VMS +# define LITTLE_ENDIAN +#endif + // Unlike Apple x64, utimensat shall be available in all Apple M1 systems. #if _POSIX_C_SOURCE >= 200809L || defined(__APPLE__) && defined(__arm64__) #define UNIX_TIME_NS // Nanosecond time precision in Unix. Modified: branches/OpenMPT-1.31/include/unrar/rdwrfn.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/rdwrfn.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/rdwrfn.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -249,15 +249,24 @@ } -void ComprDataIO::SetEncryption(bool Encrypt,CRYPT_METHOD Method, +// Return true if encryption or decryption mode is set correctly. +bool ComprDataIO::SetEncryption(bool Encrypt,CRYPT_METHOD Method, SecPassword *Password,const byte *Salt,const byte *InitV, uint Lg2Cnt,byte *HashKey,byte *PswCheck) { -#ifndef RAR_NOCRYPT +#ifdef RAR_NOCRYPT + return false; +#else if (Encrypt) + { Encryption=Crypt->SetCryptKeys(true,Method,Password,Salt,InitV,Lg2Cnt,HashKey,PswCheck); + return Encryption; + } else + { Decryption=Decrypt->SetCryptKeys(false,Method,Password,Salt,InitV,Lg2Cnt,HashKey,PswCheck); + return Decryption; + } #endif } Modified: branches/OpenMPT-1.31/include/unrar/rdwrfn.hpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/rdwrfn.hpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/rdwrfn.hpp Sat Jun 8 23:18:41 2024 (r20975) @@ -66,7 +66,7 @@ void SetFiles(File *SrcFile,File *DestFile); void SetCommand(CmdAdd *Cmd) {Command=Cmd;} void SetSubHeader(FileHeader *hd,int64 *Pos) {SubHead=hd;SubHeadPos=Pos;} - void SetEncryption(bool Encrypt,CRYPT_METHOD Method,SecPassword *Password, + bool SetEncryption(bool Encrypt,CRYPT_METHOD Method,SecPassword *Password, const byte *Salt,const byte *InitV,uint Lg2Cnt,byte *HashKey,byte *PswCheck); void SetCmt13Encryption(); void SetUnpackToMemory(byte *Addr,uint Size); Modified: branches/OpenMPT-1.31/include/unrar/rijndael.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/rijndael.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/rijndael.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -84,6 +84,7 @@ { if (S5[0]==0) GenerateTables(); + m_uRounds = 0; CBCMode = true; // Always true for RAR. #ifdef USE_SSE AES_NI=false; Modified: branches/OpenMPT-1.31/include/unrar/unpack15.cpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/unpack15.cpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/unpack15.cpp Sat Jun 8 23:18:41 2024 (r20975) @@ -474,7 +474,8 @@ void Unpack::CopyString15(uint Distance,uint Length) { DestUnpSize-=Length; - if (!FirstWinDone && Distance>UnpPtr || Distance>MaxWinSize) + // 2024.04.18: Distance can be 0 in corrupt RAR 1.5 archives. + if (!FirstWinDone && Distance>UnpPtr || Distance>MaxWinSize || Distance==0) while (Length-- > 0) { Window[UnpPtr]=0; Modified: branches/OpenMPT-1.31/include/unrar/version.hpp ============================================================================== --- branches/OpenMPT-1.31/include/unrar/version.hpp Sat Jun 8 23:18:13 2024 (r20974) +++ branches/OpenMPT-1.31/include/unrar/version.hpp Sat Jun 8 23:18:41 2024 (r20975) @@ -1,6 +1,6 @@ #define RARVER_MAJOR 7 -#define RARVER_MINOR 0 +#define RARVER_MINOR 1 #define RARVER_BETA 0 -#define RARVER_DAY 26 -#define RARVER_MONTH 2 +#define RARVER_DAY 12 +#define RARVER_MONTH 5 #define RARVER_YEAR 2024 |