summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/Common/ListFileUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/Common/ListFileUtils.cpp')
-rw-r--r--3rdparty/lzma/CPP/Common/ListFileUtils.cpp73
1 files changed, 53 insertions, 20 deletions
diff --git a/3rdparty/lzma/CPP/Common/ListFileUtils.cpp b/3rdparty/lzma/CPP/Common/ListFileUtils.cpp
index 3bf4ec29d9f..b361b378891 100644
--- a/3rdparty/lzma/CPP/Common/ListFileUtils.cpp
+++ b/3rdparty/lzma/CPP/Common/ListFileUtils.cpp
@@ -4,14 +4,19 @@
#include "../../C/CpuArch.h"
-#include "../Windows/FileIO.h"
-
#include "ListFileUtils.h"
#include "MyBuffer.h"
#include "StringConvert.h"
#include "UTFConvert.h"
-static const char kQuoteChar = '\"';
+#include "../Windows/FileIO.h"
+
+#define CSysInFile NWindows::NFile::NIO::CInFile
+#define MY_GET_LAST_ERROR ::GetLastError()
+
+
+#define kQuoteChar '\"'
+
static void AddName(UStringVector &strings, UString &s)
{
@@ -25,14 +30,39 @@ static void AddName(UStringVector &strings, UString &s)
strings.Add(s);
}
-bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage)
+
+static bool My_File_Read(CSysInFile &file, void *data, size_t size, DWORD &lastError)
+{
+ size_t processed;
+ if (!file.ReadFull(data, size, processed))
+ {
+ lastError = MY_GET_LAST_ERROR;
+ return false;
+ }
+ if (processed != size)
+ {
+ lastError = 1; // error: size of listfile was changed
+ return false;
+ }
+ return true;
+}
+
+
+bool ReadNamesFromListFile2(CFSTR fileName, UStringVector &strings, UINT codePage, DWORD &lastError)
{
- NWindows::NFile::NIO::CInFile file;
+ lastError = 0;
+ CSysInFile file;
if (!file.Open(fileName))
+ {
+ lastError = MY_GET_LAST_ERROR;
return false;
+ }
UInt64 fileSize;
if (!file.GetLength(fileSize))
+ {
+ lastError = MY_GET_LAST_ERROR;
return false;
+ }
if (fileSize >= ((UInt32)1 << 31) - 32)
return false;
UString u;
@@ -41,18 +71,17 @@ bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage
if ((fileSize & 1) != 0)
return false;
CByteArr buf((size_t)fileSize);
- UInt32 processed;
- if (!file.Read(buf, (UInt32)fileSize, processed))
- return false;
- if (processed != fileSize)
+
+ if (!My_File_Read(file, buf, (size_t)fileSize, lastError))
return false;
+
file.Close();
- unsigned num = (unsigned)fileSize / 2;
+ const unsigned num = (unsigned)fileSize / 2;
wchar_t *p = u.GetBuf(num);
if (codePage == MY__CP_UTF16)
for (unsigned i = 0; i < num; i++)
{
- wchar_t c = GetUi16(buf + i * 2);
+ wchar_t c = GetUi16(buf + (size_t)i * 2);
if (c == 0)
return false;
p[i] = c;
@@ -60,7 +89,7 @@ bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage
else
for (unsigned i = 0; i < num; i++)
{
- wchar_t c = (wchar_t)GetBe16(buf + i * 2);
+ wchar_t c = (wchar_t)GetBe16(buf + (size_t)i * 2);
if (c == 0)
return false;
p[i] = c;
@@ -72,19 +101,21 @@ bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage
{
AString s;
char *p = s.GetBuf((unsigned)fileSize);
- UInt32 processed;
- if (!file.Read(p, (UInt32)fileSize, processed))
- return false;
- if (processed != fileSize)
+
+ if (!My_File_Read(file, p, (size_t)fileSize, lastError))
return false;
+
file.Close();
- s.ReleaseBuf_CalcLen((unsigned)processed);
- if (s.Len() != processed)
+ s.ReleaseBuf_CalcLen((unsigned)fileSize);
+ if (s.Len() != fileSize)
return false;
// #ifdef CP_UTF8
if (codePage == CP_UTF8)
{
+ // we must check UTF8 here, if convert function doesn't check
+ if (!CheckUTF8_AString(s))
+ return false;
if (!ConvertUTF8ToUnicode(s, u))
return false;
}
@@ -94,7 +125,7 @@ bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage
}
const wchar_t kGoodBOM = 0xFEFF;
- const wchar_t kBadBOM = 0xFFFE;
+ // const wchar_t kBadBOM = 0xFFFE;
UString s;
unsigned i = 0;
@@ -102,9 +133,11 @@ bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage
for (; i < u.Len(); i++)
{
wchar_t c = u[i];
+ /*
if (c == kGoodBOM || c == kBadBOM)
return false;
- if (c == L'\n' || c == 0xD)
+ */
+ if (c == '\n' || c == 0xD)
{
AddName(strings, s);
s.Empty();