Author: Sergei Golovan
Description: Patch fixes computing size of the TIFF image by
 eliminating side effects of moving the file cursor while seeking.
Last-Modified: Tue, 02 Jul 2024 13:54:24 +0300

--- a/tiff/tiff.c
+++ b/tiff/tiff.c
@@ -270,7 +270,12 @@
 {
     int fsize;
 
+    /* Save the current seek position */
+    toff_t curpos = Tcl_Seek(((tkimg_Stream *) fd)->channel, (int) 0, SEEK_CUR);
+    /* Calculate the file size by seeking from its start to the end */
     fsize = Tcl_Seek(((tkimg_Stream *) fd)->channel, (int) 0, SEEK_END);
+    /* Restore the current seek position to avoid side effects */
+    Tcl_Seek(((tkimg_Stream *) fd)->channel, curpos, SEEK_SET);
     return fsize < 0 ? 0 : (toff_t) fsize;
 }
 
