vcl/source/filter/itiff/itiff.cxx |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

New commits:
commit 7351bf23f5f92b1e59436b3f7b99ed52ab03bf4e
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Sat Nov 5 21:52:29 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sun Nov 6 12:29:18 2022 +0100

    ofz#52685 Timeout
    
    only allow a short read after reading the preamble of the tiff
    
    Change-Id: Idd4b8892457566daa028c68125fe3beeb7499803
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142346
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/source/filter/itiff/itiff.cxx 
b/vcl/source/filter/itiff/itiff.cxx
index 510261e21b91..3e308f3019d3 100644
--- a/vcl/source/filter/itiff/itiff.cxx
+++ b/vcl/source/filter/itiff/itiff.cxx
@@ -39,11 +39,11 @@ namespace
     {
         SvStream& rStream;
         tsize_t nSize;
-        int nShortReads;
+        bool bAllowOneShortRead;
         Context(SvStream& rInStream, tsize_t nInSize)
             : rStream(rInStream)
             , nSize(nInSize)
-            , nShortReads(0)
+            , bAllowOneShortRead(false)
         {
         }
     };
@@ -55,10 +55,10 @@ static tsize_t tiff_read(thandle_t handle, tdata_t buf, 
tsize_t size)
     tsize_t nRead = pContext->rStream.ReadBytes(buf, size);
     // tdf#149417 allow one short read, which is similar to what
     // we do for jpeg since tdf#138950
-    if (nRead < size && !pContext->nShortReads)
+    if (nRead < size && pContext->bAllowOneShortRead)
     {
         memset(static_cast<char*>(buf) + nRead, 0, size - nRead);
-        ++pContext->nShortReads;
+        pContext->bAllowOneShortRead = false;
         return size;
     }
     return nRead;
@@ -190,6 +190,7 @@ bool ImportTiffGraphicImport(SvStream& rTIFF, Graphic& 
rGraphic)
             break;
 
         std::vector<uint32_t> raster(nPixelsRequired);
+        aContext.bAllowOneShortRead = true;
         if (TIFFReadRGBAImageOriented(tif, w, h, raster.data(), 
ORIENTATION_TOPLEFT, 1))
         {
             Bitmap bitmap(Size(w, h), vcl::PixelFormat::N24_BPP);

Reply via email to