aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Seither <[email protected]>2015-08-28 16:23:03 +0200
committerDaniel Seither <[email protected]>2015-08-28 16:23:03 +0200
commit294b66f579b6892fc60a88c27790c9da9da8c590 (patch)
treeabff6e0c8df323ddc9e324c4e2e9ed891f174c23 /src
parent47d9e96f1c6e10cef9b8d1803b6350bcf8696b49 (diff)
Compression: Prevent undefined behavior when feeding empty input
&emptyVector[n] triggers undefined behavior because it is an out-of- bounds access, even if n == 0. emptyVector.data() does not (but may return nullptr).
Diffstat (limited to 'src')
-rw-r--r--src/lib/compression/compression.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/compression/compression.cpp b/src/lib/compression/compression.cpp
index 6057f9408..22ee700b6 100644
--- a/src/lib/compression/compression.cpp
+++ b/src/lib/compression/compression.cpp
@@ -104,8 +104,8 @@ void Stream_Compression::process(secure_vector<byte>& buf, size_t offset, u32bit
if(m_buffer.size() < buf.size() + offset)
m_buffer.resize(buf.size() + offset);
- m_stream->next_in(&buf[offset], buf.size() - offset);
- m_stream->next_out(&m_buffer[offset], m_buffer.size() - offset);
+ m_stream->next_in(buf.data() + offset, buf.size() - offset);
+ m_stream->next_out(m_buffer.data() + offset, m_buffer.size() - offset);
while(true)
{
@@ -115,7 +115,7 @@ void Stream_Compression::process(secure_vector<byte>& buf, size_t offset, u32bit
{
const size_t added = 8 + m_buffer.size();
m_buffer.resize(m_buffer.size() + added);
- m_stream->next_out(&m_buffer[m_buffer.size() - added], added);
+ m_stream->next_out(m_buffer.data() + m_buffer.size() - added, added);
}
else if(m_stream->avail_in() == 0)
{
@@ -170,8 +170,8 @@ void Stream_Decompression::process(secure_vector<byte>& buf, size_t offset, u32b
if(m_buffer.size() < buf.size() + offset)
m_buffer.resize(buf.size() + offset);
- m_stream->next_in(&buf[offset], buf.size() - offset);
- m_stream->next_out(&m_buffer[offset], m_buffer.size() - offset);
+ m_stream->next_in(buf.data() + offset, buf.size() - offset);
+ m_stream->next_out(m_buffer.data() + offset, m_buffer.size() - offset);
while(true)
{
@@ -189,14 +189,14 @@ void Stream_Decompression::process(secure_vector<byte>& buf, size_t offset, u32b
// More data follows: try to process as a following stream
const size_t read = (buf.size() - offset) - m_stream->avail_in();
start();
- m_stream->next_in(&buf[offset + read], buf.size() - offset - read);
+ m_stream->next_in(buf.data() + offset + read, buf.size() - offset - read);
}
if(m_stream->avail_out() == 0)
{
const size_t added = 8 + m_buffer.size();
m_buffer.resize(m_buffer.size() + added);
- m_stream->next_out(&m_buffer[m_buffer.size() - added], added);
+ m_stream->next_out(m_buffer.data() + m_buffer.size() - added, added);
}
else if(m_stream->avail_in() == 0)
{