RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 16-Jul-2017 15:46:46 Branch: rpm-5_4 Handle: 2017071613464600 Modified files: (Branch: rpm-5_4) rpm CHANGES rpm/rpmio rpmzstd.h tzstd.c zstdio.c Log: - zstd: fix: handle read/decompress EOF correctly. Summary: Revision Changes Path 1.3501.2.585+1 -0 rpm/CHANGES 1.1.2.4 +4 -2 rpm/rpmio/rpmzstd.h 1.1.2.8 +50 -56 rpm/rpmio/tzstd.c 1.1.2.6 +10 -9 rpm/rpmio/zstdio.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.3501.2.584 -r1.3501.2.585 CHANGES --- rpm/CHANGES 16 Jul 2017 04:20:02 -0000 1.3501.2.584 +++ rpm/CHANGES 16 Jul 2017 13:46:46 -0000 1.3501.2.585 @@ -1,4 +1,5 @@ 5.4.17 -> 5.4.18: + - jbj: zstd: fix: handle read/decompress EOF correctly. - jbj: bdb: upgrade to db-6.2.32. - jbj: i18n: update PO files (Translation Project). - jbj: rpmjs: upgrade js-1.8.5 with mozjs-45 (internal). @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmzstd.h ============================================================================ $ cvs diff -u -r1.1.2.3 -r1.1.2.4 rpmzstd.h --- rpm/rpmio/rpmzstd.h 4 Jul 2017 03:14:56 -0000 1.1.2.3 +++ rpm/rpmio/rpmzstd.h 16 Jul 2017 13:46:46 -0000 1.1.2.4 @@ -47,10 +47,12 @@ size_t nb; void * b; +#if defined(WITH_ZSTD) size_t nib; - void * zib; /*!< ZSTD_inBuffer */ + ZSTD_inBuffer zib; /*!< ZSTD_inBuffer */ size_t nob; - void * zob; /*!< ZSTD_outBuffer */ + ZSTD_outBuffer zob; /*!< ZSTD_outBuffer */ +#endif }; #ifdef NOTYET @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/tzstd.c ============================================================================ $ cvs diff -u -r1.1.2.7 -r1.1.2.8 tzstd.c --- rpm/rpmio/tzstd.c 10 Jun 2017 00:22:36 -0000 1.1.2.7 +++ rpm/rpmio/tzstd.c 16 Jul 2017 13:46:46 -0000 1.1.2.8 @@ -106,52 +106,58 @@ return rc; } -static int readFile(const char *ifn, const char *fmode) +/*==============================================================*/ +static int copyZFile(FD_t ifd, FD_t ofd) { - char b[16*BUFSIZ]; + char b[BUFSIZ]; size_t nb = sizeof(b); + size_t pos = 0; int rc = -2; - FD_t ifd = Fopen(ifn, fmode); - if (ifd) { - size_t pos = 0; - size_t nr; - char xxxbuf[16*BUFSIZ]; - setvbuf(fdGetFp(ifd), xxxbuf,_IOFBF, sizeof(xxxbuf)); - do { - nr = Fread(b, 1, nb, ifd); - if (nr > 0) - pos += nr; -rpmzstd zstd = NULL; -SPEW("*** %s: pos %12zd nr %zd\n", __FUNCTION__, pos, nr); - } while (nr > 0); - rc = Fclose(ifd); + if (ifd && ofd) + while (1) { + size_t nr = Fread(b, 1, nb, ifd); +fprintf(stderr, "================= nr %zu\n", nr); + if (Ferror(ifd) || nr == 0) { + rc = 0; + break; + } + pos += nr; + size_t nw = Fwrite(b, 1, nr, ofd); +fprintf(stderr, "================= nw %zu\n", nw); + if (nr != nw) { + rc = -2; + break; + } + (void) Fflush(ofd); } + return rc; } -static int writeFile(const char *ofn, const char *fmode) +static int readZFile(const char *ifn, const char *ofn) { - char b[BUFSIZ]; - size_t nb = sizeof(b); - int rc = -2; - - strncpy(b, "abcdefghijklmnopqrstuvwxyz\n", nb); - size_t blen = strlen(b); + FD_t ifd = Fopen(ifn, "r?.zstdio"); + FD_t ofd = Fopen(ofn, "wb"); + int rc = copyZFile(ifd, ofd); + + if (ofd) + (void) Fclose(ofd); + if (ifd) + (void) Fclose(ifd); + return rc; +} - FD_t ofd = Fopen(ofn, fmode); - if (ofd) { - size_t nw; - nw = Fwrite(b, 1, blen, ofd); -assert(nw == blen); - (void) Fflush(ofd); - (void) zstdio->_flush(ofd); - nw = Fwrite(b, 1, blen, ofd); -assert(nw == blen); - (void) Fflush(ofd); - (void) zstdio->_flush(ofd); - rc = Fclose(ofd); - } +static int writeZFile(const char *ifn, const char *ofn) +{ + FD_t ifd = Fopen(ifn, "rb"); + FD_t ofd = Fopen(ofn, "w3b?.zstdio"); + int rc = copyZFile(ifd, ofd); + + if (ofd) + (void) Fclose(ofd); + if (ifd) + (void) Fclose(ifd); return rc; } @@ -195,30 +201,18 @@ printf("%s FILE\n", argv[0]); return 1; } - const char * ifn = rpmGetPath(av[0], NULL); - const char * ofn = rpmGetPath(av[0], ".zst", NULL); - - _rpmzstdOFlags = rpmioOpenFlags; -char * ostr = NULL; -#define OFLAGS(_bits) rpmioB2N(rpmioOpenFlagsTable, _bits) -rpmzstd zstd = NULL; -SPEW("*** O_TMPFILE: %#o: %s\n", O_TMPFILE, (ostr=OFLAGS(O_TMPFILE))); -ostr = _free(ostr); -SPEW("*** OMask: %#o: %s\n", _rpmioOMask, (ostr=OFLAGS(_rpmioOMask))); -ostr = _free(ostr); -SPEW("*** OFlags: %#o: %s\n", _rpmzstdOFlags, (ostr=OFLAGS(_rpmzstdOFlags))); -ostr = _free(ostr); -#undef OFLAGS + const char * fn = rpmGetPath(av[0], NULL); + const char * zfn = rpmGetPath(av[0], ".zst", NULL); switch (climode) { - case 1: ec = compressFile(ifn, "w3?.zstdio"); break; - case 2: ec = decompressFile(ifn, "r?.zstdio"); break; - case 'R': ec = readFile(ofn, "rmb.zstdio"); break; - case 'W': ec = writeFile(ofn, "w3b.zstdio"); break; + case 1: ec = compressFile(zfn, "w3?.zstdio"); break; + case 2: ec = decompressFile(zfn, "r?.zstdio"); break; + case 'R': ec = readZFile(zfn, "-"); break; + case 'W': ec = writeZFile("-", zfn); break; } - ifn = _free(ifn); - ofn = _free(ofn); + fn = _free(fn); + zfn = _free(zfn); con = rpmioFini(con); @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/zstdio.c ============================================================================ $ cvs diff -u -r1.1.2.5 -r1.1.2.6 zstdio.c --- rpm/rpmio/zstdio.c 4 Jul 2017 03:14:56 -0000 1.1.2.5 +++ rpm/rpmio/zstdio.c 16 Jul 2017 13:46:46 -0000 1.1.2.6 @@ -14,6 +14,10 @@ typedef enum { true = 1, false = 0 } bool; #endif +#if defined(WITH_ZSTD) +#include <zstd.h> +#endif + #include "rpmio_internal.h" #include <rpmmacro.h> #include <rpmcb.h> @@ -29,16 +33,15 @@ #include "debug.h" -int _rpmzstd_debug = 0; +int _rpmzstd_debug; +#define SPEW(_fmt, ...) \ + if ((zstd && ZSTDF_ISSET(DEBUGIO)) || _rpmzstd_debug || _rpmio_debug) \ + fprintf(stderr, _fmt, __VA_ARGS__) int _rpmzstdOFlags; #define ZSTDF_ISSET(_foo) (zstd->flags & RPMZSTD_FLAGS_##_foo) -#define SPEW(_fmt, ...) \ - if ((zstd && ZSTDF_ISSET(DEBUGIO)) || _rpmzstd_debug || _rpmio_debug) \ - fprintf(stderr, _fmt, __VA_ARGS__) - #define ZSTDONLY(fd) assert(fdGetIo(fd) == zstdio) /* =============================================================== */ @@ -470,10 +473,8 @@ if (zstd->zib.pos >= zstd->zib.size) { nr = fread(zstd->b, 1, zstd->nb, zstd->fp); SPEW("<--\t fread(%p, 1, %zu, %p) nr %zd\n", zstd->b, zstd->nb, zstd->fp, nr); - if (nr <= 0) { - rc = nr; - goto exit; - } + if (nr == 0) + break; ipos += nr; /* Reset to beginning of compressed data buffer. */ @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org