hwpfilter/source/hwpreader.cxx |   54 +++++++++++++++++++++--------------------
 hwpfilter/source/hwpreader.hxx |    2 +
 2 files changed, 30 insertions(+), 26 deletions(-)

New commits:
commit e1f5044b43dbe13e0c5a8383ec3f84b4c2c44ddd
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Tue Feb 22 15:39:35 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Feb 23 11:20:44 2022 +0100

    we should be testing more in the hwpfuzzer
    
    Change-Id: I742efee39496d098677fa251727494bb741f627d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130357
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index d402e4250e92..923d81f32cc8 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -130,39 +130,17 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool 
TestImportHWP(SvStream &rStream)
             stream->addData(aData, static_cast<int>(nRead));
         }
 
-        HWPFile hwpfile;
-        if (hwpfile.ReadHwpFile(std::move(stream)))
-            return false;
+        rtl::Reference<HwpReader> hwpreader(new HwpReader);
+        return hwpreader->importHStream(std::move(stream));
     }
     catch (...)
     {
-        return false;
     }
-    return true;
+    return false;
 }
 
-sal_Bool HwpReader::filter(const Sequence< PropertyValue >& rDescriptor)
+bool HwpReader::importHStream(std::unique_ptr<HStream> stream)
 {
-    utl::MediaDescriptor aDescriptor(rDescriptor);
-    aDescriptor.addInputStream();
-
-    Reference< XInputStream > xInputStream(
-        aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM], UNO_QUERY_THROW);
-
-    std::unique_ptr<HStream> stream(new HStream);
-    Sequence < sal_Int8 > aBuffer;
-    sal_Int32 nRead, nTotal = 0;
-    while( true )
-    {
-        nRead = xInputStream->readBytes(aBuffer, 32768);
-        if( nRead == 0 )
-            break;
-        stream->addData( reinterpret_cast<const byte 
*>(aBuffer.getConstArray()), nRead );
-        nTotal += nRead;
-    }
-
-    if( nTotal == 0 ) return false;
-
     if (hwpfile.ReadHwpFile(std::move(stream)))
           return false;
 
@@ -205,6 +183,30 @@ sal_Bool HwpReader::filter(const Sequence< PropertyValue 
>& rDescriptor)
     return true;
 }
 
+sal_Bool HwpReader::filter(const Sequence< PropertyValue >& rDescriptor)
+{
+    utl::MediaDescriptor aDescriptor(rDescriptor);
+    aDescriptor.addInputStream();
+
+    Reference< XInputStream > xInputStream(
+        aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM], UNO_QUERY_THROW);
+
+    std::unique_ptr<HStream> stream(new HStream);
+    Sequence < sal_Int8 > aBuffer;
+    sal_Int32 nRead, nTotal = 0;
+    while( true )
+    {
+        nRead = xInputStream->readBytes(aBuffer, 32768);
+        if( nRead == 0 )
+            break;
+        stream->addData( reinterpret_cast<const byte 
*>(aBuffer.getConstArray()), nRead );
+        nTotal += nRead;
+    }
+
+    if( nTotal == 0 ) return false;
+
+    return importHStream(std::move(stream));
+}
 
 /**
  * make office:body
diff --git a/hwpfilter/source/hwpreader.hxx b/hwpfilter/source/hwpreader.hxx
index 91021a326186..309f454e6ffe 100644
--- a/hwpfilter/source/hwpreader.hxx
+++ b/hwpfilter/source/hwpreader.hxx
@@ -88,6 +88,8 @@ public:
     {
         m_rxDocumentHandler = xHandler;
     }
+
+    bool importHStream(std::unique_ptr<HStream> stream);
 private:
     Reference< XDocumentHandler > m_rxDocumentHandler;
     rtl::Reference<AttributeListImpl> mxList;

Reply via email to