From 635aa2a3fcfb4e9c6a9beba3fd5d818631c75c3f Mon Sep 17 00:00:00 2001 From: Lloyd Parkes Date: Sun, 16 Oct 2022 12:36:00 +1300 Subject: [PATCH 1/2] 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) { From 7dcc9c664e5d4f5116f9872ea3fab4a84b61fa40 Mon Sep 17 00:00:00 2001 From: Lloyd Parkes Date: Sun, 16 Oct 2022 12:50:49 +1300 Subject: [PATCH 2/2] And another place we need to lseek() after dup(). --- libs/fst/fstapi.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/fst/fstapi.cc b/libs/fst/fstapi.cc index f1b726518..da0d959a0 100644 --- a/libs/fst/fstapi.cc +++ b/libs/fst/fstapi.cc @@ -3607,6 +3607,7 @@ static int fstReaderRecreateHierFile(struct fstReaderContext *xc) fflush(xc->f); #endif zfd = dup(fileno(xc->f)); + lseek(zfd, ftell(xc->f), SEEK_SET); zhandle = gzdopen(zfd, "rb"); if (!zhandle) { close(zfd);