oox/source/export/drawingml.cxx |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 260c86dc7a9d5354ece91ef97ebbd7e65ae97a3b
Author:     Skyler Grey <skyler.g...@collabora.com>
AuthorDate: Mon Nov 18 14:20:29 2024 +0000
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Tue Nov 19 05:40:54 2024 +0100

    fix(ooxmlexport): Prevent unknown media type crash
    
    To determine the extension of a media file, we just take whatever parts
    of the URL were left after the final dot.
    
    Normally this is something normal such as `mp4`, `mp3` or suchlike
    
    Unfortunately, sometimes (such as when in Collabora Online) this URL
    would is actually be something Uno-y, leaving an extension like
    
       Package:Media
    
    That's no good, because in Zip files we can't have colons in our names,
    at least according to our Zip file name checker, which looks through and
    denies access to any file names that have colons in
    
        bool OStorageHelper::IsValidZipEntryFileName( std::u16string_view 
aName, bool bSlashAllowed )
        {
            long nDots{0};
            for ( size_t i = 0; i < aName.size(); i++ )
            {
                switch ( aName[i] )
                {
                    // ------------------ 8< cut ------------------
                    case ':':
                        return false;
    
    Promptly causing us not to open a file output stream...
    
        if ( aElementName.isEmpty() || 
!::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, false ) )
            throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry 
name syntax.", uno::Reference< uno::XInterface >(), 1 );
    
        -> leading to implOpenSubStorage failing to set xSubXStorage...
    
        if( mxStorage.is() ) try
        {
            // XStorage::isStorageElement may throw various exceptions...
            if( mxStorage->isStorageElement( rElementName ) )
                xSubXStorage = mxStorage->openStorageElement(
                    rElementName, css::embed::ElementModes::READ );
        } catch ... { ... }
    
    ...and eventually to us never having an output stream in the first place...
    
        Reference<XOutputStream> xOutStream = 
mpFB->openFragmentStream(sFileName, aMimeType);
    
        gdb$ print xOutStream
        $1 = empty uno::Reference
    
    ...and crashing the code that tries to copy to that stream.
    
    The upshot of this bug is that any videos inserted with Collabora Online
    (or presumably similar .uno command use) crash LO when you later try to
    save your .pptx
    
    The quick fix here is to replace colons with another character, which is
    what I've done here. Future followup patches could do other sensible
    things like stopping crashes if we can't open an output stream for
    whatever reason or figuring out what to do with names that aren't
    permitted for reasons other than colon use.
    
    Change-Id: I9113b272d29f74882dc25bf6e74306bd9ecd58a2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176719
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index a3e5356c0523..c5e3f278ef8a 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -1631,7 +1631,7 @@ void DrawingML::WriteMediaNonVisualProperties(const 
css::uno::Reference<css::dra
     const OUString& rURL(pMediaObj->getURL());
     int nLastDot = rURL.lastIndexOf('.');
     if (nLastDot >= 0)
-        aExtension = rURL.copy(nLastDot);
+        aExtension = rURL.copy(nLastDot).replace(':', '_'); // Colons are not 
allowed in Zip entry file names, see OStorageHelper::IsValidZipEntryFileName
 
     bool bEmbed = rURL.startsWith("vnd.sun.star.Package:");
     Relationship eMediaType = Relationship::VIDEO;

Reply via email to