X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/de6185e212ebc37ff11ff70278e3c4f68419b097..db71eb0640221199170ac9ea83371c2d467fa456:/src/common/zipstrm.cpp diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index 1358b48275..6116b8e0c5 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -87,6 +87,9 @@ wxFORCE_LINK_THIS_MODULE(zipstrm) // static wxString ReadString(wxInputStream& stream, wxUint16 len, wxMBConv& conv) { + if (len == 0) + return wxEmptyString; + #if wxUSE_UNICODE wxCharBuffer buf(len); stream.Read(buf.data(), len); @@ -111,6 +114,14 @@ static inline wxUint32 CrackUint32(const char *m) return (n[3] << 24) | (n[2] << 16) | (n[1] << 8) | n[0]; } +// Decode a little endian wxUint16 number from a character array +// +static inline wxUint16 CrackUint16(const char *m) +{ + const unsigned char *n = (const unsigned char*)m; + return (n[1] << 8) | n[0]; +} + // Temporarily lower the logging level in debug mode to avoid a warning // from SeekI about seeking on a stream with data written back to it. // @@ -171,23 +182,23 @@ wxZipHeader::wxZipHeader(wxInputStream& stream, size_t size) wxUint8 wxZipHeader::Read8() { wxASSERT(m_pos < m_size); - return *wx_reinterpret_cast(wxUint8*, m_data + m_pos++); + return m_data[m_pos++]; } wxUint16 wxZipHeader::Read16() { wxASSERT(m_pos + 2 <= m_size); - wxUint16 n = *wx_reinterpret_cast(wxUint16*, m_data + m_pos); + wxUint16 n = CrackUint16(m_data + m_pos); m_pos += 2; - return wxUINT16_SWAP_ON_BE(n); + return n; } wxUint32 wxZipHeader::Read32() { wxASSERT(m_pos + 4 <= m_size); - wxUint32 n = *wx_reinterpret_cast(wxUint32*, m_data + m_pos); + wxUint32 n = CrackUint32(m_data + m_pos); m_pos += 4; - return wxUINT32_SWAP_ON_BE(n); + return n; } @@ -750,7 +761,7 @@ wxString wxZipEntry::GetName(wxPathFormat format /*=wxPATH_NATIVE*/) const case wxPATH_DOS: { wxString name(isDir ? m_Name + _T("\\") : m_Name); - for (size_t i = name.length() - 1; i > 0; --i) + for (size_t i = 0; i < name.length(); i++) if (name[i] == _T('/')) name[i] = _T('\\'); return name; @@ -1606,22 +1617,20 @@ wxStreamError wxZipInputStream::ReadLocal(bool readEndRec /*=false*/) return wxSTREAM_EOF; } - if (m_signature != LOCAL_MAGIC) { - wxLogError(_("error reading zip local header")); - return wxSTREAM_READ_ERROR; - } - - m_headerSize = m_entry.ReadLocal(*m_parent_i_stream, GetConv()); - m_signature = 0; - m_entry.SetOffset(m_position); - m_entry.SetKey(m_position); + if (m_signature == LOCAL_MAGIC) { + m_headerSize = m_entry.ReadLocal(*m_parent_i_stream, GetConv()); + m_signature = 0; + m_entry.SetOffset(m_position); + m_entry.SetKey(m_position); - if (!m_headerSize) { - return wxSTREAM_READ_ERROR; - } else { - m_TotalEntries++; - return wxSTREAM_NO_ERROR; + if (m_headerSize) { + m_TotalEntries++; + return wxSTREAM_NO_ERROR; + } } + + wxLogError(_("error reading zip local header")); + return wxSTREAM_READ_ERROR; } wxUint32 wxZipInputStream::ReadSignature()