From 635aa2a3fcfb4e9c6a9beba3fd5d818631c75c3f Mon Sep 17 00:00:00 2001
From: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
Date: Sun, 16 Oct 2022 12:36:00 +1300
Subject: [PATCH] Forcibly set the current seek location of gz files that we
 are accessing via dup(fileno());gzdopen() because stdio might have buffered
 data from the underlying file meaning that the underlying seek position isn't
 what we think it is.

---
 libs/fst/fstapi.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libs/fst/fstapi.cc b/libs/fst/fstapi.cc
index b79470db3..f1b726518 100644
--- a/libs/fst/fstapi.cc
+++ b/libs/fst/fstapi.cc
@@ -4272,6 +4272,7 @@ int fstReaderInit(struct fstReaderContext *xc)
 #endif
 
         zfd = dup(fileno(xc->f));
+	lseek(zfd, ftell(xc->f), SEEK_SET);
         zhandle = gzdopen(zfd, "rb");
         if (zhandle) {
             for (offpnt = 0; offpnt < uclen; offpnt += FST_GZIO_LEN) {