Skip to content

Commit

Permalink
Fix teletext memory overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
repojohnray committed Jul 6, 2022
1 parent c6ef0c3 commit 4d1a069
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions xbmc/video/Teletext.cpp
Expand Up @@ -1229,8 +1229,9 @@ void CTeletextDecoder::RenderPage()
m_RenderInfo.PageAtrb[32].fg = TXT_ColorYellow;
m_RenderInfo.PageAtrb[32].bg = TXT_ColorMenu1;
int showpage = m_txtCache->PageReceiving;
int showsubpage = m_txtCache->SubPageTable[showpage];
if (showsubpage!=0xff)
int showsubpage;

if (showpage >= 0 && (showsubpage = m_txtCache->SubPageTable[showpage]) != 0xff)
{
TextCachedPage_t *pCachedPage;
pCachedPage = m_txtCache->astCachetable[showpage][showsubpage];
Expand Down Expand Up @@ -1303,6 +1304,10 @@ void CTeletextDecoder::RenderPage()

void CTeletextDecoder::DoFlashing(int startrow)
{
if (m_RenderInfo.PageInfo !=
&m_txtCache->astCachetable[m_txtCache->Page][m_txtCache->SubPage]->pageinfo)
m_RenderInfo.PageInfo = nullptr;

/* get national subset */
if (m_txtCache->NationalSubset <= NAT_MAX_FROM_HEADER && /* not for GR/RU as long as line28 is not evaluated */
m_RenderInfo.PageInfo && m_RenderInfo.PageInfo->nationalvalid) /* individual subset according to page header */
Expand Down Expand Up @@ -2255,7 +2260,11 @@ void CTeletextDecoder::RenderCharIntern(TextRenderInfo_t* RenderInfo, int Char,

/* render char */
sbitbuffer = m_sBit->buffer;
unsigned char localbuffer[1000]; // should be enough to store one character-bitmap...
#ifdef __GNUC__
unsigned char localbuffer[(m_sBit->pitch + 1) * m_sBit->height];
#else
unsigned char localbuffer[8192]; // should be enough to store one character-bitmap...
#endif
// add diacritical marks
if (Attribute->diacrit)
{
Expand All @@ -2275,15 +2284,17 @@ void CTeletextDecoder::RenderCharIntern(TextRenderInfo_t* RenderInfo, int Char,
{
if (FTC_SBitCache_Lookup(m_Cache, &m_TypeTTF, glyph, &sbit_diacrit, NULL) == 0)
{
const int sbitLen = sbit_diacrit->height * sbit_diacrit->pitch;
sbitbuffer = localbuffer;
memcpy(sbitbuffer,m_sBit->buffer,m_sBit->pitch*m_sBit->height);

for (Row = 0; Row < m_sBit->height; Row++)
{
for (Pitch = 0; Pitch < m_sBit->pitch; Pitch++)
{
if (sbit_diacrit->pitch > Pitch && sbit_diacrit->height > Row)
sbitbuffer[Row*m_sBit->pitch+Pitch] |= sbit_diacrit->buffer[Row*m_sBit->pitch+Pitch];
const int offset = Row * m_sBit->pitch + Pitch;
if (sbit_diacrit->pitch > Pitch && sbit_diacrit->height > Row && offset < sbitLen)
sbitbuffer[offset] |= sbit_diacrit->buffer[offset];
}
}
}
Expand Down

0 comments on commit 4d1a069

Please sign in to comment.