]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fs_arc.cpp
fixing overrelease and out-of-bounds write, fixes #13725
[wxWidgets.git] / src / common / fs_arc.cpp
index 5df4232e85e38b36b03db03cb4acc8842a955901..4b4c382cac7e1ebea9721e357f464e27997c24e4 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        fs_arc.cpp
+// Name:        src/common/fs_arc.cpp
 // Purpose:     wxArchive file system
 // Author:      Vaclav Slavik, Mike Wetherell
 // Copyright:   (c) 1999 Vaclav Slavik, (c) 2006 Mike Wetherell
 
 #include "wx/fs_arc.h"
 
-#ifndef WXPRECOMP
+#ifndef WX_PRECOMP
     #include "wx/intl.h"
     #include "wx/log.h"
 #endif
 
-#include "wx/archive.h"
-#include "wx/fileback.h"
-#include "wx/thread.h"
+#if WXWIN_COMPATIBILITY_2_6 && wxUSE_ZIPSTREAM
+    #include "wx/zipstrm.h"
+#else
+    #include "wx/archive.h"
+#endif
+
+#include "wx/private/fileback.h"
 
 //---------------------------------------------------------------------------
 // wxArchiveFSCacheDataImpl
@@ -120,7 +124,7 @@ wxArchiveFSCacheDataImpl::~wxArchiveFSCacheDataImpl()
 
 wxArchiveFSEntry *wxArchiveFSCacheDataImpl::AddToCache(wxArchiveEntry *entry)
 {
-    m_hash[entry->GetName()] = entry;
+    m_hash[entry->GetName(wxPATH_UNIX)] = entry;
     wxArchiveFSEntry *fse = new wxArchiveFSEntry;
     *m_endptr = fse;
     (*m_endptr)->entry = entry;
@@ -131,10 +135,8 @@ wxArchiveFSEntry *wxArchiveFSCacheDataImpl::AddToCache(wxArchiveEntry *entry)
 
 void wxArchiveFSCacheDataImpl::CloseStreams()
 {
-    delete m_archive;
-    m_archive = NULL;
-    delete m_stream;
-    m_stream = NULL;
+    wxDELETE(m_archive);
+    wxDELETE(m_stream);
 }
 
 wxArchiveEntry *wxArchiveFSCacheDataImpl::Get(const wxString& name)
@@ -153,7 +155,7 @@ wxArchiveEntry *wxArchiveFSCacheDataImpl::Get(const wxString& name)
     {
         AddToCache(entry);
 
-        if (entry->GetName() == name)
+        if (entry->GetName(wxPATH_UNIX) == name)
             return entry;
     }
 
@@ -285,7 +287,7 @@ wxArchiveFSCacheData* wxArchiveFSCache::Add(
         const wxArchiveClassFactory& factory,
         wxInputStream *stream)
 {
-    wxArchiveFSCacheData& data(m_hash[name]);
+    wxArchiveFSCacheData& data = m_hash[name];
 
     if (stream->IsSeekable())
         data = wxArchiveFSCacheData(factory, stream);
@@ -356,7 +358,7 @@ wxFSFile* wxArchiveFSHandler::OpenFile(
         right = rightPart.GetFullPath(wxPATH_UNIX);
     }
 
-    if (right.GetChar(0) == wxT('/')) right = right.Mid(1);
+    if (!right.empty() && right.GetChar(0) == wxT('/')) right = right.Mid(1);
 
     if (!m_cache)
         m_cache = new wxArchiveFSCache;
@@ -391,20 +393,30 @@ wxFSFile* wxArchiveFSHandler::OpenFile(
     }
 
     wxArchiveInputStream *s = factory->NewStream(leftStream);
+    if ( !s )
+        return NULL;
+
     s->OpenEntry(*entry);
 
-    if (s && s->IsOk())
-        return new wxFSFile(s,
-                            key + right,
-                            GetMimeTypeFromExt(location),
-                            GetAnchor(location)
+    if (!s->IsOk())
+    {
+        delete s;
+        return NULL;
+    }
+
+#if WXWIN_COMPATIBILITY_2_6 && wxUSE_ZIPSTREAM
+    if (wxDynamicCast(factory, wxZipClassFactory))
+        ((wxZipInputStream*)s)->m_allowSeeking = true;
+#endif // WXWIN_COMPATIBILITY_2_6
+
+    return new wxFSFile(s,
+                        key + right,
+                        wxEmptyString,
+                        GetAnchor(location)
 #if wxUSE_DATETIME
-                            , entry->GetDateTime()
+                        , entry->GetDateTime()
 #endif // wxUSE_DATETIME
-                            );
-
-    delete s;
-    return NULL;
+                        );
 }
 
 wxString wxArchiveFSHandler::FindFirst(const wxString& spec, int flags)