[Libreoffice-commits] core.git: Branch 'libreoffice-5-4-2' - sax/source

Takeshi Abe tabe at fixedpoint.jp
Tue Sep 26 11:12:13 UTC 2017


 sax/source/expatwrap/xml2utf.cxx |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

New commits:
commit 959e1b409b01ffcf80ed091724fa51a54e97c3c7
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Tue Jul 18 22:44:33 2017 +0900

    sax: Check if it starts with 5 bytes of "<?xml"
    
    Reviewed-on: https://gerrit.libreoffice.org/40139
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    (cherry picked from commit b64e564492220b34c14f069e8e1f42675bd9abe6)
    
    ofz: string has to be at least 5 chars long
    
    Reviewed-on: https://gerrit.libreoffice.org/42379
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    
    this should presumably be 5, rather than 4
    
    Change-Id: Iec5b748b188c7b1bf61e8137faf4b3f2d480d7f1
    98c50a59c03fc886d50362b9c5dd8c84f60e0b62
    20c6a6fb34485f42c2a828618e8918d8a441860a
    Reviewed-on: https://gerrit.libreoffice.org/42396
    Reviewed-by: Julien Nabet <serval2412 at yahoo.fr>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
    Tested-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/sax/source/expatwrap/xml2utf.cxx b/sax/source/expatwrap/xml2utf.cxx
index 6ccecc684983..c37f7d3a0c8e 100644
--- a/sax/source/expatwrap/xml2utf.cxx
+++ b/sax/source/expatwrap/xml2utf.cxx
@@ -125,7 +125,7 @@ XMLFile2UTFConverter::~XMLFile2UTFConverter()
 void XMLFile2UTFConverter::removeEncoding( Sequence<sal_Int8> &seq )
 {
     const sal_Int8 *pSource = seq.getArray();
-    if( ! strncmp( reinterpret_cast<const char *>(pSource), "<?xml", 4) )
+    if (seq.getLength() >= 5 && !strncmp(reinterpret_cast<const char *>(pSource), "<?xml", 5))
     {
 
         // scan for encoding
@@ -160,7 +160,6 @@ void XMLFile2UTFConverter::removeEncoding( Sequence<sal_Int8> &seq )
                                 &( seq.getArray()[nStop+1]) ,
                                 seq.getLength() - nStop -1);
                 seq.realloc( seq.getLength() - ( nStop+1 - nFound ) );
-//              str = String( (char * ) seq.getArray() , seq.getLen() );
             }
         }
     }
@@ -177,7 +176,7 @@ bool XMLFile2UTFConverter::isEncodingRecognizable( const Sequence< sal_Int8 > &s
         return false;
     }
 
-    if( ! strncmp( reinterpret_cast<const char *>(pSource), "<?xml", 4 ) ) {
+    if( ! strncmp( reinterpret_cast<const char *>(pSource), "<?xml", 5 ) ) {
         // scan if the <?xml tag finishes within this buffer
         bCheckIfFirstClosingBracketExsists = true;
     }
@@ -222,8 +221,7 @@ bool XMLFile2UTFConverter::scanForEncoding( Sequence< sal_Int8 > &seq )
     }
 
     // first level : detect possible file formats
-    if( ! strncmp( reinterpret_cast<const char *>(pSource), "<?xml", 4 ) ) {
-
+    if (seq.getLength() >= 5 && !strncmp(reinterpret_cast<const char *>(pSource), "<?xml", 5)) {
         // scan for encoding
         OString str( reinterpret_cast<const char *>(pSource), seq.getLength() );
 


More information about the Libreoffice-commits mailing list