sdext/source/pdfimport/pdfparse/pdfparse.cxx |   95 +++------------------------
 1 file changed, 12 insertions(+), 83 deletions(-)

New commits:
commit 1f6eb154d859f28f9523961e7b3901603d69d445
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Oct 31 20:43:52 2023 +0300
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Nov 2 00:53:37 2023 +0100

    tdf#106057: Don't fail PDFReader::read, when several entries in stack
    
    It may happen in case of several trailers, which is OK. The calling code
    will check the type of the returned object anyway.
    
    Change-Id: I17b2f4b7cf0e0640f949565291ee5a905ef2411e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158737
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158698

diff --git a/sdext/source/pdfimport/pdfparse/pdfparse.cxx 
b/sdext/source/pdfimport/pdfparse/pdfparse.cxx
index baa322c1aa3c..cdd3ac13ff35 100644
--- a/sdext/source/pdfimport/pdfparse/pdfparse.cxx
+++ b/sdext/source/pdfimport/pdfparse/pdfparse.cxx
@@ -601,21 +601,26 @@ std::unique_ptr<PDFEntry> PDFReader::read( const char* 
pFileName )
         pRet.reset(aGrammar.m_aObjectStack.back());
         aGrammar.m_aObjectStack.pop_back();
     }
-#if OSL_DEBUG_LEVEL > 0
     else if( nEntries > 1 )
     {
+        // It is possible that there are multiple trailers, which is OK.
+        // But still keep the warnings, just in case.
         SAL_WARN("sdext.pdfimport.pdfparse", "error got " << nEntries << " 
stack objects in parse");
-        for( unsigned int i = 0; i < nEntries; i++ )
+        for (;;)
         {
-            SAL_WARN("sdext.pdfimport.pdfparse", 
typeid(*aGrammar.m_aObjectStack[i]).name());
-            PDFObject* pObj = 
dynamic_cast<PDFObject*>(aGrammar.m_aObjectStack[i]);
+            PDFEntry* pEntry = aGrammar.m_aObjectStack.back();
+            aGrammar.m_aObjectStack.pop_back();
+            SAL_WARN("sdext.pdfimport.pdfparse", typeid(*pEntry).name());
+            PDFObject* pObj = dynamic_cast<PDFObject*>(pEntry);
             if( pObj )
                 SAL_WARN("sdext.pdfimport.pdfparse", "   -> object " << 
pObj->m_nNumber << " generation " << pObj->m_nGeneration);
-            else
-                SAL_WARN("sdext.pdfimport.pdfparse", "(type " << 
typeid(*aGrammar.m_aObjectStack[i]).name() << ")");
+            if (aGrammar.m_aObjectStack.empty())
+            {
+                pRet.reset(pEntry); // The first entry references all others - 
see PDFGrammar dtor
+                break;
+            }
         }
     }
-#endif
     return pRet;
 }
 
commit c32e4b58906bf2bedc7b99dd1ac8ab252d67ba3a
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Oct 31 20:09:35 2023 +0300
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Nov 2 00:53:28 2023 +0100

    Try to revert to use of file_iterator from boost on Windows
    
    It was disabled in commit ef8d59c5b909d5a9b956934ab1120f90b90a4e10
    (vcl108: #i106853# work around broken file_iterator on Windows,
    2009-12-01), referencing boost 1.39. It seems to work fine now,
    so let's revert it, and hope it doesn't break something.
    
    Change-Id: I208aa87eca146a29ffc2f36a48810ecda5df0f00
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158736
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158742

diff --git a/sdext/source/pdfimport/pdfparse/pdfparse.cxx 
b/sdext/source/pdfimport/pdfparse/pdfparse.cxx
index 7cef299e8eaa..baa322c1aa3c 100644
--- a/sdext/source/pdfimport/pdfparse/pdfparse.cxx
+++ b/sdext/source/pdfimport/pdfparse/pdfparse.cxx
@@ -558,83 +558,8 @@ public:
 
 }
 
-#ifdef _WIN32
-std::unique_ptr<PDFEntry> PDFReader::read( const char* pBuffer, unsigned int 
nLen )
-{
-    PDFGrammar<const char*> aGrammar( pBuffer );
-
-    try
-    {
-#if OSL_DEBUG_LEVEL > 0
-        boost::spirit::classic::parse_info<const char*> aInfo =
-#endif
-            boost::spirit::classic::parse( pBuffer,
-                                  pBuffer+nLen,
-                                  aGrammar,
-                                  boost::spirit::classic::space_p );
-#if OSL_DEBUG_LEVEL > 0
-        SAL_INFO("sdext.pdfimport.pdfparse", "parseinfo: stop = " << 
aInfo.stop << " (buff=" << pBuffer << ", offset = " << aInfo.stop - pBuffer << 
"), hit = " << (aInfo.hit ? OUString("true") : OUString("false")) << ", full = 
" << (aInfo.full ? OUString("true") : OUString("false")) << ", length = " << 
static_cast<int>(aInfo.length) );
-#endif
-    }
-    catch( const parser_error<const char*, const char*>& rError )
-    {
-#if OSL_DEBUG_LEVEL > 0
-        OString aTmp;
-        unsigned int nElem = aGrammar.m_aObjectStack.size();
-        for( unsigned int i = 0; i < nElem; i++ )
-            aTmp += OString::Concat("   ") + typeid( 
*(aGrammar.m_aObjectStack[i]) ).name();
-
-        SAL_WARN("sdext.pdfimport.pdfparse", "parse error: " << 
rError.descriptor << " at buffer pos " << rError.where - pBuffer << ", object 
stack: " << aTmp);
-#else
-        (void)rError;
-#endif
-    }
-
-    std::unique_ptr<PDFEntry> pRet;
-    unsigned int nEntries = aGrammar.m_aObjectStack.size();
-    if( nEntries == 1 )
-    {
-        pRet.reset(aGrammar.m_aObjectStack.back());
-        aGrammar.m_aObjectStack.pop_back();
-    }
-#if OSL_DEBUG_LEVEL > 0
-    else if( nEntries > 1 )
-        SAL_WARN("sdext.pdfimport.pdfparse", "error got " << nEntries << " 
stack objects in parse" );
-#endif
-
-    return pRet;
-}
-#endif
-
 std::unique_ptr<PDFEntry> PDFReader::read( const char* pFileName )
 {
-#ifdef _WIN32
-    /* #i106583#
-       since converting to boost 1.39 file_iterator does not work anymore on 
all Windows systems
-       C++ stdlib istream_iterator does not allow "-" apparently
-       using spirit 2.0 doesn't work in our environment with the MSC
-
-       So for the time being bite the bullet and read the whole file.
-       FIXME: give Spirit 2.x another try when we upgrade boost again.
-    */
-    std::unique_ptr<PDFEntry> pRet;
-    FILE* fp = fopen( pFileName, "rb" );
-    if( fp )
-    {
-        fseek( fp, 0, SEEK_END );
-        unsigned int nLen = static_cast<unsigned int>(ftell( fp ));
-        fseek( fp, 0, SEEK_SET );
-        char* pBuf = static_cast<char*>(std::malloc( nLen ));
-        if( pBuf )
-        {
-            fread( pBuf, 1, nLen, fp );
-            pRet = read( pBuf, nLen );
-            std::free( pBuf );
-        }
-        fclose( fp );
-    }
-    return pRet;
-#else
     file_iterator<> file_start( pFileName );
     if( ! file_start )
         return nullptr;
@@ -692,7 +617,6 @@ std::unique_ptr<PDFEntry> PDFReader::read( const char* 
pFileName )
     }
 #endif
     return pRet;
-#endif // WIN32
 }
 
 #if defined(_MSC_VER)

Reply via email to