// create the image
wxSize sz = GetFrameSize(frame);
image->Create(sz.GetWidth(), sz.GetHeight());
+ image->SetType(wxBITMAP_TYPE_GIF);
if (!image->Ok())
return false;
// Get data for current frame
-wxSize wxGIFDecoder::GetFrameSize(unsigned int frame) const
+wxSize wxGIFDecoder::GetFrameSize(unsigned int frame) const
{
return wxSize(GetFrame(frame)->w, GetFrame(frame)->h);
}
if ( !stream.Read(buf, WXSIZEOF(buf)) )
return false;
- stream.SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent);
+ if (stream.SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent) == wxInvalidOffset)
+ return false; // this happens e.g. for non-seekable streams
return memcmp(buf, "GIF", WXSIZEOF(buf)) == 0;
}
wxGIFErrorCode wxGIFDecoder::LoadGIF(wxInputStream& stream)
{
unsigned int global_ncolors = 0;
- int bits, interl, transparent, i;
+ int bits, interl, i;
wxAnimationDisposal disposal;
long size;
long delay;
}
// transparent colour, disposal method and delay default to unused
- transparent = -1;
+ int transparent = -1;
disposal = wxANIM_UNSPECIFIED;
delay = -1;
delay = 10 * (buf[2] + 256 * buf[3]);
// read transparent colour index, if used
- if (buf[1] & 0x01)
- transparent = buf[4];
+ transparent = buf[1] & 0x01 ? buf[4] : -1;
// read disposal method
disposal = (wxAnimationDisposal)(((buf[1] & 0x1C) >> 2) - 1);
{
while ((i = (unsigned char)stream.GetC()) != 0)
{
- if (stream.Eof() || (stream.LastRead() == 0))
+ if (stream.Eof() || (stream.LastRead() == 0) ||
+ stream.SeekI(i, wxFromCurrent) == wxInvalidOffset)
{
done = true;
break;
}
- stream.SeekI(i, wxFromCurrent);
}
}
}
pimg->w = buf[4] + 256 * buf[5];
pimg->h = buf[6] + 256 * buf[7];
- if ( anim && ((pimg->w == 0) || (pimg->w > (unsigned int)m_szAnimation.GetWidth()) ||
- (pimg->h == 0) || (pimg->h > (unsigned int)m_szAnimation.GetHeight())) )
+ if ( anim && ((pimg->w == 0) || (pimg->w > (unsigned int)m_szAnimation.GetWidth()) ||
+ (pimg->h == 0) || (pimg->h > (unsigned int)m_szAnimation.GetHeight())) )
return wxGIF_INVFORMAT;
interl = ((buf[8] & 0x40)? 1 : 0);
// skip all data
while ((i = (unsigned char)stream.GetC()) != 0)
{
- if (stream.Eof() || (stream.LastRead() == 0))
+ if (stream.Eof() || (stream.LastRead() == 0) ||
+ stream.SeekI(i, wxFromCurrent) == wxInvalidOffset)
{
Destroy();
return wxGIF_INVFORMAT;
}
- stream.SeekI(i, wxFromCurrent);
}
}
else if (type == 0x2C)
{
unsigned int local_ncolors = 2 << (buf[8] & 0x07);
wxFileOffset numBytes = 3 * local_ncolors;
- stream.SeekI(numBytes, wxFromCurrent);
+ if (stream.SeekI(numBytes, wxFromCurrent) == wxInvalidOffset)
+ {
+ Destroy();
+ return wxGIF_INVFORMAT;
+ }
}
// initial code size
// skip all data
while ((i = (unsigned char)stream.GetC()) != 0)
{
- if (stream.Eof() || (stream.LastRead() == 0))
+ if (stream.Eof() || (stream.LastRead() == 0) ||
+ stream.SeekI(i, wxFromCurrent) == wxInvalidOffset)
{
Destroy();
return wxGIF_INVFORMAT;
}
- stream.SeekI(i, wxFromCurrent);
}
}
else if ((type != 0x3B) && (type != 00)) // testing