Skip to content

Commit

Permalink
Fix 34, 35, 37
Browse files Browse the repository at this point in the history
  • Loading branch information
K0R0L committed Sep 30, 2020
1 parent 4cd2bd3 commit b17d5e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
53 changes: 27 additions & 26 deletions DesktopEditor/fontengine/fontconverter/FontFileBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ namespace NSFontConverter
CFontFileBase(char *sFile, int nLen, bool bFreeFileData)
{
m_sFileData = m_sFile = (unsigned char *)sFile;
m_nLen = nLen;
m_bFreeFileData = bFreeFileData;
m_nLen = (nLen > 0) ? 0 : (unsigned int)nLen;
m_nPos = 0;
m_bFreeFileData = bFreeFileData;
}

void Reset()
Expand Down Expand Up @@ -94,11 +94,11 @@ namespace NSFontConverter
// S = signed / U = unsigned
// 8/16/32/Var = word length, in bytes
// BE = big endian
int GetS8 (int nPos, bool *pbSuccess)
int GetS8 (const unsigned int& nPos, bool *pbSuccess)
{
//*pbSuccess = true;

if ( nPos < 0 || nPos >= m_nLen )
if ( nPos >= m_nLen )
{
*pbSuccess = false;
return 0;
Expand All @@ -109,22 +109,22 @@ namespace NSFontConverter
return nRes;
}

int GetU8 (int nPos, bool *pbSuccess)
int GetU8 (const unsigned int& nPos, bool *pbSuccess)
{
//*pbSuccess = true;
if ( nPos < 0 || nPos >= m_nLen )
if ( nPos >= m_nLen )
{
*pbSuccess = false;
return 0;
}
return m_sFile[ nPos ];
}

int GetS16BE (int nPos, bool *pbSuccess)
int GetS16BE (const unsigned int& nPos, bool *pbSuccess)
{
//*pbSuccess = true;

if ( nPos < 0 || nPos + 1 >= m_nLen )
if ( m_nLen < 2 || nPos > (m_nLen - 2) )
{
*pbSuccess = false;
return 0;
Expand All @@ -136,11 +136,11 @@ namespace NSFontConverter
return nRes;
}

int GetU16BE (int nPos, bool *pbSuccess)
int GetU16BE (const unsigned int& nPos, bool *pbSuccess)
{
//*pbSuccess = true;

if ( nPos < 0 || nPos + 1 >= m_nLen)
if ( m_nLen < 2 || nPos > (m_nLen - 2) )
{
*pbSuccess = false;
return 0;
Expand All @@ -150,11 +150,11 @@ namespace NSFontConverter
return nRes;
}

int GetS32BE (int nPos, bool *pbSuccess)
int GetS32BE (const unsigned int& nPos, bool *pbSuccess)
{
//*pbSuccess = true;

if ( nPos < 0 || nPos + 3 >= m_nLen )
if ( m_nLen < 4 || nPos > (m_nLen - 4) )
{
*pbSuccess = false;
return 0;
Expand All @@ -169,11 +169,11 @@ namespace NSFontConverter
return nRes;
}

unsigned int GetU32BE (int nPos, bool *pbSuccess)
unsigned int GetU32BE (const unsigned int& nPos, bool *pbSuccess)
{
//*pbSuccess = true;

if ( nPos < 0 || nPos + 3 >= m_nLen )
if ( m_nLen < 4 || nPos > (m_nLen - 4) )
{
*pbSuccess = false;
return 0;
Expand All @@ -184,11 +184,11 @@ namespace NSFontConverter
nRes = (nRes << 8) + m_sFile[nPos + 3];
return nRes;
}
unsigned int GetU32LE (int nPos, bool *pbSuccess)
unsigned int GetU32LE (const unsigned int& nPos, bool *pbSuccess)
{
//*pbSuccess = true;

if ( nPos < 0 || nPos + 3 >= m_nLen )
if ( m_nLen < 4 || nPos > (m_nLen - 4) )
{
*pbSuccess = false;
return 0;
Expand All @@ -199,11 +199,11 @@ namespace NSFontConverter
nRes = (nRes << 8) + m_sFile[nPos + 0];
return nRes;
}
unsigned int GetUVarBE(int nPos, int nSize, bool *pbSuccess)
unsigned int GetUVarBE(const unsigned int& nPos, const unsigned int& nSize, bool *pbSuccess)
{
//*pbSuccess = true;

if ( nPos < 0 || nPos + nSize > m_nLen )
if ( m_nLen < nSize || nPos > (m_nLen - nSize) )
{
*pbSuccess = false;
return 0;
Expand All @@ -215,9 +215,9 @@ namespace NSFontConverter
return nRes;
}

bool CheckRegion(int nPos, int nSize)
bool CheckRegion(const unsigned int& nPos, const unsigned int& nSize)
{
return (nPos >= 0 && nPos + nSize >= nPos && nPos + nSize <= m_nLen);
return (m_nLen >= nSize && nPos <= (m_nLen - nSize));
}
int ReadS8 (bool *pbSuccess)
{
Expand All @@ -239,10 +239,12 @@ namespace NSFontConverter
m_nPos += 4;
return unResult;
}
int Read(void* pDestBuffer, int nSize)
int Read(void* pDestBuffer, unsigned int nSize)
{
if ( m_nPos + nSize >= m_nLen )
nSize = m_nLen - m_nPos - 1;
if (m_nPos >= m_nLen)
nSize = 0;
else if (nSize > (m_nLen - m_nPos))
nSize = m_nLen - m_nPos;

memcpy( pDestBuffer, (m_sFile + m_nPos), nSize );
m_nPos += nSize;
Expand All @@ -254,10 +256,9 @@ namespace NSFontConverter

unsigned char *m_sFileData;
unsigned char *m_sFile;
int m_nLen;
unsigned int m_nLen;
unsigned int m_nPos;
bool m_bFreeFileData;
int m_nPos;

};
}

Expand Down
5 changes: 3 additions & 2 deletions DesktopEditor/fontengine/fontconverter/FontFileType1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ namespace NSFontConverter
char nChar = *pTemp;
*pTemp = '\0';
nCode = atoi( pCur );
if (nCode < 0) nCode = 0;
*pTemp = nChar;
if ( nCode == 8 && *pTemp == '#')
{
Expand Down Expand Up @@ -612,7 +613,7 @@ namespace NSFontConverter
sToken.clear();
sGlyph.clear();

while ( ( nChar = sEexec[++nIndex] ) != ' ' )
while ( nIndex < nEexecLen && ( nChar = sEexec[++nIndex] ) != ' ' )
sGlyph.push_back( (wchar_t)nChar );
}
}
Expand Down Expand Up @@ -656,7 +657,7 @@ namespace NSFontConverter
int nChar = 0;

unsigned char *sBuffer = NULL;
int nBufLen = 0;
unsigned int nBufLen = 0;

while ( nBlockType != PFB_DONE )
{
Expand Down

0 comments on commit b17d5e8

Please sign in to comment.