Skip to content

Commit 08a782c

Browse files
authored
1 parent 92c3e6d commit 08a782c

35 files changed

+611
-465
lines changed

arccmt.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool Archive::GetComment(Array<wchar> *CmtData)
3434
#ifndef SFX_MODULE
3535
// Old style (RAR 2.9) comment header embedded into the main
3636
// archive header.
37-
if (BrokenHeader)
37+
if (BrokenHeader || CommHead.HeadSize<SIZEOF_COMMHEAD)
3838
{
3939
uiMsg(UIERROR_CMTBROKEN,FileName);
4040
return false;
@@ -57,6 +57,8 @@ bool Archive::GetComment(Array<wchar> *CmtData)
5757
#else
5858
UnpCmtLength=GetByte();
5959
UnpCmtLength+=(GetByte()<<8);
60+
if (CmtLength<2)
61+
return false;
6062
CmtLength-=2;
6163
DataIO.SetCmt13Encryption();
6264
CommHead.UnpVer=15;

archive.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Archive:public File
8484
void AddSubData(byte *SrcData,uint64 DataSize,File *SrcFile,
8585
const wchar *Name,uint Flags);
8686
bool ReadSubData(Array<byte> *UnpData,File *DestFile);
87-
HEADER_TYPE GetHeaderType() {return CurHeaderType;};
87+
HEADER_TYPE GetHeaderType() {return CurHeaderType;}
8888
RAROptions* GetRAROptions() {return Cmd;}
8989
void SetSilentOpen(bool Mode) {SilentOpen=Mode;}
9090
#if 0

arcread.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ size_t Archive::ReadHeader15()
204204
if (ShortBlock.HeaderType==HEAD_MAIN && (ShortBlock.Flags & MHD_COMMENT)!=0)
205205
{
206206
// Old style (up to RAR 2.9) main archive comment embedded into
207-
// the main archive header found. While we can read the entire
207+
// the main archive header found. While we can read the entire
208208
// ShortBlock.HeadSize here and remove this part of "if", it would be
209209
// waste of memory, because we'll read and process this comment data
210210
// in other function anyway and we do not need them here now.
@@ -230,7 +230,7 @@ size_t Archive::ReadHeader15()
230230
Encrypted=(MainHead.Flags & MHD_PASSWORD)!=0;
231231
Signed=MainHead.PosAV!=0 || MainHead.HighPosAV!=0;
232232
MainHead.CommentInHeader=(MainHead.Flags & MHD_COMMENT)!=0;
233-
233+
234234
// Only for encrypted 3.0+ archives. 2.x archives did not have this
235235
// flag, so for non-encrypted archives, we'll set it later based on
236236
// file attributes.
@@ -257,7 +257,7 @@ size_t Archive::ReadHeader15()
257257
hd->WinSize=hd->Dir ? 0:0x10000<<((hd->Flags & LHD_WINDOWMASK)>>5);
258258
hd->CommentInHeader=(hd->Flags & LHD_COMMENT)!=0;
259259
hd->Version=(hd->Flags & LHD_VERSION)!=0;
260-
260+
261261
hd->DataSize=Raw.Get4();
262262
uint LowUnpSize=Raw.Get4();
263263
hd->HostOS=Raw.Get1();
@@ -282,7 +282,7 @@ size_t Archive::ReadHeader15()
282282
{
283283
case 13: hd->CryptMethod=CRYPT_RAR13; break;
284284
case 15: hd->CryptMethod=CRYPT_RAR15; break;
285-
case 20:
285+
case 20:
286286
case 26: hd->CryptMethod=CRYPT_RAR20; break;
287287
default: hd->CryptMethod=CRYPT_RAR30; break;
288288
}
@@ -304,7 +304,7 @@ size_t Archive::ReadHeader15()
304304
}
305305

306306
hd->Inherited=!FileBlock && (hd->SubFlags & SUBHEAD_FLAGS_INHERITED)!=0;
307-
307+
308308
hd->LargeFile=(hd->Flags & LHD_LARGE)!=0;
309309

310310
uint HighPackSize,HighUnpSize;
@@ -314,7 +314,7 @@ size_t Archive::ReadHeader15()
314314
HighUnpSize=Raw.Get4();
315315
hd->UnknownUnpSize=(LowUnpSize==0xffffffff && HighUnpSize==0xffffffff);
316316
}
317-
else
317+
else
318318
{
319319
HighPackSize=HighUnpSize=0;
320320
// UnpSize equal to 0xffffffff without LHD_LARGE flag indicates
@@ -509,7 +509,7 @@ size_t Archive::ReadHeader15()
509509
NextBlockPos+=Raw.Get4();
510510
break;
511511
}
512-
512+
513513
ushort HeaderCRC=Raw.GetCRC15(false);
514514

515515
// Old AV header does not have header CRC properly set.
@@ -644,7 +644,7 @@ size_t Archive::ReadHeader50()
644644
BrokenHeaderMsg();
645645
return 0;
646646
}
647-
647+
648648
Raw.Read(SizeToRead);
649649

650650
if (Raw.Size()<HeaderSize)
@@ -677,7 +677,7 @@ size_t Archive::ReadHeader50()
677677
return 0;
678678
}
679679
}
680-
680+
681681
uint64 ExtraSize=0;
682682
if ((ShortBlock.Flags & HFL_EXTRA)!=0)
683683
{
@@ -770,7 +770,7 @@ size_t Archive::ReadHeader50()
770770
// to not break normal archive processing by calling function.
771771
int64 SaveCurBlockPos=CurBlockPos,SaveNextBlockPos=NextBlockPos;
772772
HEADER_TYPE SaveCurHeaderType=CurHeaderType;
773-
773+
774774
QOpen.Init(this,false);
775775
QOpen.Load(MainHead.QOpenOffset);
776776

@@ -795,7 +795,7 @@ size_t Archive::ReadHeader50()
795795
hd->PackSize=DataSize;
796796
hd->FileFlags=(uint)Raw.GetV();
797797
hd->UnpSize=Raw.GetV();
798-
798+
799799
hd->UnknownUnpSize=(hd->FileFlags & FHFL_UNPUNKNOWN)!=0;
800800
if (hd->UnknownUnpSize)
801801
hd->UnpSize=INT64NDF;
@@ -882,7 +882,7 @@ size_t Archive::ReadHeader50()
882882
RecoverySize=Header.RecSectionSize*Header.RecCount;
883883
}
884884
#endif
885-
885+
886886
if (BadCRC) // Add the file name to broken header message displayed above.
887887
uiMsg(UIERROR_FHEADERBROKEN,Archive::FileName,hd->FileName);
888888
}
@@ -1307,7 +1307,7 @@ void Archive::ConvertAttributes()
13071307

13081308
if (mask == (mode_t) -1)
13091309
{
1310-
// umask call returns the current umask value. Argument (022) is not
1310+
// umask call returns the current umask value. Argument (022) is not
13111311
// really important here.
13121312
mask = umask(022);
13131313

@@ -1384,8 +1384,8 @@ void Archive::ConvertFileHeader(FileHeader *hd)
13841384

13851385
// ':' in file names is allowed in Unix, but not in Windows.
13861386
// Even worse, file data will be written to NTFS stream on NTFS,
1387-
// so automatic name correction on file create error in extraction
1388-
// routine does not work. In Windows and DOS versions we better
1387+
// so automatic name correction on file create error in extraction
1388+
// routine does not work. In Windows and DOS versions we better
13891389
// replace ':' now.
13901390
if (*s==':')
13911391
*s='_';

0 commit comments

Comments
 (0)