// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "gifdecod.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
bool wxGIFDecoder::GoFrame(int which)
{
- int i;
-
if (!IsAnimation())
return false;
if ((which >= 1) && (which <= m_nimages))
{
+ m_image = 1;
m_pimage = m_pfirst;
- for (i = 0; i < which; i++)
+ while (m_image < which)
+ {
+ m_image++;
m_pimage = m_pimage->next;
+ }
return true;
}
/* loop until a valid y coordinate has been
found, Or if the maximum number of passes has
been reached, exit the loop, and stop image
- decoding (At this point the image is succesfully
+ decoding (At this point the image is successfully
decoded).
If we don't loop, but merely set y to some other
value, that new value might still be invalid depending
if ( !m_f->Read(buf, WXSIZEOF(buf)) )
return false;
- m_f->SeekI(-(off_t)WXSIZEOF(buf), wxFromCurrent);
+ m_f->SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent);
return memcmp(buf, "GIF", WXSIZEOF(buf)) == 0;
}
m_screenw = buf[0] + 256 * buf[1];
m_screenh = buf[2] + 256 * buf[3];
+ if ((m_screenw == 0) || (m_screenh == 0))
+ {
+ return wxGIF_INVFORMAT;
+ }
+
/* load global color map if available */
if ((buf[4] & 0x80) == 0x80)
{
bool done = false;
- while(!done)
+ while (!done)
{
type = (unsigned char)m_f->GetC();
transparent = buf[4];
/* read disposal method */
- disposal = (buf[1] & 0x1C) - 1;
+ disposal = ((buf[1] & 0x1C) >> 2) - 1;
}
else
/* other extension, skip */
pimg->w = buf[4] + 256 * buf[5];
pimg->h = buf[6] + 256 * buf[7];
- if (pimg->w == 0 || pimg->h == 0)
+ if ((pimg->w == 0) || (pimg->w > m_screenw) || (pimg->h == 0) || (pimg->h > m_screenh))
{
Destroy();
return wxGIF_INVFORMAT;
/* get initial code size from first byte in raster data */
bits = (unsigned char)m_f->GetC();
+ if (bits == 0)
+ {
+ Destroy();
+ return wxGIF_INVFORMAT;
+ }
/* decode image */
int result = dgif(pimg, interl, bits);
}
}
- if (m_nimages == 0)
+ if (m_nimages <= 0)
{
Destroy();
return wxGIF_INVFORMAT;