Commit 1be8ed91 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

better error handling in case of corrupt data

parent 8553e038
...@@ -94,7 +94,7 @@ rsi sets the reference sample interval. A large RSI will improve ...@@ -94,7 +94,7 @@ rsi sets the reference sample interval. A large RSI will improve
performance and efficiency. It will also increase memory requirements performance and efficiency. It will also increase memory requirements
since internal buffering is based on RSI size. A smaller RSI may be since internal buffering is based on RSI size. A smaller RSI may be
desirable in situations where each RSI will be packetized and possible 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: Flags:
...@@ -208,6 +208,6 @@ http://public.ccsds.org/publications/archive/121x0b2.pdf ...@@ -208,6 +208,6 @@ http://public.ccsds.org/publications/archive/121x0b2.pdf
[2] Consultative Committee for Space Data Systems. Lossless Data [2] Consultative Committee for Space Data Systems. Lossless Data
Compression. Recommendation for Space Data System Standards, CCSDS Compression. Recommendation for Space Data System Standards, CCSDS
120.0-G-2. Green Book. Issue 2. Washington, D.C.: CCSDS, December 120.0-G-3. Green Book. Issue 3. Washington, D.C.: CCSDS, April
2006. 2013.
http://public.ccsds.org/publications/archive/120x0g2s.pdf http://public.ccsds.org/publications/archive/120x0g3.pdf
...@@ -478,7 +478,11 @@ static int m_zero_block(struct aec_stream *strm) ...@@ -478,7 +478,11 @@ static int m_zero_block(struct aec_stream *strm)
i = zero_blocks * strm->block_size; i = zero_blocks * strm->block_size;
zero_bytes = i * state->bytes_per_sample; zero_bytes = i * state->bytes_per_sample;
if (strm->avail_out >= zero_bytes) { 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)); memset(state->rsip, 0, i * sizeof(uint32_t));
state->rsip += i; state->rsip += i;
strm->avail_out -= zero_bytes; strm->avail_out -= zero_bytes;
...@@ -740,11 +744,18 @@ int aec_decode(struct aec_stream *strm, int flush) ...@@ -740,11 +744,18 @@ int aec_decode(struct aec_stream *strm, int flush)
*/ */
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
int status;
strm->total_in += strm->avail_in; strm->total_in += strm->avail_in;
strm->total_out += strm->avail_out; 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); state->flush_output(strm);
strm->total_in -= strm->avail_in; strm->total_in -= strm->avail_in;
......
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#define M_CONTINUE 1 #define M_CONTINUE 1
#define M_EXIT 0 #define M_EXIT 0
#define M_ERROR (-1)
#define MIN(a, b) (((a) < (b))? (a): (b)) #define MIN(a, b) (((a) < (b))? (a): (b))
......
...@@ -72,9 +72,10 @@ struct aec_stream { ...@@ -72,9 +72,10 @@ struct aec_stream {
* 1, ..., 32) * 1, ..., 32)
*/ */
int block_size; /* block size in samples */ int block_size; /* block size in samples */
int rsi; /* Reference sample interval, the number int rsi; /* Reference sample interval, the
* of _blocks_ between consecutive * number of Coded Data Sets between
* reference samples (up to 4096). * consecutive reference samples (up
* to 4096).
*/ */
int flags; int flags;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment