]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
seekable_format: Prevent rereading frame when seeking forward
authorYoni Gilad <yonig@radcom.com>
Thu, 17 Feb 2022 17:46:29 +0000 (19:46 +0200)
committerYann Collet <cyan@fb.com>
Thu, 30 Mar 2023 04:24:12 +0000 (21:24 -0700)
When decompressing a seekable file, if seeking forward within
a frame (by issuing multiple ZSTD_seekable_decompress calls
with a small gap between them), the frame will be unnecessarily
reread from the beginning. This patch makes it continue using
the current frame data and simply skip over the unneeded bytes.

contrib/seekable_format/zstdseek_decompress.c

index fbb2d4fe3be3b3c3ed0057ff5b74a314398baec9..4fefc5f2eb6772b59d657f242b5ad6e8d496973a 100644 (file)
@@ -493,7 +493,7 @@ size_t ZSTD_seekable_decompress(ZSTD_seekable* zs, void* dst, size_t len, unsign
     size_t srcBytesRead = 0;
     do {
         /* check if we can continue from a previous decompress job */
-        if (targetFrame != zs->curFrame || offset != zs->decompressedOffset) {
+        if (targetFrame != zs->curFrame || offset < zs->decompressedOffset) {
             zs->decompressedOffset = zs->seekTable.entries[targetFrame].dOffset;
             zs->curFrame = targetFrame;