From 6ffa14f3b019919dd7c8d3a768606c05f87fe729 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Mon, 27 Apr 2009 11:26:09 +0300 Subject: Define VLI_BYTES_MAX macro and use it in dec_vli(). This makes it possible to use uint32_t as vli_type. Doing so risks having some integer overflows unless the caller can ensure that the total amounts of input and output will stay below 256 MiB. --- linux/lib/xz/xz_dec_stream.c | 5 ++--- linux/lib/xz/xz_stream.h | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/linux/lib/xz/xz_dec_stream.c b/linux/lib/xz/xz_dec_stream.c index 96e8736..af878c4 100644 --- a/linux/lib/xz/xz_dec_stream.c +++ b/linux/lib/xz/xz_dec_stream.c @@ -189,10 +189,9 @@ static enum xz_ret XZ_FUNC dec_vli(struct xz_dec *s, return XZ_STREAM_END; } - if (s->pos >= 56) - return XZ_DATA_ERROR; - s->pos += 7; + if (s->pos == 7 * VLI_BYTES_MAX) + return XZ_DATA_ERROR; } return XZ_OK; diff --git a/linux/lib/xz/xz_stream.h b/linux/lib/xz/xz_stream.h index de35e67..bb70b09 100644 --- a/linux/lib/xz/xz_stream.h +++ b/linux/lib/xz/xz_stream.h @@ -40,4 +40,7 @@ typedef uint64_t vli_type; #define VLI_MAX ((vli_type)-1 / 2) #define VLI_UNKNOWN ((vli_type)-1) +/* Maximum encoded size of a VLI */ +#define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7) + #endif -- cgit v1.2.3