Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/UI/Common')
-rw-r--r--CPP/7zip/UI/Common/ArchiveCommandLine.cpp38
-rw-r--r--CPP/7zip/UI/Common/ArchiveExtractCallback.cpp22
-rw-r--r--CPP/7zip/UI/Common/ArchiveOpenCallback.cpp33
-rw-r--r--CPP/7zip/UI/Common/Bench.cpp21
-rw-r--r--CPP/7zip/UI/Common/PropIDUtils.cpp18
-rw-r--r--CPP/7zip/UI/Common/SortUtils.cpp4
-rw-r--r--CPP/7zip/UI/Common/TempFiles.cpp2
-rw-r--r--CPP/7zip/UI/Common/UpdateCallback.cpp1
-rw-r--r--CPP/7zip/UI/Common/UpdatePair.cpp1
-rw-r--r--CPP/7zip/UI/Common/WorkDir.cpp2
10 files changed, 105 insertions, 37 deletions
diff --git a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
index 067b32f3..f39cf162 100644
--- a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
+++ b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
@@ -271,7 +271,7 @@ static const unsigned kCommandIndex = 0;
static const char *kCannotFindListFile = "Cannot find listfile";
static const char *kIncorrectListFile = "Incorrect item in listfile.\nCheck charset encoding and -scs switch.";
static const char *kTerminalOutError = "I won't write compressed data to a terminal";
-static const char *kSameTerminalError = "I won't write data and program's messages to same terminal";
+static const char *kSameTerminalError = "I won't write data and program's messages to same stream";
static const char *kEmptyFilePath = "Empty file path";
static const char *kCannotFindArchive = "Cannot find archive";
@@ -1219,8 +1219,26 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
if (isExtractGroupCommand)
{
- if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)
- throw CArcCmdLineException(kSameTerminalError);
+ if (options.StdOutMode)
+ {
+ if (
+ options.Number_for_Percents == k_OutStream_stdout
+ // || options.Number_for_Out == k_OutStream_stdout
+ // || options.Number_for_Errors == k_OutStream_stdout
+ ||
+ (
+ (options.IsStdOutTerminal && options.IsStdErrTerminal)
+ &&
+ (
+ options.Number_for_Percents != k_OutStream_disabled
+ // || options.Number_for_Out != k_OutStream_disabled
+ // || options.Number_for_Errors != k_OutStream_disabled
+ )
+ )
+ )
+ throw CArcCmdLineException(kSameTerminalError);
+ }
+
if (parser[NKey::kOutputDir].ThereIs)
{
eo.OutputDir = us2fs(parser[NKey::kOutputDir].PostStrings[0]);
@@ -1293,8 +1311,18 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
if (updateOptions.StdOutMode && updateOptions.EMailMode)
throw CArcCmdLineException("stdout mode and email mode cannot be combined");
- if (updateOptions.StdOutMode && options.IsStdOutTerminal)
- throw CArcCmdLineException(kTerminalOutError);
+
+ if (updateOptions.StdOutMode)
+ {
+ if (options.IsStdOutTerminal)
+ throw CArcCmdLineException(kTerminalOutError);
+
+ if (options.Number_for_Percents == k_OutStream_stdout
+ || options.Number_for_Out == k_OutStream_stdout
+ || options.Number_for_Errors == k_OutStream_stdout)
+ throw CArcCmdLineException(kSameTerminalError);
+ }
+
if (updateOptions.StdInMode)
updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();
diff --git a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
index 877326b8..fe9c3366 100644
--- a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
+++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
@@ -451,32 +451,42 @@ static UString GetDirPrefixOf(const UString &src)
return s;
}
-static bool IsSafePath(const UString &path)
+#endif
+
+
+bool IsSafePath(const UString &path)
{
+ if (NName::IsAbsolutePath(path))
+ return false;
+
UStringVector parts;
SplitPathToParts(path, parts);
- int level = 0;
- FOR_VECTOR(i, parts)
+ unsigned level = 0;
+
+ FOR_VECTOR (i, parts)
{
const UString &s = parts[i];
if (s.IsEmpty())
+ {
+ if (i == 0)
+ return false;
continue;
+ }
if (s == L".")
continue;
if (s == L"..")
{
- if (level <= 0)
+ if (level == 0)
return false;
level--;
}
else
level++;
}
+
return level > 0;
}
-#endif
-
bool CensorNode_CheckPath2(const NWildcard::CCensorNode &node, const CReadArcItem &item, bool &include)
{
diff --git a/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp b/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp
index 47af7251..359835d3 100644
--- a/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp
+++ b/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp
@@ -73,18 +73,40 @@ struct CInFileStreamVol: public CInFileStream
}
};
+
+// from ArchiveExtractCallback.cpp
+bool IsSafePath(const UString &path);
+
STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)
{
COM_TRY_BEGIN
*inStream = NULL;
+
if (_subArchiveMode)
return S_FALSE;
if (Callback)
{
RINOK(Callback->Open_CheckBreak());
}
+
+ UString name2 = name;
+
+
+ #ifndef _SFX
+
+ #ifdef _WIN32
+ name2.Replace(L'/', WCHAR_PATH_SEPARATOR);
+ #endif
+
+ // if (!allowAbsVolPaths)
+ if (!IsSafePath(name2))
+ return S_FALSE;
+
+ #endif
+
+
FString fullPath;
- if (!NFile::NName::GetFullPath(_folderPrefix, us2fs(name), fullPath))
+ if (!NFile::NName::GetFullPath(_folderPrefix, us2fs(name2), fullPath))
return S_FALSE;
if (!_fileInfo.Find(fullPath))
return S_FALSE;
@@ -93,10 +115,15 @@ STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStre
CInFileStreamVol *inFile = new CInFileStreamVol;
CMyComPtr<IInStream> inStreamTemp = inFile;
if (!inFile->Open(fullPath))
- return ::GetLastError();
+ {
+ DWORD lastError = ::GetLastError();
+ if (lastError == 0)
+ return E_FAIL;
+ return HRESULT_FROM_WIN32(lastError);
+ }
FileSizes.Add(_fileInfo.Size);
- FileNames.Add(name);
+ FileNames.Add(name2);
inFile->FileNameIndex = FileNames_WasUsed.Add(true);
inFile->OpenCallbackImp = this;
inFile->OpenCallbackRef = this;
diff --git a/CPP/7zip/UI/Common/Bench.cpp b/CPP/7zip/UI/Common/Bench.cpp
index 3833f07f..f861f503 100644
--- a/CPP/7zip/UI/Common/Bench.cpp
+++ b/CPP/7zip/UI/Common/Bench.cpp
@@ -32,9 +32,7 @@
#include "../../../../C/Alloc.h"
#include "../../../../C/CpuArch.h"
-#if defined(_WIN32)
#include "../../../Windows/System.h"
-#endif
#ifndef _7ZIP_ST
#include "../../../Windows/Synchronization.h"
@@ -1860,11 +1858,15 @@ static void PrintTotals(IBenchPrintCallback &f, bool showFreq, UInt64 cpuFreq, c
PrintResults(f, res.Usage / numIterations2, res.RPU / numIterations2, res.Rating / numIterations2, showFreq, cpuFreq);
}
-static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)
+static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString,
+ bool size_Defined, UInt64 size, const char *threadsString, UInt32 numThreads)
{
f.Print("RAM ");
f.Print(sizeString);
- PrintNumber(f, (size >> 20), 6);
+ if (size_Defined)
+ PrintNumber(f, (size >> 20), 6);
+ else
+ f.Print(" ?");
f.Print(" MB, # ");
f.Print(threadsString);
PrintNumber(f, numThreads, 3);
@@ -2450,15 +2452,13 @@ HRESULT Bench(
return S_FALSE;
UInt32 numCPUs = 1;
- UInt64 ramSize = (UInt64)512 << 20;
+ UInt64 ramSize = (UInt64)(sizeof(size_t)) << 29;
#ifndef _7ZIP_ST
numCPUs = NSystem::GetNumberOfProcessors();
#endif
- #if defined(_WIN32)
- ramSize = NSystem::GetRamSize();
- #endif
+ bool ramSize_Defined = NSystem::GetRamSize(ramSize);
UInt32 numThreadsSpecified = numCPUs;
@@ -2640,7 +2640,7 @@ HRESULT Bench(
{
printCallback->NewLine();
printCallback->NewLine();
- PrintRequirements(*printCallback, "size: ", ramSize, "CPU hardware threads:", numCPUs);
+ PrintRequirements(*printCallback, "size: ", ramSize_Defined, ramSize, "CPU hardware threads:", numCPUs);
}
if (numThreadsSpecified < 1 || numThreadsSpecified > kNumThreadsMax)
@@ -2834,6 +2834,7 @@ HRESULT Bench(
dicSizeLog = (UInt64)1 << 20;
#endif
+ if (ramSize_Defined)
for (; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)
if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog), totalBenchMode) + (8 << 20) <= ramSize)
break;
@@ -2848,7 +2849,7 @@ HRESULT Bench(
}
}
- PrintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dict, totalBenchMode), "Benchmark threads: ", numThreads);
+ PrintRequirements(f, "usage:", true, GetBenchMemoryUsage(numThreads, dict, totalBenchMode), "Benchmark threads: ", numThreads);
f.NewLine();
diff --git a/CPP/7zip/UI/Common/PropIDUtils.cpp b/CPP/7zip/UI/Common/PropIDUtils.cpp
index 32001624..dccc08b1 100644
--- a/CPP/7zip/UI/Common/PropIDUtils.cpp
+++ b/CPP/7zip/UI/Common/PropIDUtils.cpp
@@ -142,14 +142,16 @@ void ConvertPropertyToShortString(char *dest, const PROPVARIANT &prop, PROPID pr
case kpidVa:
{
UInt64 v = 0;
- if (ConvertPropVariantToUInt64(prop, v))
- {
- dest[0] = '0';
- dest[1] = 'x';
- ConvertUInt64ToHex(prop.ulVal, dest + 2);
- return;
- }
- break;
+ if (prop.vt == VT_UI4)
+ v = prop.ulVal;
+ else if (prop.vt == VT_UI8)
+ v = (UInt64)prop.uhVal.QuadPart;
+ else
+ break;
+ dest[0] = '0';
+ dest[1] = 'x';
+ ConvertUInt64ToHex(v, dest + 2);
+ return;
}
}
diff --git a/CPP/7zip/UI/Common/SortUtils.cpp b/CPP/7zip/UI/Common/SortUtils.cpp
index b7e422a2..5f29249b 100644
--- a/CPP/7zip/UI/Common/SortUtils.cpp
+++ b/CPP/7zip/UI/Common/SortUtils.cpp
@@ -14,8 +14,10 @@ static int CompareStrings(const unsigned *p1, const unsigned *p2, void *param)
void SortFileNames(const UStringVector &strings, CUIntVector &indices)
{
- unsigned numItems = strings.Size();
+ const unsigned numItems = strings.Size();
indices.ClearAndSetSize(numItems);
+ if (numItems == 0)
+ return;
unsigned *vals = &indices[0];
for (unsigned i = 0; i < numItems; i++)
vals[i] = i;
diff --git a/CPP/7zip/UI/Common/TempFiles.cpp b/CPP/7zip/UI/Common/TempFiles.cpp
index 0c13ae15..2f868381 100644
--- a/CPP/7zip/UI/Common/TempFiles.cpp
+++ b/CPP/7zip/UI/Common/TempFiles.cpp
@@ -17,5 +17,3 @@ void CTempFiles::Clear()
Paths.DeleteBack();
}
}
-
-
diff --git a/CPP/7zip/UI/Common/UpdateCallback.cpp b/CPP/7zip/UI/Common/UpdateCallback.cpp
index ea8f47e1..6c439cfd 100644
--- a/CPP/7zip/UI/Common/UpdateCallback.cpp
+++ b/CPP/7zip/UI/Common/UpdateCallback.cpp
@@ -757,4 +757,3 @@ void CArchiveUpdateCallback::InFileStream_On_Destroy(UINT_PTR val)
}
throw 20141125;
}
-
diff --git a/CPP/7zip/UI/Common/UpdatePair.cpp b/CPP/7zip/UI/Common/UpdatePair.cpp
index 68701400..e2115197 100644
--- a/CPP/7zip/UI/Common/UpdatePair.cpp
+++ b/CPP/7zip/UI/Common/UpdatePair.cpp
@@ -92,6 +92,7 @@ void GetUpdatePairInfoList(
{
arcIndices.ClearAndSetSize(numArcItems);
+ if (numArcItems != 0)
{
unsigned *vals = &arcIndices[0];
for (unsigned i = 0; i < numArcItems; i++)
diff --git a/CPP/7zip/UI/Common/WorkDir.cpp b/CPP/7zip/UI/Common/WorkDir.cpp
index 735cdda4..284eaa16 100644
--- a/CPP/7zip/UI/Common/WorkDir.cpp
+++ b/CPP/7zip/UI/Common/WorkDir.cpp
@@ -17,7 +17,7 @@ FString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const FString &path, FStr
{
NWorkDir::NMode::EEnum mode = workDirInfo.Mode;
- #ifndef UNDER_CE
+ #if defined(_WIN32) && !defined(UNDER_CE)
if (workDirInfo.ForRemovableOnly)
{
mode = NWorkDir::NMode::kCurrent;