From 849e1c2833b96321120e8c6ed774cbec7fb7d784 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 22 Jun 2025 20:14:29 -0500 Subject: [PATCH] Several minor fixes from upstream public domain repo, adapted from xz-embedded commits 40d291b609d0 f6d1f58f36cd 82078b610912 cfc1499e9fc2 Thanks to Oliver Webb for the triage. --- toys/pending/xzcat.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/toys/pending/xzcat.c b/toys/pending/xzcat.c index ec0e2c3d..f3417bd7 100644 --- a/toys/pending/xzcat.c +++ b/toys/pending/xzcat.c @@ -1,12 +1,13 @@ /* xzcat.c - Simple XZ decoder command line tool * - * Author: Lasse Collin + * Author: Lasse Collin * * This file has been put into the public domain. * You can do whatever you want with this file. * Modified for toybox by Isaac Dunham * * See http://tukaani.org/xz/xz-file-format.txt + * USE_XZCAT(NEWTOY(xzcat, NULL, TOYFLAG_USR|TOYFLAG_BIN)) config XZCAT @@ -16,8 +17,8 @@ config XZCAT usage: xzcat [FILE...] Decompress listed files to stdout. Use stdin if no files listed. - */ + #define FOR_xzcat #include "toys.h" @@ -1186,7 +1187,8 @@ static void dict_uncompressed(struct dictionary *dict, struct xz_buf *b, *left -= copy_size; - memcpy(dict->buf + dict->pos, b->in + b->in_pos, copy_size); + // With valid inputs memcpy() would be fine here. + memmove(dict->buf + dict->pos, b->in + b->in_pos, copy_size); dict->pos += copy_size; if (dict->full < dict->pos) @@ -1911,6 +1913,7 @@ enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, char props) s->dict.end = s->dict.size; if (s->dict.allocated < s->dict.size) { + s->dict.allocated = s->dict.size; free(s->dict.buf); s->dict.buf = malloc(s->dict.size); if (s->dict.buf == NULL) { @@ -2842,6 +2845,10 @@ void do_xzcat(int fd, char *name) for (;;) { if (b.in_pos == b.in_size) { b.in_size = read(fd, in, sizeof(in)); + if (ferror(stdin)) { + msg = "Read error\n"; + goto error; + } b.in_pos = 0; } -- 2.39.5