]> git.saurik.com Git - wxWidgets.git/commitdiff
allow reading GIFs with incorrectly specified animation size (closes #9465)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 5 Apr 2009 12:31:54 +0000 (12:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 5 Apr 2009 12:31:54 +0000 (12:31 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60028 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/common/gifdecod.cpp

index 326a3629ab24276fa30879118a2c95e5c0426b63..29f6e9ab0eb3942ba873b9b91649481b74225460 100644 (file)
@@ -518,6 +518,7 @@ All (GUI):
 - Added wxGetSelectedChoices() replacing wxGetMultipleChoices() (Kolya Kosenko).
 - Check whether document fits into page horizontally in wxHtmlPrintout, see the
   new CheckFit() method for more information.
+- Allow reading GIFs with incorrectly specified animation size.
 
 wxGTK:
 
index 1566f40bddff71423b3fbc74a9f67e6735bfec01..3701ea569a2e6a447961609c5449502c91dca815 100644 (file)
@@ -757,9 +757,30 @@ wxGIFErrorCode wxGIFDecoder::LoadGIF(wxInputStream& stream)
             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())) )
-                return wxGIF_INVFORMAT;
+            if ( anim )
+            {
+                // some GIF images specify incorrect animation size but we can
+                // still open them if we fix up the animation size, see #9465
+                if ( m_nFrames == 0 )
+                {
+                    if ( pimg->w > (unsigned)m_szAnimation.x )
+                        m_szAnimation.x = pimg->w;
+                    if ( pimg->h > (unsigned)m_szAnimation.y )
+                        m_szAnimation.y = pimg->h;
+                }
+                else // subsequent frames
+                {
+                    // check that we have valid size
+                    if ( (!pimg->w || pimg->w > (unsigned)m_szAnimation.x) ||
+                            (!pimg->h || pimg->h > (unsigned)m_szAnimation.y) )
+                    {
+                        wxLogError(_("Incorrect GIF frame size (%u, %d) for "
+                                     "the frame #%u"),
+                                   pimg->w, pimg->h, m_nFrames);
+                        return wxGIF_INVFORMAT;
+                    }
+                }
+            }
 
             interl = ((buf[8] & 0x40)? 1 : 0);
             size = pimg->w * pimg->h;