X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/05a98b6d5d201eb8edea04b1ab022e4a9a46e9f0..8472511246c9160d4ff40ab86f635fc67c10b54a:/src/common/anidecod.cpp diff --git a/src/common/anidecod.cpp b/src/common/anidecod.cpp index 7d502ae52a..d0d0b6d75b 100644 --- a/src/common/anidecod.cpp +++ b/src/common/anidecod.cpp @@ -35,10 +35,10 @@ wxCURHandler wxANIDecoder::sm_handler; class wxANIFrameInfo { public: - wxANIFrameInfo(size_t delay = 0, int idx = -1) + wxANIFrameInfo(unsigned int delay = 0, int idx = -1) { m_delay=delay; m_imageIndex=idx; } - size_t m_delay; + unsigned int m_delay; int m_imageIndex; }; @@ -61,9 +61,9 @@ wxANIDecoder::~wxANIDecoder() { } -bool wxANIDecoder::ConvertToImage(size_t frame, wxImage *image) const +bool wxANIDecoder::ConvertToImage(unsigned int frame, wxImage *image) const { - size_t idx = m_info[frame].m_imageIndex; + unsigned int idx = m_info[frame].m_imageIndex; *image = m_images[idx]; // copy return image->IsOk(); } @@ -73,32 +73,32 @@ bool wxANIDecoder::ConvertToImage(size_t frame, wxImage *image) const // Data accessors //--------------------------------------------------------------------------- -wxSize wxANIDecoder::GetFrameSize(size_t WXUNUSED(frame)) const +wxSize wxANIDecoder::GetFrameSize(unsigned int WXUNUSED(frame)) const { // all frames are of the same size... return m_szAnimation; } -wxPoint wxANIDecoder::GetFramePosition(size_t WXUNUSED(frame)) const +wxPoint wxANIDecoder::GetFramePosition(unsigned int WXUNUSED(frame)) const { // all frames are of the same size... return wxPoint(0,0); } -wxAnimationDisposal wxANIDecoder::GetDisposalMethod(size_t WXUNUSED(frame)) const +wxAnimationDisposal wxANIDecoder::GetDisposalMethod(unsigned int WXUNUSED(frame)) const { // this disposal is implicit for all frames inside an ANI file return wxANIM_TOBACKGROUND; } -long wxANIDecoder::GetDelay(size_t frame) const +long wxANIDecoder::GetDelay(unsigned int frame) const { return m_info[frame].m_delay; } -wxColour wxANIDecoder::GetTransparentColour(size_t frame) const +wxColour wxANIDecoder::GetTransparentColour(unsigned int frame) const { - size_t idx = m_info[frame].m_imageIndex; + unsigned int idx = m_info[frame].m_imageIndex; if (!m_images[idx].HasMask()) return wxNullColour; @@ -113,10 +113,10 @@ wxColour wxANIDecoder::GetTransparentColour(size_t frame) const // ANI reading and decoding //--------------------------------------------------------------------------- -bool wxANIDecoder::CanRead(wxInputStream& stream) const +bool wxANIDecoder::DoCanRead(wxInputStream& stream) const { wxInt32 FCC1, FCC2; - wxUint32 datalen ; + wxUint32 datalen; wxInt32 riff32; memcpy( &riff32, "RIFF", 4 ); @@ -127,7 +127,11 @@ bool wxANIDecoder::CanRead(wxInputStream& stream) const wxInt32 anih32; memcpy( &anih32, "anih", 4 ); - stream.SeekI(0); + if ( stream.IsSeekable() && stream.SeekI(0) == wxInvalidOffset ) + { + return false; + } + if ( !stream.Read(&FCC1, 4) ) return false; @@ -154,7 +158,8 @@ bool wxANIDecoder::CanRead(wxInputStream& stream) const } else { - stream.SeekI(stream.TellI() + datalen); + if ( stream.SeekI(stream.TellI() + datalen) == wxInvalidOffset ) + return false; } // try to read next data chunk: @@ -205,7 +210,7 @@ bool wxANIDecoder::Load( wxInputStream& stream ) { wxInt32 FCC1, FCC2; wxUint32 datalen; - size_t globaldelay=0; + unsigned int globaldelay=0; wxInt32 riff32; memcpy( &riff32, "RIFF", 4 ); @@ -220,8 +225,13 @@ bool wxANIDecoder::Load( wxInputStream& stream ) wxInt32 seq32; memcpy( &seq32, "seq ", 4 ); - stream.SeekI(0); - stream.Read(&FCC1, 4); + if ( stream.IsSeekable() && stream.SeekI(0) == wxInvalidOffset ) + { + return false; + } + + if ( !stream.Read(&FCC1, 4) ) + return false; if ( FCC1 != riff32 ) return false; @@ -232,10 +242,12 @@ bool wxANIDecoder::Load( wxInputStream& stream ) m_info.Clear(); // we have a riff file: - while ( stream.IsOk() ) + while ( !stream.Eof() ) { // we always have a data size: - stream.Read(&datalen, 4); + if (!stream.Read(&datalen, 4)) + return false; + datalen = wxINT32_SWAP_ON_BE(datalen); //data should be padded to make even number of bytes @@ -244,7 +256,8 @@ bool wxANIDecoder::Load( wxInputStream& stream ) // now either data or a FCC: if ( (FCC1 == riff32) || (FCC1 == list32) ) { - stream.Read(&FCC2, 4); + if (!stream.Read(&FCC2, 4)) + return false; } else if ( FCC1 == anih32 ) { @@ -255,7 +268,8 @@ bool wxANIDecoder::Load( wxInputStream& stream ) return false; // already parsed an ani header? struct wxANIHeader header; - stream.Read(&header, sizeof(wxANIHeader)); + if (!stream.Read(&header, sizeof(wxANIHeader))) + return false; header.AdjustEndianness(); // we should have a global frame size @@ -278,9 +292,10 @@ bool wxANIDecoder::Load( wxInputStream& stream ) return false; // rate chunks should always be placed after anih chunk wxASSERT(m_info.GetCount() == m_nFrames); - for (size_t i=0; i