aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Carroll <thecarrolls@jiminger.com>2011-11-27 15:17:04 -0500
committerJim Carroll <thecarrolls@jiminger.com>2011-11-27 15:25:59 -0500
commit3204eb9922ef32f4c9d41e8f4ce5c17b292e1ab3 (patch)
tree83afb6927e0d0b3c407b7638062d7bec7dbfd4eb
parentcc49b8581491436578d89fa5e4a85b71728e5d63 (diff)
[fix] fixes #12186. Fixed the missed exception catch of UnrarXLib within CFileRar.
-rw-r--r--xbmc/filesystem/FileRar.cpp258
-rw-r--r--xbmc/filesystem/FileRar.h5
-rw-r--r--xbmc/filesystem/RarManager.cpp3
3 files changed, 151 insertions, 115 deletions
diff --git a/xbmc/filesystem/FileRar.cpp b/xbmc/filesystem/FileRar.cpp
index 1b4023c538..9c87a35216 100644
--- a/xbmc/filesystem/FileRar.cpp
+++ b/xbmc/filesystem/FileRar.cpp
@@ -31,6 +31,7 @@
#include "settings/AdvancedSettings.h"
#include "FileItem.h"
#include "utils/log.h"
+#include "UnrarXLib/rar.hpp"
#ifndef _LINUX
#include <process.h>
@@ -81,7 +82,6 @@ void CFileRarExtractThread::OnStartup()
void CFileRarExtractThread::OnExit()
{
- hRunning.Reset();
}
void CFileRarExtractThread::Process()
@@ -91,7 +91,19 @@ void CFileRarExtractThread::Process()
if (AbortableWait(hRestart,1) == WAIT_SIGNALED)
{
bool Repeat = false;
- m_pExtract->ExtractCurrentFile(m_pCmd,*m_pArc,m_iSize,Repeat);
+ try
+ {
+ m_pExtract->ExtractCurrentFile(m_pCmd,*m_pArc,m_iSize,Repeat);
+ }
+ catch (int rarErrCode)
+ {
+ CLog::Log(LOGERROR,"filerar CFileRarExtractThread::Process failed. CmdExtract::ExtractCurrentFile threw a UnrarXLib error code of %d",rarErrCode);
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR,"filerar CFileRarExtractThread::Process failed. CmdExtract::ExtractCurrentFile threw an Unknown exception");
+ }
+
hRunning.Reset();
}
}
@@ -534,40 +546,51 @@ void CFileRar::InitFromUrl(const CURL& url)
void CFileRar::CleanUp()
{
#ifdef HAS_FILESYSTEM_RAR
- if (m_pExtractThread)
+ try
{
- if (m_pExtractThread->hRunning.WaitMSec(1))
+ if (m_pExtractThread)
{
- m_pExtract->GetDataIO().hQuit->Set();
- while (m_pExtractThread->hRunning.WaitMSec(1))
- Sleep(1);
+ if (m_pExtractThread->hRunning.WaitMSec(1))
+ {
+ m_pExtract->GetDataIO().hQuit->Set();
+ while (m_pExtractThread->hRunning.WaitMSec(1))
+ Sleep(1);
+ }
+ delete m_pExtract->GetDataIO().hBufferFilled;
+ delete m_pExtract->GetDataIO().hBufferEmpty;
+ delete m_pExtract->GetDataIO().hSeek;
+ delete m_pExtract->GetDataIO().hSeekDone;
+ delete m_pExtract->GetDataIO().hQuit;
+ }
+ if (m_pExtract)
+ {
+ delete m_pExtract;
+ m_pExtract = NULL;
+ }
+ if (m_pArc)
+ {
+ delete m_pArc;
+ m_pArc = NULL;
+ }
+ if (m_pCmd)
+ {
+ delete m_pCmd;
+ m_pCmd = NULL;
+ }
+ if (m_szBuffer)
+ {
+ delete[] m_szBuffer;
+ m_szBuffer = NULL;
+ m_szStartOfBuffer = NULL;
}
- delete m_pExtract->GetDataIO().hBufferFilled;
- delete m_pExtract->GetDataIO().hBufferEmpty;
- delete m_pExtract->GetDataIO().hSeek;
- delete m_pExtract->GetDataIO().hSeekDone;
- delete m_pExtract->GetDataIO().hQuit;
- }
- if (m_pExtract)
- {
- delete m_pExtract;
- m_pExtract = NULL;
- }
- if (m_pArc)
- {
- delete m_pArc;
- m_pArc = NULL;
}
- if (m_pCmd)
+ catch (int rarErrCode)
{
- delete m_pCmd;
- m_pCmd = NULL;
+ CLog::Log(LOGERROR,"filerar failed in UnrarXLib while deleting CFileRar with an UnrarXLib error code of %d",rarErrCode);
}
- if (m_szBuffer)
+ catch (...)
{
- delete[] m_szBuffer;
- m_szBuffer = NULL;
- m_szStartOfBuffer = NULL;
+ CLog::Log(LOGERROR,"filerar failed in UnrarXLib while deleting CFileRar with an Unknown exception");
}
#endif
}
@@ -575,112 +598,125 @@ void CFileRar::CleanUp()
bool CFileRar::OpenInArchive()
{
#ifdef HAS_FILESYSTEM_RAR
- int iHeaderSize;
-
- InitCRC();
-
- m_pCmd = new CommandData;
- if (!m_pCmd)
+ try
{
- CleanUp();
- return false;
- }
+ int iHeaderSize;
- // Set the arguments for the extract command
- strcpy(m_pCmd->Command, "X");
+ InitCRC();
- m_pCmd->AddArcName(const_cast<char*>(m_strRarPath.c_str()),NULL);
+ m_pCmd = new CommandData;
+ if (!m_pCmd)
+ {
+ CleanUp();
+ return false;
+ }
- strncpy(m_pCmd->ExtrPath, m_strCacheDir.c_str(), sizeof (m_pCmd->ExtrPath) - 2);
- m_pCmd->ExtrPath[sizeof (m_pCmd->ExtrPath) - 2] = 0;
- AddEndSlash(m_pCmd->ExtrPath);
+ // Set the arguments for the extract command
+ strcpy(m_pCmd->Command, "X");
- // Set password for encrypted archives
- if ((m_strPassword.size() > 0) &&
- (m_strPassword.size() < sizeof (m_pCmd->Password)))
- {
- strcpy(m_pCmd->Password, m_strPassword.c_str());
- }
+ m_pCmd->AddArcName(const_cast<char*>(m_strRarPath.c_str()),NULL);
- m_pCmd->ParseDone();
+ strncpy(m_pCmd->ExtrPath, m_strCacheDir.c_str(), sizeof (m_pCmd->ExtrPath) - 2);
+ m_pCmd->ExtrPath[sizeof (m_pCmd->ExtrPath) - 2] = 0;
+ AddEndSlash(m_pCmd->ExtrPath);
- // Open the archive
- m_pArc = new Archive(m_pCmd);
- if (!m_pArc)
- {
- CleanUp();
- return false;
- }
- if (!m_pArc->WOpen(m_strRarPath.c_str(),NULL))
- {
- CleanUp();
- return false;
- }
- if (!(m_pArc->IsOpened() && m_pArc->IsArchive(true)))
- {
- CleanUp();
- return false;
- }
+ // Set password for encrypted archives
+ if ((m_strPassword.size() > 0) &&
+ (m_strPassword.size() < sizeof (m_pCmd->Password)))
+ {
+ strcpy(m_pCmd->Password, m_strPassword.c_str());
+ }
- m_pExtract = new CmdExtract;
- if (!m_pExtract)
- {
- CleanUp();
- return false;
- }
- m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
- m_pExtract->GetDataIO().SetCurrentCommand(*(m_pCmd->Command));
- struct FindData FD;
- if (FindFile::FastFind(m_strRarPath.c_str(),NULL,&FD))
- m_pExtract->GetDataIO().TotalArcSize+=FD.Size;
- m_pExtract->ExtractArchiveInit(m_pCmd,*m_pArc);
-
- while (true)
- {
- if ((iHeaderSize = m_pArc->ReadHeader()) <= 0)
+ m_pCmd->ParseDone();
+
+ // Open the archive
+ m_pArc = new Archive(m_pCmd);
+ if (!m_pArc)
{
CleanUp();
return false;
}
-
- if (m_pArc->GetHeaderType() == FILE_HEAD)
+ if (!m_pArc->WOpen(m_strRarPath.c_str(),NULL))
+ {
+ CleanUp();
+ return false;
+ }
+ if (!(m_pArc->IsOpened() && m_pArc->IsArchive(true)))
{
- CStdString strFileName;
+ CleanUp();
+ return false;
+ }
- if (m_pArc->NewLhd.FileNameW && wcslen(m_pArc->NewLhd.FileNameW) > 0)
+ m_pExtract = new CmdExtract;
+ if (!m_pExtract)
+ {
+ CleanUp();
+ return false;
+ }
+ m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
+ m_pExtract->GetDataIO().SetCurrentCommand(*(m_pCmd->Command));
+ struct FindData FD;
+ if (FindFile::FastFind(m_strRarPath.c_str(),NULL,&FD))
+ m_pExtract->GetDataIO().TotalArcSize+=FD.Size;
+ m_pExtract->ExtractArchiveInit(m_pCmd,*m_pArc);
+
+ while (true)
+ {
+ if ((iHeaderSize = m_pArc->ReadHeader()) <= 0)
{
- g_charsetConverter.wToUTF8(m_pArc->NewLhd.FileNameW, strFileName);
+ CleanUp();
+ return false;
}
- else
+
+ if (m_pArc->GetHeaderType() == FILE_HEAD)
{
- g_charsetConverter.unknownToUTF8(m_pArc->NewLhd.FileName, strFileName);
- }
+ CStdString strFileName;
- /* replace back slashes into forward slashes */
- /* this could get us into troubles, file could two different files, one with / and one with \ */
- strFileName.Replace('\\', '/');
+ if (m_pArc->NewLhd.FileNameW && wcslen(m_pArc->NewLhd.FileNameW) > 0)
+ {
+ g_charsetConverter.wToUTF8(m_pArc->NewLhd.FileNameW, strFileName);
+ }
+ else
+ {
+ g_charsetConverter.unknownToUTF8(m_pArc->NewLhd.FileName, strFileName);
+ }
- if (strFileName == m_strPathInRar)
- {
- break;
+ /* replace back slashes into forward slashes */
+ /* this could get us into troubles, file could two different files, one with / and one with \ */
+ strFileName.Replace('\\', '/');
+
+ if (strFileName == m_strPathInRar)
+ {
+ break;
+ }
}
- }
- m_pArc->SeekToNext();
- }
+ m_pArc->SeekToNext();
+ }
- m_szBuffer = new byte[MAXWINMEMSIZE];
- m_szStartOfBuffer = m_szBuffer;
- m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
- m_iDataInBuffer = -1;
- m_iFilePosition = 0;
- m_iBufferStart = 0;
+ m_szBuffer = new byte[MAXWINMEMSIZE];
+ m_szStartOfBuffer = m_szBuffer;
+ m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
+ m_iDataInBuffer = -1;
+ m_iFilePosition = 0;
+ m_iBufferStart = 0;
- delete m_pExtractThread;
- m_pExtractThread = new CFileRarExtractThread();
- m_pExtractThread->Start(m_pArc,m_pCmd,m_pExtract,iHeaderSize);
+ delete m_pExtractThread;
+ m_pExtractThread = new CFileRarExtractThread();
+ m_pExtractThread->Start(m_pArc,m_pCmd,m_pExtract,iHeaderSize);
- return true;
+ return true;
+ }
+ catch (int rarErrCode)
+ {
+ CLog::Log(LOGERROR,"filerar failed in UnrarXLib while CFileRar::OpenInArchive with an UnrarXLib error code of %d",rarErrCode);
+ return false;
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR,"filerar failed in UnrarXLib while CFileRar::OpenInArchive with an Unknown exception");
+ return false;
+ }
#else
return false;
#endif
diff --git a/xbmc/filesystem/FileRar.h b/xbmc/filesystem/FileRar.h
index dd825d2e7e..83941dcd9b 100644
--- a/xbmc/filesystem/FileRar.h
+++ b/xbmc/filesystem/FileRar.h
@@ -26,10 +26,13 @@
#define FILERAR_H_
#include "File.h"
-#include "UnrarXLib/rar.hpp"
#include "threads/Thread.h"
#include "threads/Event.h"
+class CmdExtract;
+class CommandData;
+class Archive;
+
namespace XFILE
{
#ifdef HAS_FILESYSTEM_RAR
diff --git a/xbmc/filesystem/RarManager.cpp b/xbmc/filesystem/RarManager.cpp
index 95e90e1a4e..3265ab840e 100644
--- a/xbmc/filesystem/RarManager.cpp
+++ b/xbmc/filesystem/RarManager.cpp
@@ -21,9 +21,6 @@
#include "system.h"
#include "RarManager.h"
-#ifdef HAS_FILESYSTEM_RAR
-#include "UnrarXLib/rar.hpp"
-#endif
#include "Util.h"
#include "utils/CharsetConverter.h"
#include "utils/URIUtils.h"