Skip to content

Commit cb7782e

Browse files
committed
Update unrar to 7.1.5
1 parent a188e0e commit cb7782e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1182
-302
lines changed

vendor/unrar/arccmt.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ bool Archive::DoGetComment(std::wstring &CmtData)
3636
{
3737
// Current (RAR 3.0+) version of archive comment.
3838
Seek(GetStartPos(),SEEK_SET);
39-
return SearchSubBlock(SUBHEAD_TYPE_CMT)!=0 && ReadCommentData(CmtData);
39+
if (SearchSubBlock(SUBHEAD_TYPE_CMT)!=0)
40+
if (ReadCommentData(CmtData))
41+
return true;
42+
else
43+
uiMsg(UIERROR_CMTBROKEN,FileName);
44+
return false;
4045
}
4146
#ifndef SFX_MODULE
4247
// Old style (RAR 2.9) comment header embedded into the main

vendor/unrar/archive.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ Archive::Archive(CommandData *InitCmd)
2626
FailedHeaderDecryption=false;
2727
BrokenHeader=false;
2828
LastReadBlock=0;
29+
CurHeaderType=HEAD_UNKNOWN;
2930

3031
CurBlockPos=0;
3132
NextBlockPos=0;
3233

34+
RecoveryPercent=-1;
3335

3436
MainHead.Reset();
3537
CryptHead={};
@@ -67,7 +69,7 @@ void Archive::CheckArc(bool EnableBroken)
6769
// password is incorrect.
6870
if (!FailedHeaderDecryption)
6971
uiMsg(UIERROR_BADARCHIVE,FileName);
70-
ErrHandler.Exit(RARX_FATAL);
72+
ErrHandler.Exit(RARX_BADARC);
7173
}
7274
}
7375

@@ -109,9 +111,11 @@ RARFORMAT Archive::IsSignature(const byte *D,size_t Size)
109111
// We check the last signature byte, so we can return a sensible
110112
// warning in case we'll want to change the archive format
111113
// sometimes in the future.
114+
#ifndef SFX_MODULE
112115
if (D[6]==0)
113116
Type=RARFMT15;
114117
else
118+
#endif
115119
if (D[6]==1)
116120
Type=RARFMT50;
117121
else

vendor/unrar/archive.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Archive:public File
4747
bool DummyCmd;
4848
CommandData *Cmd;
4949

50+
int RecoveryPercent;
5051

5152
RarTime LatestTime;
5253
int LastReadBlock;
@@ -58,13 +59,14 @@ class Archive:public File
5859
bool ProhibitQOpen;
5960
#endif
6061
public:
61-
Archive(CommandData *InitCmd=NULL);
62+
Archive(CommandData *InitCmd=nullptr);
6263
~Archive();
6364
static RARFORMAT IsSignature(const byte *D,size_t Size);
6465
bool IsArchive(bool EnableBroken);
6566
size_t SearchBlock(HEADER_TYPE HeaderType);
6667
size_t SearchSubBlock(const wchar *Type);
6768
size_t SearchRR();
69+
int GetRecoveryPercent() {return RecoveryPercent;}
6870
size_t ReadHeader();
6971
void CheckArc(bool EnableBroken);
7072
void CheckOpen(const std::wstring &Name);
@@ -147,6 +149,9 @@ class Archive:public File
147149
bool NewArchive;
148150

149151
std::wstring FirstVolumeName;
152+
#ifdef PROPAGATE_MOTW
153+
MarkOfTheWeb Motw;
154+
#endif
150155
};
151156

152157

vendor/unrar/arcread.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ size_t Archive::ReadHeader()
2020
case RARFMT14:
2121
ReadSize=ReadHeader14();
2222
break;
23-
#endif
2423
case RARFMT15:
2524
ReadSize=ReadHeader15();
2625
break;
26+
#endif
2727
case RARFMT50:
2828
ReadSize=ReadHeader50();
2929
break;
@@ -106,6 +106,9 @@ void Archive::UnexpEndArcMsg()
106106
if (CurBlockPos!=ArcSize || NextBlockPos!=ArcSize)
107107
{
108108
uiMsg(UIERROR_UNEXPEOF,FileName);
109+
if (CurHeaderType!=HEAD_FILE && CurHeaderType!=HEAD_UNKNOWN)
110+
uiMsg(UIERROR_TRUNCSERVICE,FileName,SubHead.FileName);
111+
109112
ErrHandler.SetErrorCode(RARX_WARNING);
110113
}
111114
}
@@ -137,6 +140,7 @@ inline int64 SafeAdd(int64 v1,int64 v2,int64 f)
137140
}
138141

139142

143+
#ifndef SFX_MODULE
140144
size_t Archive::ReadHeader15()
141145
{
142146
RawRead Raw(this);
@@ -145,7 +149,7 @@ size_t Archive::ReadHeader15()
145149

146150
if (Decrypt)
147151
{
148-
#ifdef RAR_NOCRYPT // For rarext.dll and unrar_nocrypt.dll.
152+
#ifdef RAR_NOCRYPT // For rarext.dll, Setup.SFX and unrar_nocrypt.dll.
149153
return 0;
150154
#else
151155
RequestArcPassword(NULL);
@@ -545,6 +549,7 @@ size_t Archive::ReadHeader15()
545549

546550
return Raw.Size();
547551
}
552+
#endif // #ifndef SFX_MODULE
548553

549554

550555
size_t Archive::ReadHeader50()
@@ -740,10 +745,15 @@ size_t Archive::ReadHeader50()
740745
byte csum[SIZE_PSWCHECK_CSUM];
741746
Raw.GetB(csum,SIZE_PSWCHECK_CSUM);
742747

748+
// Exclude this code for rarext.dll, Setup.SFX and unrar_nocrypt.dll linked
749+
// without sha256. But still set Encrypted=true for rarext.dll here,
750+
// so it can recognize encrypted header archives in archive properties.
751+
#ifndef RAR_NOCRYPT
743752
byte Digest[SHA256_DIGEST_SIZE];
744753
sha256_get(CryptHead.PswCheck, SIZE_PSWCHECK, Digest);
745754

746755
CryptHead.UsePswCheck=memcmp(csum,Digest,SIZE_PSWCHECK_CSUM)==0;
756+
#endif
747757
}
748758
Encrypted=true;
749759
}
@@ -894,6 +904,16 @@ size_t Archive::ReadHeader50()
894904
if (!FileBlock && hd->CmpName(SUBHEAD_TYPE_CMT))
895905
MainComment=true;
896906

907+
// For RAR5 format we read the user specified recovery percent here.
908+
if (!FileBlock && hd->CmpName(SUBHEAD_TYPE_RR) && hd->SubData.size()>0)
909+
{
910+
// It is stored as a single byte up to RAR 6.02 and as vint since
911+
// 6.10, where we extended the maximum RR size from 99% to 1000%.
912+
RawRead RawPercent;
913+
RawPercent.Read(hd->SubData.data(),hd->SubData.size());
914+
RecoveryPercent=(int)RawPercent.GetV();
915+
916+
}
897917

898918
if (BadCRC) // Add the file name to broken header message displayed above.
899919
uiMsg(UIERROR_FHEADERBROKEN,Archive::FileName,hd->FileName);
@@ -1036,22 +1056,30 @@ void Archive::ProcessExtra50(RawRead *Raw,size_t ExtraSize,const BaseBlock *bb)
10361056
FileHeader *hd=(FileHeader *)bb;
10371057
switch(FieldType)
10381058
{
1059+
#ifndef RAR_NOCRYPT // Except rarext.dll, Setup.SFX and unrar_nocrypt.dll.
10391060
case FHEXTRA_CRYPT:
10401061
{
10411062
FileHeader *hd=(FileHeader *)bb;
10421063
uint EncVersion=(uint)Raw->GetV();
10431064
if (EncVersion>CRYPT_VERSION)
1065+
{
10441066
UnkEncVerMsg(hd->FileName,L"x" + std::to_wstring(EncVersion));
1067+
hd->CryptMethod=CRYPT_UNKNOWN;
1068+
}
10451069
else
10461070
{
10471071
uint Flags=(uint)Raw->GetV();
1048-
hd->UsePswCheck=(Flags & FHEXTRA_CRYPT_PSWCHECK)!=0;
1049-
hd->UseHashKey=(Flags & FHEXTRA_CRYPT_HASHMAC)!=0;
10501072
hd->Lg2Count=Raw->Get1();
10511073
if (hd->Lg2Count>CRYPT5_KDF_LG2_COUNT_MAX)
1074+
{
10521075
UnkEncVerMsg(hd->FileName,L"xc" + std::to_wstring(hd->Lg2Count));
1076+
hd->CryptMethod=CRYPT_UNKNOWN;
1077+
}
10531078
else
10541079
{
1080+
hd->UsePswCheck=(Flags & FHEXTRA_CRYPT_PSWCHECK)!=0;
1081+
hd->UseHashKey=(Flags & FHEXTRA_CRYPT_HASHMAC)!=0;
1082+
10551083
Raw->GetB(hd->Salt,SIZE_SALT50);
10561084
Raw->GetB(hd->InitV,SIZE_INITV);
10571085
if (hd->UsePswCheck)
@@ -1085,6 +1113,7 @@ void Archive::ProcessExtra50(RawRead *Raw,size_t ExtraSize,const BaseBlock *bb)
10851113
}
10861114
}
10871115
break;
1116+
#endif
10881117
case FHEXTRA_HASH:
10891118
{
10901119
FileHeader *hd=(FileHeader *)bb;
@@ -1289,7 +1318,7 @@ size_t Archive::ReadHeader14()
12891318
std::string FileName(NameSize,0);
12901319
Raw.GetB((byte *)&FileName[0],NameSize);
12911320
std::string NameA;
1292-
IntToExt(FileName,NameA);
1321+
OemToExt(FileName,NameA);
12931322
CharToWide(NameA,FileHead.FileName);
12941323
ConvertNameCase(FileHead.FileName);
12951324
ConvertFileHeader(&FileHead);

vendor/unrar/blake2s.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
#define BLAKE2_DIGEST_SIZE 32
66
#define BLAKE2_THREADS_NUMBER 8
77

8-
enum blake2s_constant
9-
{
10-
BLAKE2S_BLOCKBYTES = 64,
11-
BLAKE2S_OUTBYTES = 32
12-
};
13-
8+
// Use constexpr instead of enums for -std=c++20 compatibility.
9+
constexpr size_t BLAKE2S_BLOCKBYTES = 64;
10+
constexpr size_t BLAKE2S_OUTBYTES = 32;
1411

1512
// Alignment to 64 improves performance of both SSE and non-SSE versions.
1613
// Alignment to n*16 is required for SSE version, so we selected 64.

vendor/unrar/cmddata.cpp

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ void CommandData::Init()
3838
InclArgs.Reset();
3939
ArcNames.Reset();
4040
StoreArgs.Reset();
41+
#ifdef PROPAGATE_MOTW
42+
MotwList.Reset();
43+
#endif
4144
Password.Clean();
4245
NextVolSizes.clear();
4346
#ifdef RARDLL
@@ -189,7 +192,7 @@ void CommandData::ParseDone()
189192
#if !defined(SFX_MODULE)
190193
void CommandData::ParseEnvVar()
191194
{
192-
char *EnvVar=getenv("RAR");
195+
char *EnvVar=getenv("RARINISWITCHES");
193196
if (EnvVar!=NULL)
194197
{
195198
std::wstring EnvStr;
@@ -293,6 +296,9 @@ void CommandData::ProcessSwitchesString(const std::wstring &Str)
293296
void CommandData::ProcessSwitch(const wchar *Switch)
294297
{
295298

299+
if (LargePageAlloc::ProcessSwitch(this,Switch))
300+
return;
301+
296302
switch(toupperw(Switch[0]))
297303
{
298304
case '@':
@@ -619,8 +625,6 @@ void CommandData::ProcessSwitch(const wchar *Switch)
619625
}
620626
}
621627
break;
622-
case 'M':
623-
break;
624628
case 'D':
625629
{
626630
bool SetDictLimit=toupperw(Switch[2])=='X';
@@ -665,33 +669,30 @@ void CommandData::ProcessSwitch(const wchar *Switch)
665669
if (toupperw(Switch[2])=='S' && Switch[3]==0)
666670
SkipEncrypted=true;
667671
break;
668-
case 'S':
672+
case 'L':
673+
if (toupperw(Switch[2])=='P')
669674
{
670-
std::wstring StoreNames=(Switch[2]==0 ? DefaultStoreList:Switch+2);
671-
size_t Pos=0;
672-
while (Pos<StoreNames.size())
675+
UseLargePages=true;
676+
if (!LargePageAlloc::IsPrivilegeAssigned() && LargePageAlloc::AssignConfirmation())
673677
{
674-
if (StoreNames[Pos]=='.')
675-
Pos++;
676-
size_t EndPos=StoreNames.find(';',Pos);
677-
std::wstring Mask=StoreNames.substr(Pos,EndPos==std::wstring::npos ? EndPos:EndPos-Pos);
678-
if (Mask.find_first_of(L"*?.")==std::wstring::npos)
679-
Mask.insert(0,L"*.");
680-
StoreArgs.AddString(Mask);
681-
if (EndPos==std::wstring::npos)
682-
break;
683-
Pos=EndPos+1;
678+
LargePageAlloc::AssignPrivilege();
679+
680+
// Quit immediately. We do not want to interrupt the current copy
681+
// archive processing with reboot after assigning privilege.
682+
SetupComplete=true;
684683
}
685684
}
686685
break;
686+
case 'M':
687+
break;
688+
case 'S':
689+
GetBriefMaskList(Switch[2]==0 ? DefaultStoreList:Switch+2,StoreArgs);
690+
break;
687691
#ifdef RAR_SMP
688692
case 'T':
689693
Threads=atoiw(Switch+2);
690694
if (Threads>MaxPoolThreads || Threads<1)
691695
BadSwitch(Switch);
692-
else
693-
{
694-
}
695696
break;
696697
#endif
697698
default:
@@ -752,6 +753,18 @@ void CommandData::ProcessSwitch(const wchar *Switch)
752753
}
753754
break;
754755
#endif
756+
#ifdef PROPAGATE_MOTW
757+
case 'M':
758+
{
759+
MotwAllFields=Switch[2]=='1';
760+
const wchar *Sep=wcschr(Switch+2,'=');
761+
if (Switch[2]=='-')
762+
MotwList.Reset();
763+
else
764+
GetBriefMaskList(Sep==nullptr ? L"*":Sep+1,MotwList);
765+
}
766+
break;
767+
#endif
755768
#ifdef _WIN_ALL
756769
case 'N':
757770
if (toupperw(Switch[2])=='I')
@@ -1033,6 +1046,11 @@ void CommandData::ProcessCommand()
10331046
#ifndef SFX_MODULE
10341047

10351048
const wchar *SingleCharCommands=L"FUADPXETK";
1049+
1050+
// RAR -mlp command is the legitimate way to assign the required privilege.
1051+
if (Command.empty() && UseLargePages || SetupComplete)
1052+
return;
1053+
10361054
if (Command[0]!=0 && Command[1]!=0 && wcschr(SingleCharCommands,Command[0])!=NULL || ArcName.empty())
10371055
OutHelp(Command.empty() ? RARX_SUCCESS:RARX_USERERROR); // Return 'success' for 'rar' without parameters.
10381056

@@ -1096,8 +1114,18 @@ void CommandData::ProcessCommand()
10961114
OutHelp(RARX_USERERROR);
10971115
#endif
10981116
}
1117+
1118+
// Since messages usually include '\n' in the beginning, we also issue
1119+
// the final '\n'. It is especially important in Unix, where otherwise
1120+
// the shell can display the prompt on the same line as the last message.
1121+
// mprintf is blocked with -idq and if error messages had been displayed
1122+
// in this mode, we use eprintf to separate them from shell prompt.
1123+
// If nothing was displayed with -idq, we avoid the excessive empty line.
10991124
if (!BareOutput)
1100-
mprintf(L"\n");
1125+
if (MsgStream==MSG_ERRONLY && IsConsoleOutputPresent())
1126+
eprintf(L"\n");
1127+
else
1128+
mprintf(L"\n");
11011129
}
11021130

11031131

@@ -1231,5 +1259,25 @@ int64 CommandData::GetVolSize(const wchar *S,uint DefMultiplier)
12311259
}
12321260

12331261

1262+
// Treat the list like rar;zip as *.rar;*.zip for -ms and similar switches.
1263+
void CommandData::GetBriefMaskList(const std::wstring &Masks,StringList &Args)
1264+
{
1265+
size_t Pos=0;
1266+
while (Pos<Masks.size())
1267+
{
1268+
if (Masks[Pos]=='.')
1269+
Pos++;
1270+
size_t EndPos=Masks.find(';',Pos);
1271+
std::wstring Mask=Masks.substr(Pos,EndPos==std::wstring::npos ? EndPos:EndPos-Pos);
1272+
if (Mask.find_first_of(L"*?.")==std::wstring::npos)
1273+
Mask.insert(0,L"*.");
1274+
Args.AddString(Mask);
1275+
if (EndPos==std::wstring::npos)
1276+
break;
1277+
Pos=EndPos+1;
1278+
}
1279+
}
1280+
1281+
12341282

12351283

0 commit comments

Comments
 (0)