X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7ac31c429f668e236f4d9686c47b5172f625781c..80f218424f34e2ded439cc23631ea1b74c72f732:/src/common/gifdecod.cpp diff --git a/src/common/gifdecod.cpp b/src/common/gifdecod.cpp index 732557ca3b..8fda5f8ae1 100644 --- a/src/common/gifdecod.cpp +++ b/src/common/gifdecod.cpp @@ -8,10 +8,6 @@ // 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" @@ -146,21 +142,18 @@ bool wxGIFDecoder::ConvertToImage(wxImage *image) const image->SetMask(false); #if wxUSE_PALETTE - if (pal) - { - unsigned char r[256]; - unsigned char g[256]; - unsigned char b[256]; - - for (i = 0; i < 256; i++) - { - r[i] = pal[3*i + 0]; - g[i] = pal[3*i + 1]; - b[i] = pal[3*i + 2]; - } + unsigned char r[256]; + unsigned char g[256]; + unsigned char b[256]; - image->SetPalette(wxPalette(256, r, g, b)); + for (i = 0; i < 256; i++) + { + r[i] = pal[3*i + 0]; + g[i] = pal[3*i + 1]; + b[i] = pal[3*i + 2]; } + + image->SetPalette(wxPalette(256, r, g, b)); #endif // wxUSE_PALETTE /* copy image data */ @@ -271,17 +264,19 @@ bool wxGIFDecoder::GoPrevFrame(bool cyclic) 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; } @@ -507,7 +502,7 @@ int wxGIFDecoder::dgif(GIFImage *img, int interl, int bits) /* 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 @@ -621,7 +616,7 @@ bool wxGIFDecoder::CanRead() 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; } @@ -677,6 +672,11 @@ int wxGIFDecoder::ReadGIF() 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) { @@ -703,7 +703,7 @@ int wxGIFDecoder::ReadGIF() bool done = false; - while(!done) + while (!done) { type = (unsigned char)m_f->GetC(); @@ -752,7 +752,7 @@ int wxGIFDecoder::ReadGIF() transparent = buf[4]; /* read disposal method */ - disposal = (buf[1] & 0x1C) - 1; + disposal = ((buf[1] & 0x1C) >> 2) - 1; } else /* other extension, skip */ @@ -799,7 +799,7 @@ int wxGIFDecoder::ReadGIF() 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; @@ -845,6 +845,11 @@ int wxGIFDecoder::ReadGIF() /* 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); @@ -861,7 +866,7 @@ int wxGIFDecoder::ReadGIF() } } - if (m_nimages == 0) + if (m_nimages <= 0) { Destroy(); return wxGIF_INVFORMAT;