Skip to content

Commit

Permalink
Fix critical bug on reserve memory
Browse files Browse the repository at this point in the history
remittor committed Nov 29, 2019
1 parent 0f3f13c commit e1f2fe2
Showing 5 changed files with 12 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/lz4pack.cpp
Original file line number Diff line number Diff line change
@@ -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);
}

3 changes: 1 addition & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
@@ -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) {
6 changes: 2 additions & 4 deletions src/wcx_archive.cpp
Original file line number Diff line number Diff line change
@@ -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);
}

9 changes: 3 additions & 6 deletions src/wcx_cache.cpp
Original file line number Diff line number Diff line change
@@ -350,8 +350,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;
@@ -426,12 +425,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();
12 changes: 5 additions & 7 deletions src/wcx_packer.cpp
Original file line number Diff line number Diff line change
@@ -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();
@@ -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);
}

0 comments on commit e1f2fe2

Please sign in to comment.