X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/72045d5768a126191a907bc640c28e81a11afdd6..6e35d7ca0e7d975c133f024321939fa1dabb2fe5:/src/common/gifdecod.cpp?ds=sidebyside diff --git a/src/common/gifdecod.cpp b/src/common/gifdecod.cpp index ab507b8d7f..3ca73d91a6 100644 --- a/src/common/gifdecod.cpp +++ b/src/common/gifdecod.cpp @@ -125,7 +125,7 @@ bool wxGIFDecoder::ConvertToImage(size_t frame, wxImage *image) const pal = GetPalette(frame); src = GetData(frame); dst = image->GetData(); - transparent = GetTransparentColour(frame); + transparent = GetTransparentColourIndex(frame); /* set transparent colour mask */ if (transparent != -1) @@ -206,10 +206,22 @@ long wxGIFDecoder::GetDelay(size_t frame) const return GetFrame(frame)->delay; } +wxColour wxGIFDecoder::GetTransparentColour(size_t frame) const +{ + unsigned char *pal = GetFrame(frame)->pal; + int n = GetFrame(frame)->transparent; + if (n == -1) + return wxNullColour; + + return wxColour(pal[n*3 + 0], + pal[n*3 + 1], + pal[n*3 + 2]); +} + unsigned char* wxGIFDecoder::GetData(size_t frame) const { return (GetFrame(frame)->p); } unsigned char* wxGIFDecoder::GetPalette(size_t frame) const { return (GetFrame(frame)->pal); } unsigned int wxGIFDecoder::GetNcolours(size_t frame) const { return (GetFrame(frame)->ncolours); } -int wxGIFDecoder::GetTransparentColour(size_t frame) const { return (GetFrame(frame)->transparent); } +int wxGIFDecoder::GetTransparentColourIndex(size_t frame) const { return (GetFrame(frame)->transparent); } @@ -618,7 +630,7 @@ wxGIFErrorCode wxGIFDecoder::LoadGIF(wxInputStream& stream) m_szAnimation.SetWidth( buf[0] + 256 * buf[1] ); m_szAnimation.SetHeight( buf[2] + 256 * buf[3] ); - if ((m_szAnimation.GetWidth() == 0) || (m_szAnimation.GetHeight() == 0)) + if (anim && ((m_szAnimation.GetWidth() == 0) || (m_szAnimation.GetHeight() == 0))) { return wxGIF_INVFORMAT; } @@ -703,12 +715,12 @@ wxGIFErrorCode wxGIFDecoder::LoadGIF(wxInputStream& stream) { while ((i = (unsigned char)stream.GetC()) != 0) { - stream.SeekI(i, wxFromCurrent); - if (stream.Eof()) + if (stream.Eof() || (stream.LastRead() == 0)) { done = true; break; } + stream.SeekI(i, wxFromCurrent); } } } @@ -743,8 +755,8 @@ wxGIFErrorCode wxGIFDecoder::LoadGIF(wxInputStream& stream) pimg->w = buf[4] + 256 * buf[5]; pimg->h = buf[6] + 256 * buf[7]; - if ((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()))) { Destroy(); return wxGIF_INVFORMAT; @@ -834,6 +846,11 @@ wxGIFErrorCode wxGIFDecoder::LoadGIF(wxInputStream& stream) /* skip all data */ while ((i = (unsigned char)stream.GetC()) != 0) { + if (stream.Eof() || (stream.LastRead() == 0)) + { + Destroy(); + return wxGIF_INVFORMAT; + } stream.SeekI(i, wxFromCurrent); } } @@ -852,22 +869,26 @@ wxGIFErrorCode wxGIFDecoder::LoadGIF(wxInputStream& stream) if ((buf[8] & 0x80) == 0x80) { unsigned int local_ncolors = 2 << (buf[8] & 0x07); - wxFileOffset pos = stream.TellI(); wxFileOffset numBytes = 3 * local_ncolors; stream.SeekI(numBytes, wxFromCurrent); - if (stream.TellI() != (pos + numBytes)) - { - Destroy(); - return wxGIF_INVFORMAT; - } } /* initial code size */ (void) stream.GetC(); + if (stream.Eof() || (stream.LastRead() == 0)) + { + Destroy(); + return wxGIF_INVFORMAT; + } /* skip all data */ while ((i = (unsigned char)stream.GetC()) != 0) { + if (stream.Eof() || (stream.LastRead() == 0)) + { + Destroy(); + return wxGIF_INVFORMAT; + } stream.SeekI(i, wxFromCurrent); } }