Minor bug fixes to new unrar code

CQTexperiment
Chris Moeller 2014-09-20 22:21:08 -07:00
parent bfb319988f
commit 318b2cfed8
21 changed files with 118 additions and 64 deletions

View File

@ -33,7 +33,7 @@ unrar_err_t Archive::ReadHeader(size_t * ReadSize_)
if (Error!=unrar_ok)
return Error;
if (ReadSize>0 & NextBlockPos<=CurBlockPos)
if (ReadSize>0 && NextBlockPos<=CurBlockPos)
return unrar_err_corrupt;
*ReadSize_ = ReadSize;

View File

@ -1,5 +1,7 @@
// Based on public domain code written in 2012 by Samuel Neves
#ifdef RAR_COMMON_HPP
extern const byte blake2s_sigma[10][16];
// Initialization vector.
@ -125,3 +127,5 @@ static int blake2s_compress_sse( blake2s_state *S, const byte block[BLAKE2S_BLOC
STORE( &S->h[4], _mm_xor_si128( ff1, _mm_xor_si128( row[1], row[3] ) ) );
return 0;
}
#endif

View File

@ -11,6 +11,8 @@
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifdef RAR_COMMON_HPP
#define PARALLELISM_DEGREE 8
void blake2sp_init( blake2sp_state *S )
@ -151,3 +153,5 @@ void blake2sp_final( blake2sp_state *S, byte *digest )
blake2s_final( &S->R, digest );
}
#endif

View File

@ -72,7 +72,7 @@ unrar_err_t CmdExtract::ExtractCurrentFile( bool SkipSolid, bool check_compatibi
Unp->DoUnpack(15,FileCount>1 && Arc.Solid);
else
#endif
Unp->DoUnpack(Arc.FileHead.UnpVer,Arc.FileHead.Flags & LHD_SOLID);
Unp->DoUnpack(Arc.FileHead.UnpVer,!!(Arc.FileHead.Flags & LHD_SOLID));
}
// (no need to seek to next file)
@ -100,7 +100,7 @@ unrar_err_t CmdExtract::ExtractCurrentFile( bool SkipSolid, bool check_compatibi
void CmdExtract::UnstoreFile(int64 DestUnpSize)
{
Buffer.Alloc(Min(DestUnpSize,0x10000));
Buffer.Alloc((int)Min(DestUnpSize,0x10000));
while (1)
{
unsigned int Code=DataIO.UnpRead(&Buffer[0],(uint)Buffer.Size());

View File

@ -5,6 +5,8 @@
* Contents: model description and encoding/decoding routines *
****************************************************************************/
#ifdef RAR_COMMON_HPP
static const int MAX_O=64; /* maximum allowed model order */
const uint TOP=1 << 24, BOT=1 << 15;
@ -615,3 +617,5 @@ int ModelPPM::DecodeChar()
ARI_DEC_NORMALIZE(Coder.code,Coder.low,Coder.range,Coder.UnpackRead);
return(Symbol);
}
#endif

View File

@ -19,3 +19,38 @@ wchar* GetWideName(const char *Name,const wchar *NameW,wchar *DestW,size_t DestS
return(DestW);
}
void UnixSlashToDos(const char *SrcName, char *DestName, size_t MaxLength)
{
size_t Copied = 0;
for (; Copied<MaxLength - 1 && SrcName[Copied] != 0; Copied++)
DestName[Copied] = SrcName[Copied] == '/' ? '\\' : SrcName[Copied];
DestName[Copied] = 0;
}
void DosSlashToUnix(const char *SrcName, char *DestName, size_t MaxLength)
{
size_t Copied = 0;
for (; Copied<MaxLength - 1 && SrcName[Copied] != 0; Copied++)
DestName[Copied] = SrcName[Copied] == '\\' ? '/' : SrcName[Copied];
DestName[Copied] = 0;
}
void UnixSlashToDos(const wchar *SrcName, wchar *DestName, size_t MaxLength)
{
size_t Copied = 0;
for (; Copied<MaxLength - 1 && SrcName[Copied] != 0; Copied++)
DestName[Copied] = SrcName[Copied] == '/' ? '\\' : SrcName[Copied];
DestName[Copied] = 0;
}
void DosSlashToUnix(const wchar *SrcName, wchar *DestName, size_t MaxLength)
{
size_t Copied = 0;
for (; Copied<MaxLength - 1 && SrcName[Copied] != 0; Copied++)
DestName[Copied] = SrcName[Copied] == '\\' ? '/' : SrcName[Copied];
DestName[Copied] = 0;
}

View File

@ -174,6 +174,10 @@ void cleandata(void *data,size_t size);
//// pathfn.hpp
wchar* GetWideName(const char *Name,const wchar *NameW,wchar *DestW,size_t DestSize);
void UnixSlashToDos(const char *SrcName, char *DestName, size_t MaxLength);
void DosSlashToUnix(const char *SrcName, char *DestName, size_t MaxLength);
void UnixSlashToDos(const wchar *SrcName, wchar *DestName, size_t MaxLength);
void DosSlashToUnix(const wchar *SrcName, wchar *DestName, size_t MaxLength);
//// rar.hpp
class Unpack;

View File

@ -403,7 +403,7 @@ bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,uint CodeSize)
break;
case VM_CALL:
R[7]-=4;
SET_VALUE(false,(uint *)&Mem[R[7]&VM_MEMMASK],Cmd-PreparedCode+1);
SET_VALUE(false,(uint *)&Mem[R[7]&VM_MEMMASK],(uint)(Cmd-PreparedCode+1));
SET_IP(GET_VALUE(false,Op1));
continue;
case VM_NOT:
@ -512,7 +512,7 @@ bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,uint CodeSize)
uint Result=GET_UINT32(Value1+GET_VALUE(Cmd->ByteMode,Op2)+FC);
if (Cmd->ByteMode)
Result&=0xff;
Flags=(Result<Value1 || Result==Value1 && FC)|(Result==0 ? VM_FZ:(Result&VM_FS));
Flags=(Result<Value1 || (Result==Value1 && FC))|(Result==0 ? VM_FZ:(Result&VM_FS));
SET_VALUE(Cmd->ByteMode,Op1,Result);
}
break;
@ -523,7 +523,7 @@ bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,uint CodeSize)
uint Result=GET_UINT32(Value1-GET_VALUE(Cmd->ByteMode,Op2)-FC);
if (Cmd->ByteMode)
Result&=0xff;
Flags=(Result>Value1 || Result==Value1 && FC)|(Result==0 ? VM_FZ:(Result&VM_FS));
Flags=(Result>Value1 || (Result==Value1 && FC))|(Result==0 ? VM_FZ:(Result&VM_FS));
SET_VALUE(Cmd->ByteMode,Op1,Result);
}
break;
@ -807,6 +807,8 @@ void RarVM::Optimize(VM_PreparedProgram *Prg)
case VM_CMP:
Cmd->OpCode=Cmd->ByteMode ? VM_CMPB:VM_CMPD;
continue;
default: break;
}
if ((VM_CmdFlags[Cmd->OpCode] & VMCF_CHFLAGS)==0)
continue;
@ -850,6 +852,8 @@ void RarVM::Optimize(VM_PreparedProgram *Prg)
case VM_NEG:
Cmd->OpCode=Cmd->ByteMode ? VM_NEGB:VM_NEGD;
continue;
default: break;
}
}
}

View File

@ -129,7 +129,7 @@ wchar etoupperw(wchar ch)
{
if (ch=='i')
return('I');
#ifdef __APPLE__
#if defined(__APPLE__) || defined(_MSC_VER)
return(toupper(ch));
#else
return(toupperw(ch));
@ -234,7 +234,7 @@ bool LowAscii(const wchar *Str)
int wcsicompc(const wchar *Str1,const wchar *Str2)
{
#if defined(_UNIX)
#if defined(_UNIX) || defined(_MSC_VER)
return my_wcscmp(Str1,Str2);
#else
return wcsicomp(Str1,Str2);
@ -247,7 +247,11 @@ char* strncpyz(char *dest, const char *src, size_t maxlen)
{
if (maxlen>0)
{
strncpy(dest,src,maxlen-1);
#if _MSC_VER >= 1300
strcpy_s(dest,maxlen-1,src);
#else
strncpy(dest,src,maxlen-1);
#endif
dest[maxlen-1]=0;
}
return dest;
@ -273,7 +277,11 @@ char* strncatz(char* dest, const char* src, size_t maxlen)
{
size_t Length = strlen(dest);
if (Length + 1 < maxlen)
#if _MSC_VER >= 1300
strcat_s(dest, maxlen - Length - 1, src);
#else
strncat(dest, src, maxlen - Length - 1);
#endif
return dest;
}

View File

@ -105,9 +105,9 @@ void SubAllocator::InitSubAllocator()
int i, k;
memset(FreeList,0,sizeof(FreeList));
pText=HeapStart;
uint Size2=FIXED_UNIT_SIZE*(SubAllocatorSize/8/FIXED_UNIT_SIZE*7);
uint Size2=(uint)(FIXED_UNIT_SIZE*(SubAllocatorSize/8/FIXED_UNIT_SIZE*7));
uint RealSize2=Size2/FIXED_UNIT_SIZE*UNIT_SIZE;
uint Size1=SubAllocatorSize-Size2;
uint Size1=(uint)(SubAllocatorSize-Size2);
uint RealSize1=Size1/FIXED_UNIT_SIZE*UNIT_SIZE+Size1%FIXED_UNIT_SIZE;
#ifdef STRICT_ALIGNMENT_REQUIRED
if (Size1%FIXED_UNIT_SIZE!=0)

View File

@ -1,6 +1,7 @@
#include "rar.hpp"
#ifdef _WIN_ALL
#include <Windows.h>
RarTime& RarTime::operator =(FILETIME &ft)
{
_ULARGE_INTEGER ul = {ft.dwLowDateTime, ft.dwHighDateTime};
@ -42,30 +43,8 @@ void RarTime::GetLocal(RarLocalTime *lt)
GetWin32(&ft);
FILETIME lft;
if (WinNT() < WNT_VISTA)
{
// SystemTimeToTzSpecificLocalTime based code produces 1 hour error on XP.
FileTimeToLocalFileTime(&ft,&lft);
}
else
{
// We use these functions instead of FileTimeToLocalFileTime according to
// MSDN recommendation: "To account for daylight saving time
// when converting a file time to a local time ..."
SYSTEMTIME st1,st2;
FileTimeToSystemTime(&ft,&st1);
SystemTimeToTzSpecificLocalTime(NULL,&st1,&st2);
SystemTimeToFileTime(&st2,&lft);
// Correct precision loss (low 4 decimal digits) in FileTimeToSystemTime.
FILETIME rft;
SystemTimeToFileTime(&st1,&rft);
int64 Corrected=INT32TO64(ft.dwHighDateTime,ft.dwLowDateTime)-
INT32TO64(rft.dwHighDateTime,rft.dwLowDateTime)+
INT32TO64(lft.dwHighDateTime,lft.dwLowDateTime);
lft.dwLowDateTime=(DWORD)Corrected;
lft.dwHighDateTime=(DWORD)(Corrected>>32);
}
// SystemTimeToTzSpecificLocalTime based code produces 1 hour error on XP.
FileTimeToLocalFileTime(&ft,&lft);
SYSTEMTIME st;
FileTimeToSystemTime(&lft,&st);
@ -91,8 +70,8 @@ void RarTime::GetLocal(RarLocalTime *lt)
// Calculate the time reminder, which is the part of time smaller
// than 1 second, represented in 100-nanosecond intervals.
lt->Reminder=INT32TO64(lft.dwHighDateTime,lft.dwLowDateTime)-
INT32TO64(zft.dwHighDateTime,zft.dwLowDateTime);
lt->Reminder=int32to64(lft.dwHighDateTime,lft.dwLowDateTime)-
int32to64(zft.dwHighDateTime,zft.dwLowDateTime);
#else
time_t ut=GetUnix();
struct tm *t;
@ -131,28 +110,8 @@ void RarTime::SetLocal(RarLocalTime *lt)
FILETIME ft;
if (WinNT() < WNT_VISTA)
{
// TzSpecificLocalTimeToSystemTime based code produces 1 hour error on XP.
LocalFileTimeToFileTime(&lft,&ft);
}
else
{
// Reverse procedure which we do in GetLocal.
SYSTEMTIME st1,st2;
FileTimeToSystemTime(&lft,&st2);
TzSpecificLocalTimeToSystemTime(NULL,&st2,&st1);
SystemTimeToFileTime(&st1,&ft);
// Correct precision loss (low 4 decimal digits) in FileTimeToSystemTime.
FILETIME rft;
SystemTimeToFileTime(&st2,&rft);
int64 Corrected=INT32TO64(lft.dwHighDateTime,lft.dwLowDateTime)-
INT32TO64(rft.dwHighDateTime,rft.dwLowDateTime)+
INT32TO64(ft.dwHighDateTime,ft.dwLowDateTime);
ft.dwLowDateTime=(DWORD)Corrected;
ft.dwHighDateTime=(DWORD)(Corrected>>32);
}
// TzSpecificLocalTimeToSystemTime based code produces 1 hour error on XP.
LocalFileTimeToFileTime(&lft,&ft);
*this=ft;
}

View File

@ -2,6 +2,9 @@
#define _RAR_TIMEFN_
#include <time.h>
#ifdef _WIN_ALL
#include <Windows.h>
#endif
struct RarLocalTime
{

View File

@ -1,5 +1,7 @@
#include "rar.hpp"
#define _RAR_UNPACK_CPP_
#include "coder.cpp"
#include "suballoc.cpp"
#include "model.cpp"

View File

@ -1,3 +1,5 @@
#ifdef RAR_COMMON_HPP
#define STARTL1 2
static unsigned int DecL1[]={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00,
0xee00,0xf000,0xf200,0xf200,0xffff};
@ -479,3 +481,5 @@ uint Unpack::DecodeNum(uint Num,uint StartPos,uint *DecTab,uint *PosTab)
Inp.faddbits(StartPos);
return(((Num-(I ? DecTab[I-1]:0))>>(16-StartPos))+PosTab[StartPos]);
}
#endif

View File

@ -1,4 +1,4 @@
#include "rar.hpp"
#ifdef RAR_COMMON_HPP
void Unpack::CopyString20(uint Length,uint Distance)
{
@ -368,3 +368,5 @@ byte Unpack::DecodeAudio(int Delta)
}
return((byte)Ch);
}
#endif

View File

@ -1,3 +1,5 @@
#ifdef RAR_COMMON_HPP
// We use it instead of direct PPM.DecodeChar call to be sure that
// we reset PPM structures in case of corrupt data. It is important,
// because these structures can be invalid after PPM.DecodeChar returned -1.
@ -834,3 +836,5 @@ void Unpack::InitFilters30()
delete PrgStack[I];
PrgStack.Reset();
}
#endif

View File

@ -1,3 +1,5 @@
#ifdef RAR_COMMON_HPP
void Unpack::Unpack5(bool Solid)
{
FileExtracted=true;
@ -646,3 +648,5 @@ void Unpack::InitFilters()
{
Filters.Reset();
}
#endif

View File

@ -1,3 +1,5 @@
#ifdef RAR_COMMON_HPP
FragmentedWindow::FragmentedWindow()
{
memset(Mem,0,sizeof(Mem));
@ -101,3 +103,5 @@ size_t FragmentedWindow::GetBlockSize(size_t StartPos,size_t RequiredSize)
return Min(MemSize[I]-StartPos,RequiredSize);
return 0; // Must never be here.
}
#endif

View File

@ -1,3 +1,5 @@
#ifdef RAR_COMMON_HPP
inline void Unpack::InsertOldDist(uint Distance)
{
OldDist[3]=OldDist[2];
@ -140,3 +142,5 @@ inline uint Unpack::SlotToLength(BitInput &Inp,uint Slot)
}
return Length;
}
#endif

View File

@ -76,7 +76,7 @@ extern "C" {
assert( !p->data_ );
unrar_pos_t size = unrar_info( p )->size;
p->own_data_ = malloc( size ? size : 1 );
p->own_data_ = malloc( size ? (size_t)size : 1 );
if ( !p->own_data_ )
return unrar_err_memory;
@ -159,7 +159,7 @@ int ComprDataIO::UnpRead( byte* out, uint count )
return 0;
if ( count > (uint) UnpPackedSize )
count = UnpPackedSize;
count = (uint) UnpPackedSize;
int result = Read( out, count );
UnpPackedSize -= result;

View File

@ -10,7 +10,7 @@ extern "C" {
FILE* file = (FILE*) user_data;
// most of the time, seeking won't be necessary
if ( pos != ftell( file ) && fseek( file, pos, SEEK_SET ) != 0 )
if ( pos != ftell( file ) && fseek( file, (long)pos, SEEK_SET ) != 0 )
return unrar_err_corrupt;
*count = (int) fread( out, 1, *count, file );
@ -30,8 +30,13 @@ static void unrar_close_file( void* user_data )
unrar_err_t unrar_open( unrar_t** arc_out, const char path [] )
{
*arc_out = NULL;
#if _MSC_VER >= 1300
FILE* file = NULL;
fopen_s(&file, path, "rb");
#else
FILE* file = fopen( path, "rb" );
#endif
if ( file == NULL )
return unrar_err_open;