summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMathis Rosenhauer <rosenhauer@dkrz.de>2014-02-04 13:53:19 +0100
committerMathis Rosenhauer <rosenhauer@dkrz.de>2014-02-04 13:53:19 +0100
commit1be8ed91a4f17cb71c8ac14e3506936a3d30e0b8 (patch)
treec6381d49f671d24a7e4c9c0f1f015ff22aab276c /src
parent8553e038bb00b55021c68fb6b59c195d18086cba (diff)
downloadlibaec-1be8ed91a4f17cb71c8ac14e3506936a3d30e0b8.tar.gz
libaec-1be8ed91a4f17cb71c8ac14e3506936a3d30e0b8.tar.bz2
libaec-1be8ed91a4f17cb71c8ac14e3506936a3d30e0b8.zip
better error handling in case of corrupt data
Diffstat (limited to 'src')
-rw-r--r--src/decode.c13
-rw-r--r--src/decode.h1
-rw-r--r--src/libaec.h7
3 files changed, 17 insertions, 4 deletions
diff --git a/src/decode.c b/src/decode.c
index c916b41..c4464aa 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -478,7 +478,11 @@ static int m_zero_block(struct aec_stream *strm)
i = zero_blocks * strm->block_size;
zero_bytes = i * state->bytes_per_sample;
+
if (strm->avail_out >= zero_bytes) {
+ if (state->rsi_size - (state->rsip - state->rsi_buffer) < i)
+ return M_ERROR;
+
memset(state->rsip, 0, i * sizeof(uint32_t));
state->rsip += i;
strm->avail_out -= zero_bytes;
@@ -740,11 +744,18 @@ int aec_decode(struct aec_stream *strm, int flush)
*/
struct internal_state *state = strm->state;
+ int status;
strm->total_in += strm->avail_in;
strm->total_out += strm->avail_out;
- while (state->mode(strm) == M_CONTINUE);
+ do {
+ status = state->mode(strm);
+ } while (status == M_CONTINUE);
+
+ if (status == M_ERROR)
+ return AEC_DATA_ERROR;
+
state->flush_output(strm);
strm->total_in -= strm->avail_in;
diff --git a/src/decode.h b/src/decode.h
index db4a0a2..724e195 100644
--- a/src/decode.h
+++ b/src/decode.h
@@ -64,6 +64,7 @@
#define M_CONTINUE 1
#define M_EXIT 0
+#define M_ERROR (-1)
#define MIN(a, b) (((a) < (b))? (a): (b))
diff --git a/src/libaec.h b/src/libaec.h
index cab1795..84ad763 100644
--- a/src/libaec.h
+++ b/src/libaec.h
@@ -72,9 +72,10 @@ struct aec_stream {
* 1, ..., 32)
*/
int block_size; /* block size in samples */
- int rsi; /* Reference sample interval, the number
- * of _blocks_ between consecutive
- * reference samples (up to 4096).
+ int rsi; /* Reference sample interval, the
+ * number of Coded Data Sets between
+ * consecutive reference samples (up
+ * to 4096).
*/
int flags;