diff options
author | Mathis Rosenhauer <rosenhauer@dkrz.de> | 2014-02-04 13:53:19 +0100 |
---|---|---|
committer | Mathis Rosenhauer <rosenhauer@dkrz.de> | 2014-02-04 13:53:19 +0100 |
commit | 1be8ed91a4f17cb71c8ac14e3506936a3d30e0b8 (patch) | |
tree | c6381d49f671d24a7e4c9c0f1f015ff22aab276c | |
parent | 8553e038bb00b55021c68fb6b59c195d18086cba (diff) | |
download | libaec-1be8ed91a4f17cb71c8ac14e3506936a3d30e0b8.tar.gz libaec-1be8ed91a4f17cb71c8ac14e3506936a3d30e0b8.tar.bz2 libaec-1be8ed91a4f17cb71c8ac14e3506936a3d30e0b8.zip |
better error handling in case of corrupt data
-rw-r--r-- | README | 8 | ||||
-rw-r--r-- | src/decode.c | 13 | ||||
-rw-r--r-- | src/decode.h | 1 | ||||
-rw-r--r-- | src/libaec.h | 7 |
4 files changed, 21 insertions, 8 deletions
@@ -94,7 +94,7 @@ rsi sets the reference sample interval. A large RSI will improve performance and efficiency. It will also increase memory requirements since internal buffering is based on RSI size. A smaller RSI may be desirable in situations where each RSI will be packetized and possible -error propagation has to be minimized (e.g. on board a spacecraft[2]). +error propagation has to be minimized. Flags: @@ -208,6 +208,6 @@ http://public.ccsds.org/publications/archive/121x0b2.pdf [2] Consultative Committee for Space Data Systems. Lossless Data Compression. Recommendation for Space Data System Standards, CCSDS -120.0-G-2. Green Book. Issue 2. Washington, D.C.: CCSDS, December -2006. -http://public.ccsds.org/publications/archive/120x0g2s.pdf +120.0-G-3. Green Book. Issue 3. Washington, D.C.: CCSDS, April +2013. +http://public.ccsds.org/publications/archive/120x0g3.pdf 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; |