Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
remittor committed Nov 29, 2019
2 parents d69a221 + 680fd69 commit 255573f
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void WcxPrintMsgA(int level, const char * fmt, ...)
int len = _vsnprintf(buf + 9, _countof(buf)-2, fmt, argptr);
if (len < 0)
len = 0;
buf[8 + len] = 0;
buf[9 + len] = 0;
OutputDebugStringA(buf);
va_end(argptr);
}
Expand All @@ -47,7 +47,7 @@ void WcxPrintMsgW(int level, const wchar_t * fmt, ...)
int len = _vsnwprintf(buf + 9, _countof(buf)-2, fmt, argptr);
if (len < 0)
len = 0;
buf[8 + len] = 0;
buf[9 + len] = 0;
OutputDebugStringW(buf);
va_end(argptr);
}
Expand Down
17 changes: 8 additions & 9 deletions src/lz4lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

namespace lz4 {

bool is_legacy_frame(DWORD magic)
Format check_frame_magic(DWORD magic)
{
return (magic == LEGACY_MAGICNUMBER) ? true : false;
}

bool check_frame_magic(DWORD magic)
{
return (magic == LZ4F_MAGICNUMBER || magic == LEGACY_MAGICNUMBER) ? true : false;
if (is_legacy_frame(magic))
return ffLegacy;

return (magic == LZ4F_MAGICNUMBER) ? ffActual : ffUnknown;
}

int check_file_header(HANDLE hFile, UINT64 file_size)
Expand Down Expand Up @@ -40,9 +38,10 @@ int check_file_header(HANDLE hFile, UINT64 file_size)
FIN_IF(!x, -5);
FIN_IF(dwRead != sizeof(header.magic), -6);

FIN_IF(lz4::check_frame_magic(header.magic) == FALSE, -7);
Format fmt = lz4::check_frame_magic(header.magic);
FIN_IF(fmt == ffUnknown, -7);

hr = 0;
hr = (int)fmt;

fin:
return hr;
Expand Down
11 changes: 8 additions & 3 deletions src/lz4lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ const DWORD BLOCKUNCOMPRES_FLAG = 0x80000000UL; // LZ4F_BLOCKUNCOMPRESSED_FLAG
enum Format : char {
ffUnknown = 0,
ffLegacy = 1, // legacy LZ4 frame
ffLz4 = 2, // actual LZ4 frame
ffActual = 2, // actual LZ4 frame
};

bool is_legacy_frame(DWORD magic);
bool check_frame_magic(DWORD magic);
__forceinline
bool is_legacy_frame(DWORD magic)
{
return (magic == LEGACY_MAGICNUMBER) ? true : false;
}

Format check_frame_magic(DWORD magic);
int check_file_header(HANDLE hFile, UINT64 file_size);
int check_file_header(LPCWSTR filename);

Expand Down
3 changes: 1 addition & 2 deletions src/lz4pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ int packer::frame_create(UINT64 data_size)
size_t bsz = LZ4F_compressFrameBound(m_block_size, &m_prefs);
if (bsz > m_buf.size()) {
size_t msz = bsz + 2048;
size_t sz = m_buf.reserve(msz + 2048);
FIN_IF(sz == bst::npos, -11);
FIN_IF(!m_buf.reserve(msz + 2048), -11);
m_buf.resize(msz);
}

Expand Down
7 changes: 4 additions & 3 deletions src/tar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,10 @@ int pax_encode::create_header(HANDLE hFile, fileinfo * fi, LPCWSTR fullFilename,
m_fullname.wstr[--ffn_len] = 0;
}
LPSTR utf8name = m_utf8name.str + 2;
int aLen = WideCharToMultiByte(CP_UTF8, 0, m_fullname.wstr, -1, utf8name, (int)m_utf8name.size - 8, NULL, NULL);
FIN_IF(aLen <= 1, 0x1502700);
size_t ufn_len = strlen(utf8name);
int aLen = WideCharToMultiByte(CP_UTF8, 0, m_fullname.wstr, (int)ffn_len, utf8name, (int)m_utf8name.size - 8, NULL, NULL);
FIN_IF(aLen <= 0, 0x1502700);
FIN_IF((size_t)aLen >= m_utf8name.size - 8, 0x1502800);
size_t ufn_len = aLen;
utf8name[ufn_len] = 0;

size_t k = INT_MAX;
Expand Down
3 changes: 1 addition & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ int get_full_filename(LPCWSTR path, LPCWSTR name, bst::wstr & fullname)
{
size_t fnlen = path ? wcslen(path) : 0;
fnlen += wcslen(name);
size_t cap = fullname.reserve(fnlen + 32);
if (cap == bst::npos)
if (!fullname.reserve(fnlen + 32))
return -10;
int hr = get_full_filename(path, name, fullname.data(), fnlen + 15);
if (hr) {
Expand Down
2 changes: 1 addition & 1 deletion src/wcx_arcfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int arcfile::update_type(HANDLE hFile)
FIN_IF(finfo.frameType != LZ4F_frame, 0);

m_type = atLz4;
m_lz4format = lz4::ffLz4;
m_lz4format = lz4::ffActual;

if (finfo.data_size) {
int sz = 0;
Expand Down
6 changes: 2 additions & 4 deletions src/wcx_archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,11 @@ int archive::extract(int Operation, LPCWSTR DestPath, LPCWSTR DestName)

const size_t buf_size = 4*1024*1024;
if (m_buf.capacity() < buf_size) {
size_t sz = m_buf.reserve(buf_size + 256);
FIN_IF(sz == bst::npos, 0x117000 | E_NO_MEMORY);
FIN_IF(!m_buf.reserve(buf_size + 256), 0x117000 | E_NO_MEMORY);
m_buf.resize(buf_size);
}
if (m_dst.capacity() < buf_size) {
size_t sz = m_dst.reserve(buf_size + 256);
FIN_IF(sz == bst::npos, 0x118000 | E_NO_MEMORY);
FIN_IF(!m_dst.reserve(buf_size + 256), 0x118000 | E_NO_MEMORY);
m_dst.resize(buf_size);
}

Expand Down
12 changes: 5 additions & 7 deletions src/wcx_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ int cache::add_pax_info(tar::pax_decode & pax, UINT64 file_pos, UINT64 frame_siz
break;
int x = MultiByteToWideChar(CP_UTF8, 0, name, (int)nlen, m_add_name.data(), (int)m_add_name.capacity() - 32);
FIN_IF(x <= 0, 0x45013400 | E_EOPEN);
m_add_name.data()[x] = 0;
m_add_name.fix_length();
LPWSTR ws = m_add_name.data();
do {
Expand Down Expand Up @@ -350,8 +351,7 @@ int cache::scan_pax_file(HANDLE hFile)
// TODO: support GNU tar!!!
FIN_IF(m_arcfile.get_tar_format() != tar::POSIX_FORMAT, 0x45010100 | E_EOPEN);

size_t sz = buf.reserve(buf_size + tar::BLOCKSIZE * 2);
FIN_IF(sz == bst::npos, 0x45010100 | E_EOPEN);
FIN_IF(!buf.reserve(buf_size + tar::BLOCKSIZE * 2), 0x45010100 | E_EOPEN);
buf.resize(buf_size);

pos.QuadPart = 0;
Expand Down Expand Up @@ -426,12 +426,10 @@ int cache::scan_paxlz4_file(HANDLE hFile)
bst::buf dst;
tar::pax_decode pax;

size_t sz = buf.reserve(buf_size + tar::BLOCKSIZE);
FIN_IF(sz == bst::npos, 0x44010100 | E_EOPEN);
FIN_IF(!buf.reserve(buf_size + tar::BLOCKSIZE), 0x44010100 | E_EOPEN);
buf.resize(buf_size);

sz = dst.reserve(buf_size + tar::BLOCKSIZE);
FIN_IF(sz == bst::npos, 0x44010200 | E_EOPEN);
FIN_IF(!dst.reserve(buf_size + tar::BLOCKSIZE), 0x44010200 | E_EOPEN);
dst.resize(buf_size);

pos.QuadPart = m_arcfile.get_data_begin();
Expand Down Expand Up @@ -486,7 +484,7 @@ int cache::scan_paxlz4_file(HANDLE hFile)
size_t plen = frame.data_size;
DWORD calc_hash = XXH32(pd, plen, 0);
DWORD read_hash = *(PDWORD)(pd + plen);
LOGi("pos = 0x%X hash = %08X cacl = %08X ", (DWORD)pos.QuadPart - 4, read_hash, calc_hash);
//LOGi("pos = 0x%X hash = %08X calc = %08X ", (DWORD)pos.QuadPart - 4, read_hash, calc_hash);
FIN_IF(read_hash != calc_hash, 0x44013700 | E_EOPEN);

if (frame.is_compressed) {
Expand Down
12 changes: 5 additions & 7 deletions src/wcx_packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ int packer::pack_files(LPCWSTR SubPath, LPCWSTR SrcPath, LPCWSTR AddList)
m_delete_out_file = true;

if (m_buf.empty()) {
size_t bufsize = 4*1024*1024;
sz = m_buf.reserve(bufsize + tar::BLOCKSIZE * 8);
FIN_IF(sz == bst::npos, 0x207000 | E_NO_MEMORY);
sz = m_buf.resize(bufsize);
const size_t bufsize = 4*1024*1024;
FIN_IF(!m_buf.reserve(bufsize + tar::BLOCKSIZE * 8), 0x207000 | E_NO_MEMORY);
m_buf.resize(bufsize);
FIN_IF(m_buf.size() & tar::BLOCKSIZE_MASK, 0x208000 | E_NO_MEMORY);
}
m_lz4.reset();
Expand All @@ -75,9 +74,8 @@ int packer::pack_files(LPCWSTR SubPath, LPCWSTR SrcPath, LPCWSTR AddList)
FIN_IF(!x || dw != frlen, 0x209300 | E_ECREATE);

if (m_ext_buf.empty()) {
size_t bufsize = 2*1024*1024;
sz = m_ext_buf.reserve(bufsize + 64);
FIN_IF(sz == bst::npos, 0x209900 | E_NO_MEMORY);
const size_t bufsize = 2*1024*1024;
FIN_IF(!m_ext_buf.reserve(bufsize + 64), 0x209900 | E_NO_MEMORY);
m_ext_buf.resize(bufsize);
}

Expand Down

0 comments on commit 255573f

Please sign in to comment.