Skip to content
This repository
Browse code

Merge pull request #549 from jimfcarroll/rar-exception-fix

[fix] fixes #12186. Fixed the missed exception catch of UnrarXLib in CFileRar
  • Loading branch information...
commit beecf524b37334d6a4bdef8811ddc571b58b4861 2 parents 683abe0 + 3204eb9
authored
258  xbmc/filesystem/FileRar.cpp
@@ -31,6 +31,7 @@
31 31
 #include "settings/AdvancedSettings.h"
32 32
 #include "FileItem.h"
33 33
 #include "utils/log.h"
  34
+#include "UnrarXLib/rar.hpp"
34 35
 
35 36
 #ifndef _LINUX
36 37
 #include <process.h>
@@ -81,7 +82,6 @@ void CFileRarExtractThread::OnStartup()
81 82
 
82 83
 void CFileRarExtractThread::OnExit()
83 84
 {
84  
-  hRunning.Reset();
85 85
 }
86 86
 
87 87
 void CFileRarExtractThread::Process()
@@ -91,7 +91,19 @@ void CFileRarExtractThread::Process()
91 91
     if (AbortableWait(hRestart,1) == WAIT_SIGNALED)
92 92
     {
93 93
       bool Repeat = false;
94  
-      m_pExtract->ExtractCurrentFile(m_pCmd,*m_pArc,m_iSize,Repeat);
  94
+      try
  95
+      {
  96
+        m_pExtract->ExtractCurrentFile(m_pCmd,*m_pArc,m_iSize,Repeat);
  97
+      }
  98
+      catch (int rarErrCode)
  99
+      {
  100
+        CLog::Log(LOGERROR,"filerar CFileRarExtractThread::Process failed. CmdExtract::ExtractCurrentFile threw a UnrarXLib error code of %d",rarErrCode);
  101
+      }
  102
+      catch (...)
  103
+      {
  104
+        CLog::Log(LOGERROR,"filerar CFileRarExtractThread::Process failed. CmdExtract::ExtractCurrentFile threw an Unknown exception");
  105
+      }
  106
+
95 107
       hRunning.Reset();
96 108
     }
97 109
   }
@@ -534,40 +546,51 @@ void CFileRar::InitFromUrl(const CURL& url)
534 546
 void CFileRar::CleanUp()
535 547
 {
536 548
 #ifdef HAS_FILESYSTEM_RAR
537  
-  if (m_pExtractThread)
  549
+  try
538 550
   {
539  
-    if (m_pExtractThread->hRunning.WaitMSec(1))
  551
+    if (m_pExtractThread)
540 552
     {
541  
-      m_pExtract->GetDataIO().hQuit->Set();
542  
-      while (m_pExtractThread->hRunning.WaitMSec(1))
543  
-        Sleep(1);
  553
+      if (m_pExtractThread->hRunning.WaitMSec(1))
  554
+      {
  555
+        m_pExtract->GetDataIO().hQuit->Set();
  556
+        while (m_pExtractThread->hRunning.WaitMSec(1))
  557
+          Sleep(1);
  558
+      }
  559
+      delete m_pExtract->GetDataIO().hBufferFilled;
  560
+      delete m_pExtract->GetDataIO().hBufferEmpty;
  561
+      delete m_pExtract->GetDataIO().hSeek;
  562
+      delete m_pExtract->GetDataIO().hSeekDone;
  563
+      delete m_pExtract->GetDataIO().hQuit;
  564
+    }
  565
+    if (m_pExtract)
  566
+    {
  567
+      delete m_pExtract;
  568
+      m_pExtract = NULL;
  569
+    }
  570
+    if (m_pArc)
  571
+    {
  572
+      delete m_pArc;
  573
+      m_pArc = NULL;
  574
+    }
  575
+    if (m_pCmd)
  576
+    {
  577
+      delete m_pCmd;
  578
+      m_pCmd = NULL;
  579
+    }
  580
+    if (m_szBuffer)
  581
+    {
  582
+      delete[] m_szBuffer;
  583
+      m_szBuffer = NULL;
  584
+      m_szStartOfBuffer = NULL;
544 585
     }
545  
-    delete m_pExtract->GetDataIO().hBufferFilled;
546  
-    delete m_pExtract->GetDataIO().hBufferEmpty;
547  
-    delete m_pExtract->GetDataIO().hSeek;
548  
-    delete m_pExtract->GetDataIO().hSeekDone;
549  
-    delete m_pExtract->GetDataIO().hQuit;
550  
-  }
551  
-  if (m_pExtract)
552  
-  {
553  
-    delete m_pExtract;
554  
-    m_pExtract = NULL;
555  
-  }
556  
-  if (m_pArc)
557  
-  {
558  
-    delete m_pArc;
559  
-    m_pArc = NULL;
560 586
   }
561  
-  if (m_pCmd)
  587
+  catch (int rarErrCode)
562 588
   {
563  
-    delete m_pCmd;
564  
-    m_pCmd = NULL;
  589
+    CLog::Log(LOGERROR,"filerar failed in UnrarXLib while deleting CFileRar with an UnrarXLib error code of %d",rarErrCode);
565 590
   }
566  
-  if (m_szBuffer)
  591
+  catch (...)
567 592
   {
568  
-    delete[] m_szBuffer;
569  
-    m_szBuffer = NULL;
570  
-    m_szStartOfBuffer = NULL;
  593
+    CLog::Log(LOGERROR,"filerar failed in UnrarXLib while deleting CFileRar with an Unknown exception");
571 594
   }
572 595
 #endif
573 596
 }
@@ -575,112 +598,125 @@ void CFileRar::CleanUp()
575 598
 bool CFileRar::OpenInArchive()
576 599
 {
577 600
 #ifdef HAS_FILESYSTEM_RAR
578  
-  int iHeaderSize;
579  
-
580  
-  InitCRC();
581  
-
582  
-  m_pCmd = new CommandData;
583  
-  if (!m_pCmd)
  601
+  try
584 602
   {
585  
-    CleanUp();
586  
-    return false;
587  
-  }
  603
+    int iHeaderSize;
588 604
 
589  
-  // Set the arguments for the extract command
590  
-  strcpy(m_pCmd->Command, "X");
  605
+    InitCRC();
591 606
 
592  
-  m_pCmd->AddArcName(const_cast<char*>(m_strRarPath.c_str()),NULL);
  607
+    m_pCmd = new CommandData;
  608
+    if (!m_pCmd)
  609
+    {
  610
+      CleanUp();
  611
+      return false;
  612
+    }
593 613
 
594  
-  strncpy(m_pCmd->ExtrPath, m_strCacheDir.c_str(), sizeof (m_pCmd->ExtrPath) - 2);
595  
-  m_pCmd->ExtrPath[sizeof (m_pCmd->ExtrPath) - 2] = 0;
596  
-  AddEndSlash(m_pCmd->ExtrPath);
  614
+    // Set the arguments for the extract command
  615
+    strcpy(m_pCmd->Command, "X");
597 616
 
598  
-  // Set password for encrypted archives
599  
-  if ((m_strPassword.size() > 0) &&
600  
-      (m_strPassword.size() < sizeof (m_pCmd->Password)))
601  
-  {
602  
-    strcpy(m_pCmd->Password, m_strPassword.c_str());
603  
-  }
  617
+    m_pCmd->AddArcName(const_cast<char*>(m_strRarPath.c_str()),NULL);
604 618
 
605  
-  m_pCmd->ParseDone();
  619
+    strncpy(m_pCmd->ExtrPath, m_strCacheDir.c_str(), sizeof (m_pCmd->ExtrPath) - 2);
  620
+    m_pCmd->ExtrPath[sizeof (m_pCmd->ExtrPath) - 2] = 0;
  621
+    AddEndSlash(m_pCmd->ExtrPath);
606 622
 
607  
-  // Open the archive
608  
-  m_pArc = new Archive(m_pCmd);
609  
-  if (!m_pArc)
610  
-  {
611  
-    CleanUp();
612  
-    return false;
613  
-  }
614  
-  if (!m_pArc->WOpen(m_strRarPath.c_str(),NULL))
615  
-  {
616  
-    CleanUp();
617  
-    return false;
618  
-  }
619  
-  if (!(m_pArc->IsOpened() && m_pArc->IsArchive(true)))
620  
-  {
621  
-    CleanUp();
622  
-    return false;
623  
-  }
  623
+    // Set password for encrypted archives
  624
+    if ((m_strPassword.size() > 0) &&
  625
+        (m_strPassword.size() < sizeof (m_pCmd->Password)))
  626
+    {
  627
+      strcpy(m_pCmd->Password, m_strPassword.c_str());
  628
+    }
624 629
 
625  
-  m_pExtract = new CmdExtract;
626  
-  if (!m_pExtract)
627  
-  {
628  
-    CleanUp();
629  
-    return false;
630  
-  }
631  
-  m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
632  
-  m_pExtract->GetDataIO().SetCurrentCommand(*(m_pCmd->Command));
633  
-  struct FindData FD;
634  
-  if (FindFile::FastFind(m_strRarPath.c_str(),NULL,&FD))
635  
-    m_pExtract->GetDataIO().TotalArcSize+=FD.Size;
636  
-  m_pExtract->ExtractArchiveInit(m_pCmd,*m_pArc);
637  
-
638  
-  while (true)
639  
-  {
640  
-    if ((iHeaderSize = m_pArc->ReadHeader()) <= 0)
  630
+    m_pCmd->ParseDone();
  631
+
  632
+    // Open the archive
  633
+    m_pArc = new Archive(m_pCmd);
  634
+    if (!m_pArc)
641 635
     {
642 636
       CleanUp();
643 637
       return false;
644 638
     }
645  
-
646  
-    if (m_pArc->GetHeaderType() == FILE_HEAD)
  639
+    if (!m_pArc->WOpen(m_strRarPath.c_str(),NULL))
  640
+    {
  641
+      CleanUp();
  642
+      return false;
  643
+    }
  644
+    if (!(m_pArc->IsOpened() && m_pArc->IsArchive(true)))
647 645
     {
648  
-      CStdString strFileName;
  646
+      CleanUp();
  647
+      return false;
  648
+    }
649 649
 
650  
-      if (m_pArc->NewLhd.FileNameW && wcslen(m_pArc->NewLhd.FileNameW) > 0)
  650
+    m_pExtract = new CmdExtract;
  651
+    if (!m_pExtract)
  652
+    {
  653
+      CleanUp();
  654
+      return false;
  655
+    }
  656
+    m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
  657
+    m_pExtract->GetDataIO().SetCurrentCommand(*(m_pCmd->Command));
  658
+    struct FindData FD;
  659
+    if (FindFile::FastFind(m_strRarPath.c_str(),NULL,&FD))
  660
+      m_pExtract->GetDataIO().TotalArcSize+=FD.Size;
  661
+    m_pExtract->ExtractArchiveInit(m_pCmd,*m_pArc);
  662
+
  663
+    while (true)
  664
+    {
  665
+      if ((iHeaderSize = m_pArc->ReadHeader()) <= 0)
651 666
       {
652  
-        g_charsetConverter.wToUTF8(m_pArc->NewLhd.FileNameW, strFileName);
  667
+        CleanUp();
  668
+        return false;
653 669
       }
654  
-      else
  670
+
  671
+      if (m_pArc->GetHeaderType() == FILE_HEAD)
655 672
       {
656  
-        g_charsetConverter.unknownToUTF8(m_pArc->NewLhd.FileName, strFileName);
657  
-      }
  673
+        CStdString strFileName;
658 674
 
659  
-      /* replace back slashes into forward slashes */
660  
-      /* this could get us into troubles, file could two different files, one with / and one with \ */
661  
-      strFileName.Replace('\\', '/');
  675
+        if (m_pArc->NewLhd.FileNameW && wcslen(m_pArc->NewLhd.FileNameW) > 0)
  676
+        {
  677
+          g_charsetConverter.wToUTF8(m_pArc->NewLhd.FileNameW, strFileName);
  678
+        }
  679
+        else
  680
+        {
  681
+          g_charsetConverter.unknownToUTF8(m_pArc->NewLhd.FileName, strFileName);
  682
+        }
662 683
 
663  
-      if (strFileName == m_strPathInRar)
664  
-      {
665  
-        break;
  684
+        /* replace back slashes into forward slashes */
  685
+        /* this could get us into troubles, file could two different files, one with / and one with \ */
  686
+        strFileName.Replace('\\', '/');
  687
+
  688
+        if (strFileName == m_strPathInRar)
  689
+        {
  690
+          break;
  691
+        }
666 692
       }
667  
-    }
668 693
 
669  
-    m_pArc->SeekToNext();
670  
-  }
  694
+      m_pArc->SeekToNext();
  695
+    }
671 696
 
672  
-  m_szBuffer = new byte[MAXWINMEMSIZE];
673  
-  m_szStartOfBuffer = m_szBuffer;
674  
-  m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
675  
-  m_iDataInBuffer = -1;
676  
-  m_iFilePosition = 0;
677  
-  m_iBufferStart = 0;
  697
+    m_szBuffer = new byte[MAXWINMEMSIZE];
  698
+    m_szStartOfBuffer = m_szBuffer;
  699
+    m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
  700
+    m_iDataInBuffer = -1;
  701
+    m_iFilePosition = 0;
  702
+    m_iBufferStart = 0;
678 703
 
679  
-  delete m_pExtractThread;
680  
-  m_pExtractThread = new CFileRarExtractThread();
681  
-  m_pExtractThread->Start(m_pArc,m_pCmd,m_pExtract,iHeaderSize);
  704
+    delete m_pExtractThread;
  705
+    m_pExtractThread = new CFileRarExtractThread();
  706
+    m_pExtractThread->Start(m_pArc,m_pCmd,m_pExtract,iHeaderSize);
682 707
 
683  
-  return true;
  708
+    return true;
  709
+  }
  710
+  catch (int rarErrCode)
  711
+  {
  712
+    CLog::Log(LOGERROR,"filerar failed in UnrarXLib while CFileRar::OpenInArchive with an UnrarXLib error code of %d",rarErrCode);
  713
+    return false;
  714
+  }
  715
+  catch (...)
  716
+  {
  717
+    CLog::Log(LOGERROR,"filerar failed in UnrarXLib while CFileRar::OpenInArchive with an Unknown exception");
  718
+    return false;
  719
+  }
684 720
 #else
685 721
   return false;
686 722
 #endif
5  xbmc/filesystem/FileRar.h
@@ -26,10 +26,13 @@
26 26
 #define FILERAR_H_
27 27
 
28 28
 #include "File.h"
29  
-#include "UnrarXLib/rar.hpp"
30 29
 #include "threads/Thread.h"
31 30
 #include "threads/Event.h"
32 31
 
  32
+class CmdExtract;
  33
+class CommandData;
  34
+class Archive;
  35
+
33 36
 namespace XFILE
34 37
 {
35 38
 #ifdef HAS_FILESYSTEM_RAR
3  xbmc/filesystem/RarManager.cpp
@@ -21,9 +21,6 @@
21 21
 
22 22
 #include "system.h"
23 23
 #include "RarManager.h"
24  
-#ifdef HAS_FILESYSTEM_RAR
25  
-#include "UnrarXLib/rar.hpp"
26  
-#endif
27 24
 #include "Util.h"
28 25
 #include "utils/CharsetConverter.h"
29 26
 #include "utils/URIUtils.h"

0 notes on commit beecf52

Please sign in to comment.
Something went wrong with that request. Please try again.