From: Robert Pengelly Date: Sun, 1 Mar 2026 19:13:38 +0000 (+0000) Subject: Bug fixes X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;ds=sidebyside;p=unxz.git Bug fixes --- diff --git a/Makefile.wat b/Makefile.wat new file mode 100644 index 0000000..7ab6968 --- /dev/null +++ b/Makefile.wat @@ -0,0 +1,25 @@ +#****************************************************************************** +# @file Makefile.wat +#****************************************************************************** +SRCDIR ?= $(CURDIR) +VPATH := $(SRCDIR) + +CSRC := libxz/xz_crc32.c libxz/xz_crc64.c libxz/xz_dec_lzma2.c libxz/xz_dec_stream.c lib.c report.c unxz.c +COBJ := $(subst /,\,$(CSRC:.c=.obj)) + +INCDIR := $(subst /,\,$(SRCDIR)) + +all: unxz.exe + +unxz.exe: $(COBJ) + + wcl -fe=$@ $^ + +%.obj: %.c + + wcc -I$(INCDIR)\\include -fo=$@ $^ + +clean: + + for /r %%f in (*.obj) do ( if exist %%f ( del /q %%f ) ) + if exist unxz.exe ( del /q unxz.exe ) diff --git a/include/xz_lzma2.h b/include/xz_lzma2.h index 2a8abf4..d077742 100755 --- a/include/xz_lzma2.h +++ b/include/xz_lzma2.h @@ -10,8 +10,8 @@ #define RC_SHIFT_BITS 8 #define RC_MOVE_BITS 5 -#define RC_TOP_VALUE (1 << RC_TOP_BITS) -#define RC_BIT_MODEL_TOTAL (1 << RC_BIT_MODEL_TOTAL_BITS) +#define RC_BIT_MODEL_TOTAL (1LU << RC_BIT_MODEL_TOTAL_BITS) +#define RC_TOP_VALUE (1LU << RC_TOP_BITS) /* * Maximum number of position states. A position state is the lowest pb @@ -199,4 +199,4 @@ enum lzma_state { */ #define REPS 4 -#endif /* _XZ_LZMA2_H */ \ No newline at end of file +#endif /* _XZ_LZMA2_H */ diff --git a/libxz/xz_dec_lzma2.c b/libxz/xz_dec_lzma2.c index a4dd2e7..a43ac95 100755 --- a/libxz/xz_dec_lzma2.c +++ b/libxz/xz_dec_lzma2.c @@ -677,7 +677,7 @@ static void rc_direct (struct rc_dec *rc, uint32_t *dest, uint32_t limit) { /* Get pointer to literal coder probability array. */ static uint16_t *lzma_literal_probs (struct xz_dec_lzma2 *s) { - uint32_t prev_byte = dict_get(&s->dict, 0); + uint32_t prev_byte = dict_get (&s->dict, 0); uint32_t low = prev_byte >> (8 - s->lzma.lc); uint32_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc; @@ -1063,10 +1063,8 @@ static int lzma2_lzma (struct xz_dec_lzma2 *s, struct xz_buf *b) { if (s->rc.in_pos < s->temp.size) { s->temp.size -= s->rc.in_pos; - - memmove (s->temp.buf, s->temp.buf + s->rc.in_pos, - s->temp.size); - + + memmove (s->temp.buf, s->temp.buf + s->rc.in_pos, s->temp.size); return 1; } @@ -1113,8 +1111,8 @@ static int lzma2_lzma (struct xz_dec_lzma2 *s, struct xz_buf *b) { } memcpy (s->temp.buf, b->in + b->in_pos, in_avail); - s->temp.size = in_avail; + s->temp.size = in_avail; b->in_pos += in_avail; } @@ -1335,7 +1333,7 @@ struct xz_dec_lzma2 *xz_dec_lzma2_create (enum xz_mode mode, uint32_t dict_max) } memzero (s, sizeof (*s)); - + s->dict.mode = mode; s->dict.size_max = dict_max; @@ -1348,7 +1346,7 @@ struct xz_dec_lzma2 *xz_dec_lzma2_create (enum xz_mode mode, uint32_t dict_max) } - memzero (s->dict.buf, sizeof (dict_max)); + memzero (s->dict.buf, dict_max); } else if (DEC_IS_DYNALLOC (mode)) { @@ -1363,8 +1361,11 @@ struct xz_dec_lzma2 *xz_dec_lzma2_create (enum xz_mode mode, uint32_t dict_max) enum xz_ret xz_dec_lzma2_reset (struct xz_dec_lzma2 *s, uint8_t props) { - /* This limits dictionary size to 3 GiB to keep parsing simpler. */ +#if defined (__WATCOMC__) + if (props > 18) { +#else if (props > 39) { +#endif return XZ_OPTIONS_ERROR; } @@ -1392,7 +1393,7 @@ enum xz_ret xz_dec_lzma2_reset (struct xz_dec_lzma2 *s, uint8_t props) { } - memzero (s->dict.buf, sizeof (s->dict.size)); + memzero (s->dict.buf, s->dict.size); } @@ -1415,7 +1416,7 @@ void xz_dec_lzma2_end (struct xz_dec_lzma2 *s) { if (DEC_IS_MULTI (s->dict.mode)) { free (s->dict.buf); } - + free (s); } diff --git a/libxz/xz_dec_stream.c b/libxz/xz_dec_stream.c index 5dd264f..a51e4e9 100755 --- a/libxz/xz_dec_stream.c +++ b/libxz/xz_dec_stream.c @@ -547,7 +547,7 @@ static enum xz_ret dec_block_header (struct xz_dec *s) /* Uncompressed Size */ if (s->temp.buf[1] & 0x80) { - if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size) != XZ_STREAM_END) { + if (dec_vli (s, s->temp.buf, &s->temp.pos, s->temp.size) != XZ_STREAM_END) { return XZ_DATA_ERROR; } @@ -557,26 +557,6 @@ static enum xz_ret dec_block_header (struct xz_dec *s) s->block_header.uncompressed = (uint64_t) -1; } -#ifdef XZ_DEC_BCJ - /* If there are two filters, the first one must be a BCJ filter. */ - s->bcj_active = s->temp.buf[1] & 0x01; - if (s->bcj_active) { - if (s->temp.size - s->temp.pos < 2) - return XZ_OPTIONS_ERROR; - - ret = xz_dec_bcj_reset(s->bcj, s->temp.buf[s->temp.pos++]); - if (ret != XZ_OK) - return ret; - - /* - * We don't support custom start offset, - * so Size of Properties must be zero. - */ - if (s->temp.buf[s->temp.pos++] != 0x00) - return XZ_OPTIONS_ERROR; - } -#endif - /* Valid Filter Flags always take at least two bytes. */ if (s->temp.size - s->temp.pos < 2) { return XZ_DATA_ERROR; @@ -927,12 +907,6 @@ struct xz_dec *xz_dec_init (enum xz_mode mode, uint32_t dict_max) { memzero (s, sizeof (*s)); s->mode = mode; -#ifdef XZ_DEC_BCJ - s->bcj = xz_dec_bcj_create(DEC_IS_SINGLE(mode)); - if (s->bcj == NULL) - goto error_bcj; -#endif - if (!(s->lzma2 = xz_dec_lzma2_create (mode, dict_max))) { goto error_lzma2; }