libtiff: Merge branch 'TIFFReadFromUserBuffer_fix' into 'master'

From c1dfe33a8c93aacfba728e970e60dc5638db096f Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Thu, 21 Jul 2022 11:25:57 +0200
Subject: [PATCH] TIFFReadFromUserBuffer(): fix clearing of TIFF_CODERSETUP
 flag that could cause issues with reading JPEG compressed files

---
 libtiff/tif_read.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libtiff/tif_read.c b/libtiff/tif_read.c
index 66f2e402..cb237f6b 100644
--- a/libtiff/tif_read.c
+++ b/libtiff/tif_read.c
@@ -1493,7 +1493,8 @@ int      TIFFReadFromUserBuffer(TIFF* tif, uint32_t strile,
         TIFFReverseBits(inbuf, insize);
     }
 
-    tif->tif_flags = old_tif_flags;
+    tif->tif_flags = (old_tif_flags & (TIFF_MYBUFFER | TIFF_BUFFERMMAP)) |
+                     (tif->tif_flags & ~(TIFF_MYBUFFER | TIFF_BUFFERMMAP));
     tif->tif_rawdatasize = old_rawdatasize;
     tif->tif_rawdata = old_rawdata;
     tif->tif_rawdataoff = 0;