Skip to content

Commit 6a592a9

Browse files
committed
Fixed error in compressed buffer processing. version 1.0.3.2
1 parent c088889 commit 6a592a9

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

libendetool.cbp

+3-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Option compiler="gcc" />
88
<Build>
99
<Target title="Debug">
10-
<Option output="endetool_d" prefix_auto="1" extension_auto="1" />
10+
<Option output="lib/endetool_d" prefix_auto="1" extension_auto="1" />
1111
<Option working_dir="" />
1212
<Option object_output="obj/Debug/" />
1313
<Option type="2" />
@@ -20,7 +20,7 @@
2020
</Compiler>
2121
</Target>
2222
<Target title="Release">
23-
<Option output="endetool" prefix_auto="1" extension_auto="1" />
23+
<Option output="lib/endetool" prefix_auto="1" extension_auto="1" />
2424
<Option working_dir="" />
2525
<Option object_output="obj/Release/" />
2626
<Option type="2" />
@@ -60,10 +60,6 @@
6060
<Unit filename="src/lzmat/lzmat_enc.c">
6161
<Option compilerVar="CC" />
6262
</Unit>
63-
<Extensions>
64-
<code_completion />
65-
<envvars />
66-
<debugger />
67-
</Extensions>
63+
<Extensions />
6864
</Project>
6965
</CodeBlocks_project_file>

src/endetool.cpp

+22-14
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ int EnDeTool::encodebinary( const char* src, unsigned srcsize, char* &out )
119119
}
120120

121121
memset( encptr, 0, tmpCiperLen );
122-
memcpy( &encptr[0], &srcsize, sizeof(unsigned int) );
123-
memcpy( &encptr[sizeof(unsigned int)], src, srcsize );
122+
memcpy( &encptr[0], &srcsize, 4 );
123+
memcpy( &encptr[4], src, srcsize );
124124

125125
int encloop = tmpCiperLen / AES_BLOCKLEN;
126126
if ( encloop == 0 )
@@ -170,19 +170,27 @@ int EnDeTool::decodebinary( const char* src, unsigned srcsize, char* &out )
170170
unsigned int realsz = 0;
171171

172172
// checks is it compressed ..
173-
if ( strncmp( &src[4], LZMAT_COMPRESS_HEADER, 4 ) == 0 )
173+
if ( strncmp( &src[0], LZMAT_COMPRESS_HEADER, 0 ) == 0 )
174174
{
175-
realsz = *(unsigned int*)src;
176-
decbuff = new char[ srcsize - 4 ];
175+
memcpy( &realsz, &src[4], 4 );
176+
if ( realsz == 0 )
177+
return -1;
178+
179+
// reallocate buffer for decompress buffer.
180+
decbuff = NULL;
181+
decbuff = new char[ srcsize ];
177182

178183
if ( decbuff == NULL )
179-
return -1;
184+
return -1;
180185

181-
memcpy( decbuff, &src[4], srcsize - 4 );
182-
decbuffsz = decompressbuffer( decbuff, srcsize - 4 );
186+
memcpy( decbuff, src, srcsize );
187+
decbuffsz = decompressbuffer( decbuff, srcsize );
183188

184189
if ( decbuffsz < AES_BLOCKLEN )
185-
return -2;
190+
{
191+
delete[] decbuff;
192+
return -2;
193+
}
186194

187195
need2free = true;
188196
}
@@ -586,24 +594,24 @@ unsigned EnDeTool::decompressbuffer( char* &buff, unsigned blen )
586594
//Check original size.
587595
MP_U32* olen = (MP_U32*)&buff[4];
588596

589-
if ( olen > 0 )
597+
if ( *olen > 0 )
590598
{
599+
MP_U32 buffolen = *olen;
591600
MP_U8* rebuff = (MP_U8*)buff + 8;
592601
MP_U32 rebufflen = blen - 8;
593602

594-
MP_U8* debuff = new MP_U8[ *olen ];
603+
MP_U8* debuff = new MP_U8[ buffolen ];
595604
if ( debuff != NULL )
596605
{
597-
MP_U32 debufflen = *olen;
598-
int retcode = lzmat_decode( debuff, &debufflen,
606+
int retcode = lzmat_decode( debuff, &buffolen,
599607
rebuff, rebufflen );
600608

601609
if ( retcode == LZMAT_STATUS_OK )
602610
{
603611
delete[] buff;
604612
buff = (char*)debuff;
605613

606-
return *olen;
614+
return buffolen;
607615
}
608616
}
609617
}

src/endetool.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// EnDeTool for Crypting data with AES256-CBC and BASE64.
66
// ===========================================================================
77
// A Front-End of C++ class library for gcc/MinGW
8-
// (C)Copyright 2014, 2019 Raphael Kim.
8+
// (C)Copyright 2014 to 2020 Raphael Kim.
99
//
1010
////////////////////////////////////////////////////////////////////////////////
1111

12-
// Version means 1.0.3.0
13-
#define ENDETOOL_VERSION (0x01000300)
12+
// Version means 1.0.3.2
13+
#define ENDETOOL_VERSION (0x01000302)
1414

1515
class EnDeTool
1616
{

0 commit comments

Comments
 (0)