Skip to content

Commit e816959

Browse files
committed
Update unrar to 6.21
1 parent 09baa24 commit e816959

File tree

8 files changed

+84
-53
lines changed

8 files changed

+84
-53
lines changed

vendor/unrar/cmdfilter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ int CommandData::IsProcessFile(FileHeader &FileHead,bool *ExactMatch,int MatchTy
289289
return 0;
290290
if ((FileHead.FileAttr & ExclFileAttr)!=0 || FileHead.Dir && ExclDir)
291291
return 0;
292-
if (InclAttrSet && (!FileHead.Dir && (FileHead.FileAttr & InclFileAttr)==0 ||
293-
FileHead.Dir && !InclDir))
292+
if (InclAttrSet && (FileHead.FileAttr & InclFileAttr)==0 &&
293+
(!FileHead.Dir || !InclDir))
294294
return 0;
295295
if (!Dir && SizeCheck(FileHead.UnpSize))
296296
return 0;

vendor/unrar/crypt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool CryptData::SetCryptKeys(bool Encrypt,CRYPT_METHOD Method,
4747
SecPassword *Password,const byte *Salt,
4848
const byte *InitV,uint Lg2Cnt,byte *HashKey,byte *PswCheck)
4949
{
50-
if (!Password->IsSet() || Method==CRYPT_NONE)
50+
if (Method==CRYPT_NONE || !Password->IsSet())
5151
return false;
5252

5353
CryptData::Method=Method;

vendor/unrar/errhnd.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,13 @@ void ErrorHandler::OpenErrorMsg(const wchar *FileName)
169169

170170
void ErrorHandler::OpenErrorMsg(const wchar *ArcName,const wchar *FileName)
171171
{
172-
Wait(); // Keep GUI responsive if many files cannot be opened when archiving.
173172
uiMsg(UIERROR_FILEOPEN,ArcName,FileName);
174173
SysErrMsg();
175174
SetErrorCode(RARX_OPEN);
175+
176+
// Keep GUI responsive if many files cannot be opened when archiving.
177+
// Call after SysErrMsg to avoid modifying the error code and SysErrMsg text.
178+
Wait();
176179
}
177180

178181

vendor/unrar/extract.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ CmdExtract::CmdExtract(CommandData *Cmd)
3838

3939
CmdExtract::~CmdExtract()
4040
{
41-
ReleaseAnalyzeData();
41+
FreeAnalyzeData();
4242
delete Unp;
4343
delete Analyze;
4444
}
4545

4646

47-
void CmdExtract::ReleaseAnalyzeData()
47+
void CmdExtract::FreeAnalyzeData()
4848
{
4949
for (size_t I=0;I<RefList.Size();I++)
5050
{
@@ -638,6 +638,8 @@ bool CmdExtract::ExtractCurrentFile(Archive &Arc,size_t HeaderSize,bool &Repeat)
638638
break;
639639
}
640640
}
641+
else
642+
DataIO.SetEncryption(false,CRYPT_NONE,NULL,NULL,NULL,0,NULL,NULL);
641643

642644
#ifdef RARDLL
643645
if (*Cmd->DllDestName!=0)
@@ -1464,7 +1466,7 @@ bool CmdExtract::CheckUnpVer(Archive &Arc,const wchar *ArcFileName)
14641466
//
14651467
void CmdExtract::AnalyzeArchive(const wchar *ArcName,bool Volume,bool NewNumbering)
14661468
{
1467-
ReleaseAnalyzeData(); // If processing non-first archive in multiple archives set.
1469+
FreeAnalyzeData(); // If processing non-first archive in multiple archives set.
14681470

14691471
wchar *ArgName=Cmd->FileArgs.GetString();
14701472
Cmd->FileArgs.Rewind();
@@ -1479,10 +1481,16 @@ void CmdExtract::AnalyzeArchive(const wchar *ArcName,bool Volume,bool NewNumberi
14791481
wcsncpyz(NextName,ArcName,ASIZE(NextName));
14801482

14811483
bool MatchFound=false;
1482-
bool FirstVolume=true;
14831484
bool PrevMatched=false;
14841485
bool OpenNext=false;
14851486

1487+
bool FirstVolume=true;
1488+
1489+
// We shall set FirstFile once for all volumes and not for each volume.
1490+
// So we do not reuse the outdated Analyze->StartPos from previous volume
1491+
// if extracted file resides completely in the beginning of current one.
1492+
bool FirstFile=true;
1493+
14861494
while (true)
14871495
{
14881496
Archive Arc(Cmd);
@@ -1500,7 +1508,6 @@ void CmdExtract::AnalyzeArchive(const wchar *ArcName,bool Volume,bool NewNumberi
15001508
}
15011509

15021510
OpenNext=false;
1503-
bool FirstFile=true;
15041511
while (Arc.ReadHeader()>0)
15051512
{
15061513
Wait();
@@ -1518,13 +1525,18 @@ void CmdExtract::AnalyzeArchive(const wchar *ArcName,bool Volume,bool NewNumberi
15181525
if (!MatchFound && !Arc.FileHead.Solid) // Can start extraction from here.
15191526
{
15201527
// We would gain nothing and unnecessarily complicate extraction
1521-
// by setting these values for first volume or first archived file.
1528+
// if we set StartName for first volume or StartPos for first
1529+
// archived file.
15221530
if (!FirstVolume)
15231531
wcsncpyz(Analyze->StartName,NextName,ASIZE(Analyze->StartName));
1532+
1533+
// We shall set FirstFile once for all volumes for this code
1534+
// to work properly. Alternatively we could append
1535+
// "|| Analyze->StartPos!=0" to the condition, so we do not reuse
1536+
// the outdated Analyze->StartPos value from previous volume.
15241537
if (!FirstFile)
15251538
Analyze->StartPos=Arc.CurBlockPos;
15261539
}
1527-
FirstFile=false;
15281540

15291541
if (Cmd->IsProcessFile(Arc.FileHead,NULL,MATCH_WILDSUBPATH,0,NULL,0)!=0)
15301542
{
@@ -1569,16 +1581,18 @@ void CmdExtract::AnalyzeArchive(const wchar *ArcName,bool Volume,bool NewNumberi
15691581
{
15701582
if (PrevMatched) // First non-matched item after matched.
15711583
{
1572-
// We would gain nothing and unnecessarily complicate extraction
1573-
// by setting these values for first volume or first archived file.
1584+
// We would perform the unnecessarily string comparison
1585+
// when extracting if we set this value for first volume
1586+
// or non-volume archive.
15741587
if (!FirstVolume)
15751588
wcsncpyz(Analyze->EndName,NextName,ASIZE(Analyze->EndName));
1576-
if (!FirstFile)
1577-
Analyze->EndPos=Arc.CurBlockPos;
1589+
Analyze->EndPos=Arc.CurBlockPos;
15781590
}
15791591
PrevMatched=false;
15801592
}
15811593
}
1594+
1595+
FirstFile=false;
15821596
if (Arc.FileHead.SplitAfter)
15831597
{
15841598
OpenNext=true; // Allow open next volume.
@@ -1593,6 +1607,12 @@ void CmdExtract::AnalyzeArchive(const wchar *ArcName,bool Volume,bool NewNumberi
15931607
{
15941608
NextVolumeName(NextName,ASIZE(NextName),!Arc.NewNumbering);
15951609
FirstVolume=false;
1610+
1611+
// Needed for multivolume archives. Added in case some 'break'
1612+
// will quit early from loop above, so we do not set it in the loop.
1613+
// Now it can happen for hypothetical archive without file records
1614+
// and with HEAD_ENDARC record.
1615+
FirstFile=false;
15961616
}
15971617
else
15981618
break;

vendor/unrar/extract.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CmdExtract
2424

2525
bool ArcAnalyzed;
2626

27-
void ReleaseAnalyzeData();
27+
void FreeAnalyzeData();
2828
EXTRACT_ARC_CODE ExtractArchive();
2929
bool ExtractFileCopy(File &New,wchar *ArcName,const wchar *RedirName,wchar *NameNew,wchar *NameExisting,size_t NameExistingSize,int64 UnpSize);
3030
void ExtrPrepareName(Archive &Arc,const wchar *ArcFileName,wchar *DestName,size_t DestSize);

vendor/unrar/pathfn.cpp

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -428,50 +428,39 @@ void NextVolumeName(wchar *ArcName,uint MaxLength,bool OldNumbering)
428428

429429
bool IsNameUsable(const wchar *Name)
430430
{
431-
#ifndef _UNIX
432-
if (Name[0] && Name[1] && wcschr(Name+2,':')!=NULL)
431+
// We were asked to apply Windows-like conversion in Linux in case
432+
// files are unpacked to Windows share. This code is invoked only
433+
// if file failed to be created, so it doesn't affect extraction
434+
// of Unix compatible names to native Unix drives.
435+
#ifdef _UNIX
436+
// Windows shares in Unix do not allow the drive letter,
437+
// so unlike Windows version, we check all characters here.
438+
if (wcschr(Name,':')!=NULL)
439+
return false;
440+
#else
441+
if (Name[0]!=0 && Name[1]!=0 && wcschr(Name+2,':')!=NULL)
433442
return false;
443+
#endif
434444
for (const wchar *s=Name;*s!=0;s++)
435445
{
436446
if ((uint)*s<32)
437447
return false;
448+
449+
// It is for Windows shares in Unix. We can create such names in Windows.
450+
#ifdef _UNIX
451+
// No spaces or dots before the path separator are allowed in Windows
452+
// shares. But they are allowed and automtically removed at the end of
453+
// file or folder name, so it is useless to replace them here.
454+
// Since such files or folders are created successfully, a supposed
455+
// conversion here would never be invoked.
438456
if ((*s==' ' || *s=='.') && IsPathDiv(s[1]))
439457
return false;
440-
}
441458
#endif
459+
}
442460
return *Name!=0 && wcspbrk(Name,L"?*<>|\"")==NULL;
443461
}
444462

445463

446-
void MakeNameUsable(char *Name,bool Extended)
447-
{
448-
#ifdef _WIN_ALL
449-
// In Windows we also need to convert characters not defined in current
450-
// code page. This double conversion changes them to '?', which is
451-
// catched by code below.
452-
size_t NameLength=strlen(Name);
453-
wchar NameW[NM];
454-
CharToWide(Name,NameW,ASIZE(NameW));
455-
WideToChar(NameW,Name,NameLength+1);
456-
Name[NameLength]=0;
457-
#endif
458-
for (char *s=Name;*s!=0;s=charnext(s))
459-
{
460-
if (strchr(Extended ? "?*<>|\"":"?*",*s)!=NULL || Extended && (byte)*s<32)
461-
*s='_';
462-
#ifdef _EMX
463-
if (*s=='=')
464-
*s='_';
465-
#endif
466-
#ifndef _UNIX
467-
if (s-Name>1 && *s==':')
468-
*s='_';
469-
// Remove ' ' and '.' before path separator, but allow .\ and ..\.
470-
if ((*s==' ' || *s=='.' && s>Name && !IsPathDiv(s[-1]) && s[-1]!='.') && IsPathDiv(s[1]))
471-
*s='_';
472-
#endif
473-
}
474-
}
475464

476465

477466
void MakeNameUsable(wchar *Name,bool Extended)
@@ -480,7 +469,27 @@ void MakeNameUsable(wchar *Name,bool Extended)
480469
{
481470
if (wcschr(Extended ? L"?*<>|\"":L"?*",*s)!=NULL || Extended && (uint)*s<32)
482471
*s='_';
483-
#ifndef _UNIX
472+
#ifdef _UNIX
473+
// We were asked to apply Windows-like conversion in Linux in case
474+
// files are unpacked to Windows share. This code is invoked only
475+
// if file failed to be created, so it doesn't affect extraction
476+
// of Unix compatible names to native Unix drives.
477+
if (Extended)
478+
{
479+
// Windows shares in Unix do not allow the drive letter,
480+
// so unlike Windows version, we check all characters here.
481+
if (*s==':')
482+
*s='_';
483+
484+
// No spaces or dots before the path separator are allowed on Windows
485+
// shares. But they are allowed and automtically removed at the end of
486+
// file or folder name, so it is useless to replace them here.
487+
// Since such files or folders are created successfully, a supposed
488+
// conversion here would never be invoked.
489+
if ((*s==' ' || *s=='.') && IsPathDiv(s[1]))
490+
*s='_';
491+
}
492+
#else
484493
if (s-Name>1 && *s==':')
485494
*s='_';
486495
#if 0 // We already can create such files.

vendor/unrar/pathfn.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ void GetConfigName(const wchar *Name,wchar *FullName,size_t MaxSize,bool CheckEx
2929
wchar* GetVolNumPart(const wchar *ArcName);
3030
void NextVolumeName(wchar *ArcName,uint MaxLength,bool OldNumbering);
3131
bool IsNameUsable(const wchar *Name);
32-
void MakeNameUsable(char *Name,bool Extended);
3332
void MakeNameUsable(wchar *Name,bool Extended);
3433

3534
void UnixSlashToDos(const char *SrcName,char *DestName,size_t MaxLength);

vendor/unrar/version.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RARVER_MAJOR 6
2-
#define RARVER_MINOR 20
2+
#define RARVER_MINOR 21
33
#define RARVER_BETA 0
4-
#define RARVER_DAY 17
5-
#define RARVER_MONTH 1
4+
#define RARVER_DAY 16
5+
#define RARVER_MONTH 2
66
#define RARVER_YEAR 2023

0 commit comments

Comments
 (0)