summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-09-15 11:34:44 +0200
committerljfa-ag <ljfa-ag@web.de>2015-09-15 12:04:08 +0200
commita692b3be10084aec02a5b6483c878e1dc20081f2 (patch)
treeaae909881dde16ad11d14e2758dfe487f418c2f2
parent089a804a12c0592b0d2a396df1d35dad4fd134c0 (diff)
downloadProject-Tick-a692b3be10084aec02a5b6483c878e1dc20081f2.tar.gz
Project-Tick-a692b3be10084aec02a5b6483c878e1dc20081f2.zip
Check for errors in input stream
-rw-r--r--include/io/izlibstream.h1
-rw-r--r--src/io/izlibstream.cpp8
2 files changed, 8 insertions, 1 deletions
diff --git a/include/io/izlibstream.h b/include/io/izlibstream.h
index b88839ea99..2b67003232 100644
--- a/include/io/izlibstream.h
+++ b/include/io/izlibstream.h
@@ -48,6 +48,7 @@ private:
std::vector<char> in;
std::vector<char> out;
z_stream zstr;
+ bool stream_end;
int_type underflow() override;
};
diff --git a/src/io/izlibstream.cpp b/src/io/izlibstream.cpp
index f9d9463d95..db69e0e626 100644
--- a/src/io/izlibstream.cpp
+++ b/src/io/izlibstream.cpp
@@ -24,7 +24,7 @@ namespace zlib
{
inflate_streambuf::inflate_streambuf(std::istream& input, size_t bufsize, int window_bits):
- is(input), in(bufsize), out(bufsize)
+ is(input), in(bufsize), out(bufsize), stream_end(false)
{
zstr.zalloc = Z_NULL;
zstr.zfree = Z_NULL;
@@ -56,7 +56,12 @@ inflate_streambuf::int_type inflate_streambuf::underflow()
if(zstr.avail_in <= 0)
{
is.read(in.data(), in.size());
+ if(is.bad())
+ throw std::ios_base::failure("Input stream is bad");
size_t count = is.gcount();
+ if(count == 0 && !stream_end)
+ throw zlib_error("Unexpected end of stream", Z_DATA_ERROR);
+
zstr.next_in = reinterpret_cast<Bytef*>(in.data());
zstr.avail_in = count;
}
@@ -76,6 +81,7 @@ inflate_streambuf::int_type inflate_streambuf::underflow()
throw std::bad_alloc();
case Z_STREAM_END:
+ stream_end = true;
if(have == 0)
return traits_type::eof();
break;