From bf34105a41faf8e267354e7a96eb1b1e847580da Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Sun, 1 May 2011 23:35:46 +0000 Subject: [PATCH] Fixed reading multiple images from ANI and ICO image files. In r60852 various 'unneeded' SeekI(0) calls were removed. Examined the changes in that revision and restored all SeekI(0) calls after finding out their removal caused problems with reading more than one image from ICO and ANI files. The image handling code for these formats expects to read from the start of a stream for reading its images (as well as for DoCanRead and DoGetImageCount), regardless of the index of the requested image. Closes #12861. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67671 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/anidecod.cpp | 10 ++++++++++ src/common/imagbmp.cpp | 22 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/common/anidecod.cpp b/src/common/anidecod.cpp index 9d202672c6..2cb075948d 100644 --- a/src/common/anidecod.cpp +++ b/src/common/anidecod.cpp @@ -127,6 +127,11 @@ bool wxANIDecoder::DoCanRead(wxInputStream& stream) const wxInt32 anih32; memcpy( &anih32, "anih", 4 ); + if ( stream.SeekI(0) == wxInvalidOffset ) + { + return false; + } + if ( !stream.Read(&FCC1, 4) ) return false; @@ -220,6 +225,11 @@ bool wxANIDecoder::Load( wxInputStream& stream ) wxInt32 seq32; memcpy( &seq32, "seq ", 4 ); + if ( stream.SeekI(0) == wxInvalidOffset) + { + return false; + } + if ( !stream.Read(&FCC1, 4) ) return false; if ( FCC1 != riff32 ) diff --git a/src/common/imagbmp.cpp b/src/common/imagbmp.cpp index f691b233e6..875da6e3f0 100644 --- a/src/common/imagbmp.cpp +++ b/src/common/imagbmp.cpp @@ -1335,6 +1335,11 @@ bool wxICOHandler::SaveFile(wxImage *image, bool wxICOHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int index) { + if (stream.SeekI(0) == wxInvalidOffset) + { + return false; + } + return DoLoadFile(image, stream, verbose, index); } @@ -1423,10 +1428,16 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream, int wxICOHandler::DoGetImageCount(wxInputStream& stream) { + // It's ok to modify the stream position in this function. + + if (stream.SeekI(0) == wxInvalidOffset) + { + return 0; + } + ICONDIR IconDir; if (stream.Read(&IconDir, sizeof(IconDir)).LastRead() != sizeof(IconDir)) - // it's ok to modify the stream position here return 0; return (int)wxUINT16_SWAP_ON_BE(IconDir.idCount); @@ -1492,8 +1503,15 @@ int wxANIHandler::DoGetImageCount(wxInputStream& stream) static bool CanReadICOOrCUR(wxInputStream *stream, wxUint16 resourceType) { + // It's ok to modify the stream position in this function. + + if ( stream->SeekI(0) == wxInvalidOffset) + { + return false; + } + ICONDIR iconDir; - if ( !stream->Read(&iconDir, sizeof(iconDir)) ) // it's ok to modify the stream position here + if ( !stream->Read(&iconDir, sizeof(iconDir)) ) { return false; } -- 2.47.2