aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/rangecoder
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2012-06-28 10:47:49 +0300
committerLasse Collin <lasse.collin@tukaani.org>2012-06-28 10:47:49 +0300
commit1403707fc64a70976aebe66f8d9a9bd12f73a2c5 (patch)
treec86756ed5ffbad7da56f39c793e3f19b728a5b77 /src/liblzma/rangecoder
parentUpdate NEWS from 5.0.4. (diff)
downloadxz-1403707fc64a70976aebe66f8d9a9bd12f73a2c5.tar.xz
liblzma: Check that the first byte of range encoded data is 0x00.
It is just to be more pedantic and thus perhaps catch broken files slightly earlier.
Diffstat (limited to 'src/liblzma/rangecoder')
-rw-r--r--src/liblzma/rangecoder/range_decoder.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/liblzma/rangecoder/range_decoder.h b/src/liblzma/rangecoder/range_decoder.h
index fb96180f..e0b051fa 100644
--- a/src/liblzma/rangecoder/range_decoder.h
+++ b/src/liblzma/rangecoder/range_decoder.h
@@ -25,20 +25,26 @@ typedef struct {
/// Reads the first five bytes to initialize the range decoder.
-static inline bool
+static inline lzma_ret
rc_read_init(lzma_range_decoder *rc, const uint8_t *restrict in,
size_t *restrict in_pos, size_t in_size)
{
while (rc->init_bytes_left > 0) {
if (*in_pos == in_size)
- return false;
+ return LZMA_OK;
+
+ // The first byte is always 0x00. It could have been omitted
+ // in LZMA2 but it wasn't, so one byte is wasted in every
+ // LZMA2 chunk.
+ if (rc->init_bytes_left == 5 && in[*in_pos] != 0x00)
+ return LZMA_DATA_ERROR;
rc->code = (rc->code << 8) | in[*in_pos];
++*in_pos;
--rc->init_bytes_left;
}
- return true;
+ return LZMA_STREAM_END;
}