From 598b50750b0395ad0e776eb936577a311361eb5f Mon Sep 17 00:00:00 2001 From: morkt Date: Sun, 21 Jun 2015 20:41:43 +0400 Subject: [PATCH] (CRangeCoder.Decode): fixed buffers length checks. --- ArcFormats/KogadoCocotte.cs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ArcFormats/KogadoCocotte.cs b/ArcFormats/KogadoCocotte.cs index 0af68c5f..288e939e 100644 --- a/ArcFormats/KogadoCocotte.cs +++ b/ArcFormats/KogadoCocotte.cs @@ -144,8 +144,8 @@ namespace GameRes.Formats.Kogado { byte[] m_pSrcBuffer; byte[] m_pDestBuffer; - uint m_dwSrcLength; - uint m_dwDestLength; + uint m_dwSrcEnd; + uint m_dwDestEnd; uint m_dwSrcIndex; uint m_dwDestIndex; RangeCoder m_rc = new RangeCoder(); @@ -216,13 +216,13 @@ namespace GameRes.Formats.Kogado m_dwSrcIndex = m_dwDestIndex = 0; m_pSrcBuffer = src; m_pDestBuffer = dest; - m_dwSrcLength = srcsize; - m_dwDestLength = destsize; + m_dwSrcEnd = srcsize; + m_dwDestEnd = destsize; //this->InitQSModel(); this->StartEncoding(); - while ( m_dwSrcIndex < m_dwSrcLength ) { + while ( m_dwSrcIndex < m_dwSrcEnd ) { if ( !this->GetSrcByteImpl( &ch_byte ) ) return false; qsgetfreq( &m_qsm, ch_byte, &syfreq, <freq ); @@ -253,20 +253,19 @@ namespace GameRes.Formats.Kogado m_dwDestIndex = dst_index; m_pSrcBuffer = src; m_pDestBuffer = dst; - m_dwSrcLength = src_size; - m_dwDestLength = dst_size; + m_dwSrcEnd = src_index + src_size; + m_dwDestEnd = dst_index + dst_size; StartDecoding(); - while (m_dwSrcIndex < m_dwSrcLength) + while (m_dwSrcIndex < m_dwSrcEnd) { ltfreq = (int)DecodeCulshift (12); ch = m_qsm.GetSym (ltfreq); if (256 == ch) // check for end-of-file break; - if (m_dwDestIndex >= m_dwDestLength) + if (!SetDestByteImpl ((byte)ch)) return 0; - SetDestByteImpl ((byte)ch); m_qsm.GetFreq (ch, out syfreq, out ltfreq); DecodeUpdate (syfreq, ltfreq, 1 << 12); m_qsm.Update (ch); @@ -274,7 +273,7 @@ namespace GameRes.Formats.Kogado m_qsm.GetFreq (256, out syfreq, out ltfreq); DecodeUpdate (syfreq, ltfreq, 1 << 12); DoneDecoding(); - return m_dwDestIndex; + return m_dwDestIndex-dst_index; } /* // Encode -------------------------------------------------------- @@ -417,7 +416,7 @@ namespace GameRes.Formats.Kogado // I/O ----------------------------------------------------------- bool GetSrcByteImpl (out byte pData) { - if (m_dwSrcIndex >= m_dwSrcLength) + if (m_dwSrcIndex >= m_dwSrcEnd) { pData = 0; return false; @@ -428,7 +427,7 @@ namespace GameRes.Formats.Kogado bool SetDestByteImpl (byte byData) { - if (m_dwDestIndex >= m_dwDestLength) + if (m_dwDestIndex >= m_dwDestEnd) return false; m_pDestBuffer[m_dwDestIndex++] = byData; return true;