From a9a2485d6464928fcf1012e573f4b3b734238300 Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Mon, 1 Jun 2009 13:56:41 +0000 Subject: [PATCH] fix loading ICO from socket stream: override OnSysTell and OnSysSeek rather than directly SeekO/I or TellO/I; in wxICOHandler only call SeekI() if we have a non-null seek offset git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60856 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/sckstrm.h | 51 ++++++++++++++++++++++-------------------- src/common/imagbmp.cpp | 8 +++---- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/include/wx/sckstrm.h b/include/wx/sckstrm.h index 7018209199..c9c19f284b 100644 --- a/include/wx/sckstrm.h +++ b/include/wx/sckstrm.h @@ -19,38 +19,41 @@ class WXDLLIMPEXP_NET wxSocketOutputStream : public wxOutputStream { - public: - wxSocketOutputStream(wxSocketBase& s); - virtual ~wxSocketOutputStream(); +public: + wxSocketOutputStream(wxSocketBase& s); + virtual ~wxSocketOutputStream(); - wxFileOffset SeekO( wxFileOffset WXUNUSED(pos), wxSeekMode WXUNUSED(mode) ) - { return -1; } - wxFileOffset TellO() const - { return -1; } +protected: + wxSocketBase *m_o_socket; - protected: - wxSocketBase *m_o_socket; + size_t OnSysWrite(const void *buffer, size_t bufsize); - size_t OnSysWrite(const void *buffer, size_t bufsize); + // socket streams are both un-seekable and size-less streams: + wxFileOffset OnSysTell() const + { return wxInvalidOffset; } + wxFileOffset OnSysSeek(wxFileOffset WXUNUSED(pos), wxSeekMode WXUNUSED(mode)) + { return wxInvalidOffset; } wxDECLARE_NO_COPY_CLASS(wxSocketOutputStream); }; class WXDLLIMPEXP_NET wxSocketInputStream : public wxInputStream { - public: - wxSocketInputStream(wxSocketBase& s); - virtual ~wxSocketInputStream(); +public: + wxSocketInputStream(wxSocketBase& s); + virtual ~wxSocketInputStream(); - wxFileOffset SeekI( wxFileOffset WXUNUSED(pos), wxSeekMode WXUNUSED(mode) ) - { return -1; } - wxFileOffset TellI() const - { return -1; } +protected: + wxSocketBase *m_i_socket; - protected: - wxSocketBase *m_i_socket; + size_t OnSysRead(void *buffer, size_t bufsize); - size_t OnSysRead(void *buffer, size_t bufsize); + // socket streams are both un-seekable and size-less streams: + + wxFileOffset OnSysTell() const + { return wxInvalidOffset; } + wxFileOffset OnSysSeek(wxFileOffset WXUNUSED(pos), wxSeekMode WXUNUSED(mode)) + { return wxInvalidOffset; } wxDECLARE_NO_COPY_CLASS(wxSocketInputStream); }; @@ -58,11 +61,11 @@ class WXDLLIMPEXP_NET wxSocketInputStream : public wxInputStream class WXDLLIMPEXP_NET wxSocketStream : public wxSocketInputStream, public wxSocketOutputStream { - public: - wxSocketStream(wxSocketBase& s); - virtual ~wxSocketStream(); +public: + wxSocketStream(wxSocketBase& s); + virtual ~wxSocketStream(); - wxDECLARE_NO_COPY_CLASS(wxSocketStream); + wxDECLARE_NO_COPY_CLASS(wxSocketStream); }; #endif diff --git a/src/common/imagbmp.cpp b/src/common/imagbmp.cpp index 9693a0d85e..388a0c8224 100644 --- a/src/common/imagbmp.cpp +++ b/src/common/imagbmp.cpp @@ -1280,11 +1280,11 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream, int iSel = wxNOT_FOUND; // remember how many bytes we read from the stream: - wxFileOffset offset = sizeof(IconDir); + wxFileOffset alreadySeeked = sizeof(IconDir); for (unsigned int i = 0; i < nIcons; i++ ) { - offset += stream.Read(pCurrentEntry, sizeof(ICONDIRENTRY)).LastRead(); + alreadySeeked += stream.Read(pCurrentEntry, sizeof(ICONDIRENTRY)).LastRead(); // bHeight and bColorCount are wxUint8 if ( pCurrentEntry->bWidth >= wMax ) @@ -1322,8 +1322,8 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream, // NOTE: seeking a positive amount in wxFromCurrent mode allows us to // load even non-seekable streams (see wxInputStream::SeekI docs)! - if (stream.SeekI(wxUINT32_SWAP_ON_BE(pCurrentEntry->dwImageOffset) - offset, - wxFromCurrent) == wxInvalidOffset) + wxFileOffset offset = wxUINT32_SWAP_ON_BE(pCurrentEntry->dwImageOffset) - alreadySeeked; + if (offset != 0 && stream.SeekI(offset, wxFromCurrent) == wxInvalidOffset) return false; bResult = LoadDib(image, stream, true, IsBmp); -- 2.47.2