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
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
......@@ -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;
......
......@@ -64,6 +64,7 @@
#define M_CONTINUE 1
#define M_EXIT 0
#define M_ERROR (-1)
#define MIN(a, b) (((a) < (b))? (a): (b))
......
......@@ -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;
......
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