summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathis Rosenhauer <rosenhauer@dkrz.de>2016-01-15 10:25:35 +0100
committerMathis Rosenhauer <rosenhauer@dkrz.de>2016-01-15 10:25:35 +0100
commit7bd95ff2d586a1f5fa251735537a69c0ce110538 (patch)
treeea0b409b7206037a8305504a774cefe30ef74063
parent3a6b42c10ef34a42ba354399b2193e1c248ef11c (diff)
downloadlibaec-7bd95ff2d586a1f5fa251735537a69c0ce110538.tar.gz
libaec-7bd95ff2d586a1f5fa251735537a69c0ce110538.tar.bz2
libaec-7bd95ff2d586a1f5fa251735537a69c0ce110538.zip
Fail with uneven output buffer only if it filled up.
-rw-r--r--src/decode.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/decode.c b/src/decode.c
index 66be682..b4b38e7 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -388,7 +388,7 @@ static inline void fs_drop(struct aec_stream *strm)
static inline uint32_t copysample(struct aec_stream *strm)
{
if (bits_ask(strm, strm->bits_per_sample) == 0
- || strm->avail_out == 0)
+ || strm->avail_out < strm->state->bytes_per_sample)
return 0;
put_sample(strm, bits_get(strm, strm->bits_per_sample));
@@ -423,7 +423,7 @@ static int m_split_output(struct aec_stream *strm)
int k = state->id - 1;
do {
- if (bits_ask(strm, k) == 0 || strm->avail_out == 0)
+ if (bits_ask(strm, k) == 0 || strm->avail_out < state->bytes_per_sample)
return M_EXIT;
if (k)
*state->rsip++ += bits_get(strm, k);
@@ -502,7 +502,7 @@ static int m_zero_output(struct aec_stream *strm)
struct internal_state *state = strm->state;
do {
- if (strm->avail_out == 0)
+ if (strm->avail_out < state->bytes_per_sample)
return M_EXIT;
put_sample(strm, 0);
} while(--state->i);
@@ -565,13 +565,13 @@ static int m_se_decode(struct aec_stream *strm)
d1 = m - state->se_table[2 * m + 1];
if ((state->i & 1) == 0) {
- if (strm->avail_out == 0)
+ if (strm->avail_out < state->bytes_per_sample)
return M_EXIT;
put_sample(strm, state->se_table[2 * m] - d1);
state->i++;
}
- if (strm->avail_out == 0)
+ if (strm->avail_out < state->bytes_per_sample)
return M_EXIT;
put_sample(strm, d1);
state->i++;
@@ -804,9 +804,6 @@ int aec_decode(struct aec_stream *strm, int flush)
struct internal_state *state = strm->state;
int status;
- if (strm->avail_out % strm->state->bytes_per_sample)
- return AEC_MEM_ERROR;
-
strm->total_in += strm->avail_in;
strm->total_out += strm->avail_out;
@@ -817,6 +814,10 @@ int aec_decode(struct aec_stream *strm, int flush)
if (status == M_ERROR)
return AEC_DATA_ERROR;
+ if (status == M_EXIT && strm->avail_out > 0 &&
+ strm->avail_out < state->bytes_per_sample)
+ return AEC_MEM_ERROR;
+
state->flush_output(strm);
strm->total_in -= strm->avail_in;