Skip to content

Commit 5d70d0b

Browse files
Update unrar from 5.71 to 5.91 (#1606)
1 parent 288a899 commit 5d70d0b

Some content is hidden

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

51 files changed

+374
-278
lines changed

vendor/unrar/arccmt.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ bool Archive::GetComment(Array<wchar> *CmtData)
44
{
55
if (!MainComment)
66
return false;
7-
SaveFilePos SavePos(*this);
7+
int64 SavePos=Tell();
8+
bool Success=DoGetComment(CmtData);
9+
Seek(SavePos,SEEK_SET);
10+
return Success;
11+
}
12+
813

14+
bool Archive::DoGetComment(Array<wchar> *CmtData)
15+
{
916
#ifndef SFX_MODULE
1017
uint CmtLength;
1118
if (Format==RARFMT14)
@@ -136,7 +143,7 @@ bool Archive::GetComment(Array<wchar> *CmtData)
136143
bool Archive::ReadCommentData(Array<wchar> *CmtData)
137144
{
138145
Array<byte> CmtRaw;
139-
if (!ReadSubData(&CmtRaw,NULL))
146+
if (!ReadSubData(&CmtRaw,NULL,false))
140147
return false;
141148
size_t CmtSize=CmtRaw.Size();
142149
CmtRaw.Push(0);

vendor/unrar/archive.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ bool Archive::IsArchive(bool EnableBroken)
208208
break;
209209
}
210210

211-
// This check allows to make RS based recovery even if password is incorrect.
212-
// But we should not do it for EnableBroken or we'll get 'not RAR archive'
211+
212+
// We should not do it for EnableBroken or we'll get 'not RAR archive'
213213
// messages when extracting encrypted archives with wrong password.
214214
if (FailedHeaderDecryption && !EnableBroken)
215215
return false;
@@ -233,7 +233,7 @@ bool Archive::IsArchive(bool EnableBroken)
233233
// immediately after IsArchive call.
234234
if (HeadersLeft && (!SilentOpen || !Encrypted))
235235
{
236-
SaveFilePos SavePos(*this);
236+
int64 SavePos=Tell();
237237
int64 SaveCurBlockPos=CurBlockPos,SaveNextBlockPos=NextBlockPos;
238238
HEADER_TYPE SaveCurHeaderType=CurHeaderType;
239239

@@ -262,6 +262,7 @@ bool Archive::IsArchive(bool EnableBroken)
262262
CurBlockPos=SaveCurBlockPos;
263263
NextBlockPos=SaveNextBlockPos;
264264
CurHeaderType=SaveCurHeaderType;
265+
Seek(SavePos,SEEK_SET);
265266
}
266267
if (!Volume || FirstVolume)
267268
wcsncpyz(FirstVolumeName,FileName,ASIZE(FirstVolumeName));

vendor/unrar/archive.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class Archive:public File
2929
void UpdateLatestTime(FileHeader *CurBlock);
3030
void ConvertNameCase(wchar *Name);
3131
void ConvertFileHeader(FileHeader *hd);
32-
void WriteBlock50(HEADER_TYPE HeaderType,BaseBlock *wb,bool OnlySetSize,bool NonFinalWrite);
3332
size_t ReadHeader14();
3433
size_t ReadHeader15();
3534
size_t ReadHeader50();
@@ -38,6 +37,7 @@ class Archive:public File
3837
void UnexpEndArcMsg();
3938
void BrokenHeaderMsg();
4039
void UnkEncVerMsg(const wchar *Name,const wchar *Info);
40+
bool DoGetComment(Array<wchar> *CmtData);
4141
bool ReadCommentData(Array<wchar> *CmtData);
4242

4343
#if !defined(RAR_NOCRYPT)
@@ -65,8 +65,6 @@ class Archive:public File
6565
size_t SearchBlock(HEADER_TYPE HeaderType);
6666
size_t SearchSubBlock(const wchar *Type);
6767
size_t SearchRR();
68-
void WriteBlock(HEADER_TYPE HeaderType,BaseBlock *wb=NULL,bool OnlySetSize=false,bool NonFinalWrite=false);
69-
void SetBlockSize(HEADER_TYPE HeaderType,BaseBlock *wb=NULL) {WriteBlock(HeaderType,wb,true);}
7068
size_t ReadHeader();
7169
void CheckArc(bool EnableBroken);
7270
void CheckOpen(const wchar *Name);
@@ -83,7 +81,7 @@ class Archive:public File
8381
int64 GetStartPos();
8482
void AddSubData(byte *SrcData,uint64 DataSize,File *SrcFile,
8583
const wchar *Name,uint Flags);
86-
bool ReadSubData(Array<byte> *UnpData,File *DestFile);
84+
bool ReadSubData(Array<byte> *UnpData,File *DestFile,bool TestMode);
8785
HEADER_TYPE GetHeaderType() {return CurHeaderType;}
8886
RAROptions* GetRAROptions() {return Cmd;}
8987
void SetSilentOpen(bool Mode) {SilentOpen=Mode;}

vendor/unrar/arcread.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ size_t Archive::ReadHeader15()
268268
uint FileTime=Raw.Get4();
269269
hd->UnpVer=Raw.Get1();
270270

271-
// RAR15 did not use the special dictionary size to mark dirs.
272-
if (hd->UnpVer<20 && (hd->FileAttr & 0x10)!=0)
273-
hd->Dir=true;
274-
275271
hd->Method=Raw.Get1()-0x30;
276272
size_t NameSize=Raw.Get2();
277273
hd->FileAttr=Raw.Get4();
278274

275+
// RAR15 did not use the special dictionary size to mark dirs.
276+
if (hd->UnpVer<20 && (hd->FileAttr & 0x10)!=0)
277+
hd->Dir=true;
278+
279279
hd->CryptMethod=CRYPT_NONE;
280280
if (hd->Encrypted)
281281
switch(hd->UnpVer)
@@ -402,8 +402,8 @@ size_t Archive::ReadHeader15()
402402
if (rmode & 4)
403403
rlt.Second++;
404404
rlt.Reminder=0;
405-
int count=rmode&3;
406-
for (int J=0;J<count;J++)
405+
uint count=rmode&3;
406+
for (uint J=0;J<count;J++)
407407
{
408408
byte CurByte=Raw.Get1();
409409
rlt.Reminder|=(((uint)CurByte)<<((J+3-count)*8));
@@ -521,7 +521,6 @@ size_t Archive::ReadHeader15()
521521
{
522522
// Last 7 bytes of recovered volume can contain zeroes, because
523523
// REV files store its own information (volume number, etc.) here.
524-
SaveFilePos SavePos(*this);
525524
int64 Length=Tell();
526525
Seek(Length-7,SEEK_SET);
527526
Recovered=true;
@@ -584,7 +583,7 @@ size_t Archive::ReadHeader50()
584583
{
585584
// This message is used by Android GUI to reset cached passwords.
586585
// Update appropriate code if changed.
587-
uiMsg(UIERROR_BADPSW,FileName);
586+
uiMsg(UIERROR_BADPSW,FileName,FileName);
588587
FailedHeaderDecryption=true;
589588
ErrHandler.SetErrorCode(RARX_BADPWD);
590589
return 0;
@@ -593,7 +592,7 @@ size_t Archive::ReadHeader50()
593592
{
594593
// This message is used by Android GUI and Windows GUI and SFX to
595594
// reset cached passwords. Update appropriate code if changed.
596-
uiMsg(UIWAIT_BADPSW,FileName);
595+
uiMsg(UIWAIT_BADPSW,FileName,FileName);
597596
Cmd->Password.Clean();
598597
}
599598

@@ -720,6 +719,7 @@ size_t Archive::ReadHeader50()
720719
UnkEncVerMsg(FileName,Info);
721720
return 0;
722721
}
722+
723723
Raw.GetB(CryptHead.Salt,SIZE_SALT50);
724724
if (CryptHead.UsePswCheck)
725725
{
@@ -1256,11 +1256,13 @@ size_t Archive::ReadHeader14()
12561256
Raw.Read(NameSize);
12571257

12581258
char FileName[NM];
1259-
Raw.GetB((byte *)FileName,Min(NameSize,ASIZE(FileName)));
1260-
FileName[NameSize]=0;
1259+
size_t ReadNameSize=Min(NameSize,ASIZE(FileName)-1);
1260+
Raw.GetB((byte *)FileName,ReadNameSize);
1261+
FileName[ReadNameSize]=0;
12611262
IntToExt(FileName,FileName,ASIZE(FileName));
12621263
CharToWide(FileName,FileHead.FileName,ASIZE(FileHead.FileName));
12631264
ConvertNameCase(FileHead.FileName);
1265+
ConvertFileHeader(&FileHead);
12641266

12651267
if (Raw.Size()!=0)
12661268
NextBlockPos=CurBlockPos+FileHead.HeadSize+FileHead.PackSize;
@@ -1414,7 +1416,7 @@ int64 Archive::GetStartPos()
14141416
}
14151417

14161418

1417-
bool Archive::ReadSubData(Array<byte> *UnpData,File *DestFile)
1419+
bool Archive::ReadSubData(Array<byte> *UnpData,File *DestFile,bool TestMode)
14181420
{
14191421
if (BrokenHeader)
14201422
{
@@ -1462,6 +1464,7 @@ bool Archive::ReadSubData(Array<byte> *UnpData,File *DestFile)
14621464
SubDataIO.SetPackedSizeToRead(SubHead.PackSize);
14631465
SubDataIO.EnableShowProgress(false);
14641466
SubDataIO.SetFiles(this,DestFile);
1467+
SubDataIO.SetTestMode(TestMode);
14651468
SubDataIO.UnpVolume=SubHead.SplitAfter;
14661469
SubDataIO.SetSubHeader(&SubHead,NULL);
14671470
Unpack.SetDestSize(SubHead.UnpSize);

vendor/unrar/blake2s.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _RAR_BLAKE2_
44

55
#define BLAKE2_DIGEST_SIZE 32
6+
#define BLAKE2_THREADS_NUMBER 8
67

78
enum blake2s_constant
89
{

vendor/unrar/cmddata.cpp

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,13 @@ void CommandData::ProcessSwitch(const wchar *Switch)
295295
if (Switch[2]=='-' && Switch[3]==0)
296296
GenerateArcName=0;
297297
else
298-
{
299-
GenerateArcName=true;
300-
wcsncpyz(GenerateMask,Switch+2,ASIZE(GenerateMask));
301-
}
298+
if (toupperw(Switch[2])=='F')
299+
wcsncpyz(DefGenerateMask,Switch+3,ASIZE(DefGenerateMask));
300+
else
301+
{
302+
GenerateArcName=true;
303+
wcsncpyz(GenerateMask,Switch+2,ASIZE(GenerateMask));
304+
}
302305
break;
303306
#endif
304307
case 'I':
@@ -373,11 +376,11 @@ void CommandData::ProcessSwitch(const wchar *Switch)
373376
default:
374377
if (Switch[1]=='+')
375378
{
376-
InclFileAttr|=GetExclAttr(Switch+2);
379+
InclFileAttr|=GetExclAttr(Switch+2,InclDir);
377380
InclAttrSet=true;
378381
}
379382
else
380-
ExclFileAttr|=GetExclAttr(Switch+1);
383+
ExclFileAttr|=GetExclAttr(Switch+1,ExclDir);
381384
break;
382385
}
383386
break;
@@ -825,39 +828,7 @@ void CommandData::ProcessSwitch(const wchar *Switch)
825828
SetTimeFilters(Switch+2,false,false);
826829
break;
827830
case 'S':
828-
{
829-
EXTTIME_MODE Mode=EXTTIME_HIGH3;
830-
bool CommonMode=Switch[2]>='0' && Switch[2]<='4';
831-
if (CommonMode)
832-
Mode=(EXTTIME_MODE)(Switch[2]-'0');
833-
if (Mode==EXTTIME_HIGH1 || Mode==EXTTIME_HIGH2) // '2' and '3' not supported anymore.
834-
Mode=EXTTIME_HIGH3;
835-
if (Switch[2]=='-')
836-
Mode=EXTTIME_NONE;
837-
if (CommonMode || Switch[2]=='-' || Switch[2]=='+' || Switch[2]==0)
838-
xmtime=xctime=xatime=Mode;
839-
else
840-
{
841-
if (Switch[3]>='0' && Switch[3]<='4')
842-
Mode=(EXTTIME_MODE)(Switch[3]-'0');
843-
if (Mode==EXTTIME_HIGH1 || Mode==EXTTIME_HIGH2) // '2' and '3' not supported anymore.
844-
Mode=EXTTIME_HIGH3;
845-
if (Switch[3]=='-')
846-
Mode=EXTTIME_NONE;
847-
switch(toupperw(Switch[2]))
848-
{
849-
case 'M':
850-
xmtime=Mode;
851-
break;
852-
case 'C':
853-
xctime=Mode;
854-
break;
855-
case 'A':
856-
xatime=Mode;
857-
break;
858-
}
859-
}
860-
}
831+
SetStoreTimeMode(Switch+2);
861832
break;
862833
case '-':
863834
Test=false;
@@ -960,7 +931,10 @@ void CommandData::ProcessCommand()
960931
if (wcschr(L"AFUMD",*Command)==NULL)
961932
{
962933
if (GenerateArcName)
963-
GenerateArchiveName(ArcName,ASIZE(ArcName),GenerateMask,false);
934+
{
935+
const wchar *Mask=*GenerateMask!=0 ? GenerateMask:DefGenerateMask;
936+
GenerateArchiveName(ArcName,ASIZE(ArcName),Mask,false);
937+
}
964938

965939
StringList ArcMasks;
966940
ArcMasks.AddString(ArcName);
@@ -979,7 +953,6 @@ void CommandData::ProcessCommand()
979953
case 'X':
980954
case 'E':
981955
case 'T':
982-
case 'I':
983956
{
984957
CmdExtract Extract(this);
985958
Extract.DoExtract();
@@ -1022,7 +995,7 @@ bool CommandData::IsSwitch(int Ch)
1022995

1023996

1024997
#ifndef SFX_MODULE
1025-
uint CommandData::GetExclAttr(const wchar *Str)
998+
uint CommandData::GetExclAttr(const wchar *Str,bool &Dir)
1026999
{
10271000
if (IsDigit(*Str))
10281001
return wcstol(Str,NULL,0);
@@ -1032,10 +1005,10 @@ uint CommandData::GetExclAttr(const wchar *Str)
10321005
{
10331006
switch(toupperw(*Str))
10341007
{
1035-
#ifdef _UNIX
10361008
case 'D':
1037-
Attr|=S_IFDIR;
1009+
Dir=true;
10381010
break;
1011+
#ifdef _UNIX
10391012
case 'V':
10401013
Attr|=S_IFCHR;
10411014
break;
@@ -1049,9 +1022,6 @@ uint CommandData::GetExclAttr(const wchar *Str)
10491022
case 'S':
10501023
Attr|=0x4;
10511024
break;
1052-
case 'D':
1053-
Attr|=0x10;
1054-
break;
10551025
case 'A':
10561026
Attr|=0x20;
10571027
break;

vendor/unrar/cmddata.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ class CommandData:public RAROptions
1414
void ProcessSwitchesString(const wchar *Str);
1515
void ProcessSwitch(const wchar *Switch);
1616
void BadSwitch(const wchar *Switch);
17-
uint GetExclAttr(const wchar *Str);
17+
uint GetExclAttr(const wchar *Str,bool &Dir);
1818
#if !defined(SFX_MODULE)
1919
void SetTimeFilters(const wchar *Mod,bool Before,bool Age);
20+
void SetStoreTimeMode(const wchar *S);
2021
#endif
2122

2223
bool FileLists;

vendor/unrar/cmdfilter.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,10 @@ int CommandData::IsProcessFile(FileHeader &FileHead,bool *ExactMatch,int MatchTy
285285
#ifndef SFX_MODULE
286286
if (TimeCheck(FileHead.mtime,FileHead.ctime,FileHead.atime))
287287
return 0;
288-
if ((FileHead.FileAttr & ExclFileAttr)!=0 || InclAttrSet && (FileHead.FileAttr & InclFileAttr)==0)
288+
if ((FileHead.FileAttr & ExclFileAttr)!=0 || FileHead.Dir && ExclDir)
289+
return 0;
290+
if (InclAttrSet && (!FileHead.Dir && (FileHead.FileAttr & InclFileAttr)==0 ||
291+
FileHead.Dir && !InclDir))
289292
return 0;
290293
if (!Dir && SizeCheck(FileHead.UnpSize))
291294
return 0;
@@ -303,3 +306,47 @@ int CommandData::IsProcessFile(FileHeader &FileHead,bool *ExactMatch,int MatchTy
303306
}
304307
return 0;
305308
}
309+
310+
311+
#if !defined(SFX_MODULE)
312+
void CommandData::SetStoreTimeMode(const wchar *S)
313+
{
314+
if (*S==0 || IsDigit(*S) || *S=='-' || *S=='+')
315+
{
316+
// Apply -ts, -ts1, -ts-, -ts+ to all 3 times.
317+
// Handle obsolete -ts[2,3,4] as ts+.
318+
EXTTIME_MODE Mode=EXTTIME_MAX;
319+
if (*S=='-')
320+
Mode=EXTTIME_NONE;
321+
if (*S=='1')
322+
Mode=EXTTIME_1S;
323+
xmtime=xctime=xatime=Mode;
324+
S++;
325+
}
326+
327+
while (*S!=0)
328+
{
329+
EXTTIME_MODE Mode=EXTTIME_MAX;
330+
if (S[1]=='-')
331+
Mode=EXTTIME_NONE;
332+
if (S[1]=='1')
333+
Mode=EXTTIME_1S;
334+
switch(toupperw(*S))
335+
{
336+
case 'M':
337+
xmtime=Mode;
338+
break;
339+
case 'C':
340+
xctime=Mode;
341+
break;
342+
case 'A':
343+
xatime=Mode;
344+
break;
345+
case 'P':
346+
PreserveAtime=true;
347+
break;
348+
}
349+
S++;
350+
}
351+
}
352+
#endif

vendor/unrar/crc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ uint CRC32(uint StartCRC,const void *Addr,size_t Size)
7373
crc_tables[5][(byte)(StartCRC >> 16)] ^
7474
crc_tables[4][(byte)(StartCRC >> 24)] ^
7575
crc_tables[3][(byte) NextData ] ^
76-
crc_tables[2][(byte)(NextData >>8 ) ] ^
76+
crc_tables[2][(byte)(NextData >> 8) ] ^
7777
crc_tables[1][(byte)(NextData >> 16)] ^
7878
crc_tables[0][(byte)(NextData >> 24)];
7979
}

0 commit comments

Comments
 (0)