From 7cf73b7a1e4f127098cae5b8593cd1d0c675e4a4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 9 Mar 2018 15:15:27 +0100 Subject: zstd: Implement support for multi-frame files This implements support for multi frame files while keeping error checking for unexpected EOF working correctly. Files with multiple frames are generated by pzstd, for example. --- apt-pkg/contrib/fileutl.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 5acf40221..85d7b36c7 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1764,7 +1764,7 @@ class APT_HIDDEN ZstdFileFdPrivate : public FileFdPrivate virtual ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) APT_OVERRIDE { /* Keep reading as long as the compressor still wants to read */ - while (next_to_load) + while (true) { // Fill compressed buffer; if (zstd_buffer.empty()) @@ -1776,9 +1776,12 @@ class APT_HIDDEN ZstdFileFdPrivate : public FileFdPrivate return -1; zstd_buffer.bufferend += read; - /* Expected EOF */ if (read == 0) { + /* Expected EOF */ + if (next_to_load == 0) + return 0; + res = -1; return filefd->FileFdError("ZSTD: %s %s", filefd->FileName.c_str(), @@ -1798,11 +1801,16 @@ class APT_HIDDEN ZstdFileFdPrivate : public FileFdPrivate .pos = 0, }; - res = ZSTD_decompressStream(dctx, &out, &in); + next_to_load = res = ZSTD_decompressStream(dctx, &out, &in); + + if (res == 0) + { + res = ZSTD_initDStream(dctx); + } + if (ZSTD_isError(res)) return -1; - next_to_load = res; zstd_buffer.bufferstart += in.pos; if (out.pos != 0) -- cgit v1.2.3