diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-03-04 20:58:26 +0000 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2017-03-06 16:08:05 +0100 |
commit | 1e81d4cc5dfdcb45c3e07e82ed5080d122d27d3d (patch) | |
tree | 1d087cb15990b8664d1c944ef17b2e0fba3e220f | |
parent | 5d4ed24dfa40a7a11d92796430927035a13bad12 (diff) |
Resolves: ofz#727 don't allow negative sizes or indexes
remove extra size in favour of vector size and don't resize
and memcpy data, just use vector::insert
Change-Id: I8efb91a8c11fbd862c0458042554cf7e94b813cd
Reviewed-on: https://gerrit.libreoffice.org/34892
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
(cherry picked from commit ecad9326a0e40a4bfe1e3c8232ee1a1f5cb84a65)
-rw-r--r-- | hwpfilter/source/hstream.cxx | 21 | ||||
-rw-r--r-- | hwpfilter/source/hstream.hxx | 11 |
2 files changed, 15 insertions, 17 deletions
diff --git a/hwpfilter/source/hstream.cxx b/hwpfilter/source/hstream.cxx index 6a0d59f48048..6b5bf98cb35d 100644 --- a/hwpfilter/source/hstream.cxx +++ b/hwpfilter/source/hstream.cxx @@ -22,38 +22,37 @@ #include "hstream.hxx" HStream::HStream() - : size(0) - , pos(0) + : pos(0) { } -void HStream::addData(const byte *buf, int aToAdd) +void HStream::addData(const byte *buf, size_t aToAdd) { - seq.resize(size + aToAdd); - memcpy(seq.data() + size, buf, aToAdd); - size += aToAdd; + seq.insert(seq.end(), buf, buf + aToAdd); } -int HStream::readBytes(byte * buf, int aToRead) +size_t HStream::readBytes(byte * buf, size_t aToRead) { + auto size = seq.size(); if (aToRead >= (size - pos)) aToRead = size - pos; - for (int i = 0; i < aToRead; i++) + for (size_t i = 0; i < aToRead; ++i) buf[i] = seq[pos++]; return aToRead; } -int HStream::skipBytes(int aToSkip) +size_t HStream::skipBytes(size_t aToSkip) { + auto size = seq.size(); if (aToSkip >= (size - pos)) aToSkip = size - pos; pos += aToSkip; return aToSkip; } -int HStream::available() const +size_t HStream::available() const { - return size - pos; + return seq.size() - pos; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/hstream.hxx b/hwpfilter/source/hstream.hxx index 4374b92674e3..e6654f707dde 100644 --- a/hwpfilter/source/hstream.hxx +++ b/hwpfilter/source/hstream.hxx @@ -34,24 +34,23 @@ class HStream /** * */ - void addData( const byte *buf, int aToAdd); + void addData( const byte *buf, size_t aToAdd); /** * Read some byte to buf as given size */ - int readBytes( byte *buf, int aToRead); + size_t readBytes( byte *buf, size_t aToRead); /** * Skip some byte from stream as given size */ - int skipBytes( int aToSkip ); + size_t skipBytes( size_t aToSkip ); /** * @returns Size of remained stream */ - int available() const; + size_t available() const; private: - int size; std::vector<byte> seq; - int pos; + size_t pos; }; #endif |