[PATCH] consider VndSunStarExpand an exotic protocol
authorCaolán McNamara <caolan.mcnamara@collabora.com>
Fri, 15 Nov 2024 12:30:39 +0000 (12:30 +0000)
committerRene Engelhard <rene@debian.org>
Tue, 18 Mar 2025 17:53:50 +0000 (18:53 +0100)
and generally don't bother with it when fetching data
from urls

Change-Id: I51a2601c6fb7d6c32f9e2d1286ee0d3b05b370b9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176922
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
(cherry picked from commit 4fbe740677b90d8b73842b60863e2f4c9f4ea382)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178313
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Gbp-Pq: Name consider-VndSunStarExpand-an-exotic-protocol.diff

avmedia/source/viewer/mediawindow_impl.cxx
editeng/source/items/frmitems.cxx
embeddedobj/source/commonembedding/persistence.cxx
forms/source/component/ImageControl.cxx
forms/source/component/clickableimage.cxx
sfx2/source/appl/linkmgr2.cxx
sw/source/filter/html/htmlgrin.cxx
toolkit/source/controls/unocontrols.cxx
tools/source/fsys/urlobj.cxx
unotools/source/misc/mediadescriptor.cxx
vcl/source/filter/graphicfilter.cxx

index a12ed42d4500522db00bc90f56a8643351347a59..c897b3e101036d9e6d152a44535d767e1a0d9112 100644 (file)
@@ -170,15 +170,16 @@ void MediaWindowImpl::dispose()
 
 uno::Reference<media::XPlayer> MediaWindowImpl::createPlayer(const OUString& rURL, const OUString& rReferer, const OUString* pMimeType)
 {
-    uno::Reference<media::XPlayer> xPlayer;
-
     if( rURL.isEmpty() )
-        return xPlayer;
+        return nullptr;
 
     if (SvtSecurityOptions::isUntrustedReferer(rReferer))
-    {
-        return xPlayer;
-    }
+        return nullptr;
+
+    if (INetURLObject(rURL).IsExoticProtocol())
+        return nullptr;
+
+    uno::Reference<media::XPlayer> xPlayer;
 
     if (!pMimeType || *pMimeType == AVMEDIA_MIMETYPE_COMMON)
     {
index 35e1be7b094cf23be3039a97550fbe266732a362..1011570f87e14687faa7f6d527a15c8412f8a7f2 100644 (file)
@@ -45,6 +45,7 @@
 #include <svl/memberid.h>
 #include <rtl/math.hxx>
 #include <rtl/ustring.hxx>
+#include <sal/log.hxx>
 #include <tools/mapunit.hxx>
 #include <tools/UnitConversion.hxx>
 #include <vcl/graphicfilter.hxx>
@@ -3214,6 +3215,13 @@ const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) co
             return nullptr;
         }
 
+        INetURLObject aGraphicURL( maStrLink );
+        if (aGraphicURL.IsExoticProtocol())
+        {
+            SAL_WARN("editeng", "Ignore exotic protocol: " << maStrLink);
+            return nullptr;
+        }
+
         // tdf#94088 prepare graphic and state
         Graphic aGraphic;
         bool bGraphicLoaded = false;
@@ -3234,8 +3242,6 @@ const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) co
         // a 'data:' scheme url and try to load that (embedded graphics)
         if(!bGraphicLoaded)
         {
-            INetURLObject aGraphicURL( maStrLink );
-
             if( INetProtocol::Data == aGraphicURL.GetProtocol() )
             {
                 std::unique_ptr<SvMemoryStream> const xMemStream(aGraphicURL.getData());
index 65e88266a78f388e178827206c95384683a86bc2..d4a2613e9b43a51968f0d2013743b1e82c6a1085 100644 (file)
@@ -55,6 +55,7 @@
 #include <comphelper/namedvaluecollection.hxx>
 #include <comphelper/propertyvalue.hxx>
 #include <unotools/mediadescriptor.hxx>
+#include <tools/urlobj.hxx>
 
 #include <tools/diagnose_ex.h>
 #include <sal/log.hxx>
@@ -373,11 +374,19 @@ uno::Reference< util::XCloseable > OCommonEmbeddedObject::LoadLink_Impl()
     uno::Sequence< beans::PropertyValue > aArgs( m_aDocMediaDescriptor.getLength() + nLen );
     auto pArgs = aArgs.getArray();
 
-    pArgs[0].Name = "URL";
-    if(m_aLinkTempFile.is())
-        pArgs[0].Value <<= m_aLinkTempFile->getUri();
+    OUString sURL;
+    if (m_aLinkTempFile.is())
+        sURL = m_aLinkTempFile->getUri();
     else
-        pArgs[0].Value <<= m_aLinkURL;
+        sURL = m_aLinkURL;
+    if (INetURLObject(sURL).IsExoticProtocol())
+    {
+        SAL_WARN("embeddedobj.common", "Ignore exotic protocol: " << pArgs[0].Value);
+        return nullptr;
+    }
+
+    pArgs[0].Name = "URL";
+    pArgs[0].Value <<= sURL;
 
     pArgs[1].Name = "FilterName";
     pArgs[1].Value <<= m_aLinkFilterName;
index 3e8dee00e3e4f2e721c3c110e1db33cb94d8ffd2..7db4081a9278504cb3d56fde2e60e088358cee8a 100644 (file)
@@ -398,6 +398,10 @@ void OImageControlModel::read(const Reference<XObjectInputStream>& _rxInStream)
 
 bool OImageControlModel::impl_updateStreamForURL_lck( const OUString& _rURL, ValueChangeInstigator _eInstigator )
 {
+    if (INetURLObject(_rURL).IsExoticProtocol()) {
+        return false;
+    }
+
     // create a stream for the image specified by the URL
     std::unique_ptr< SvStream > pImageStream;
     Reference< XInputStream > xImageStream;
index 7079344dbc45fd5c3fbc15750ba5d831d36f059f..0edb76c6c9b4c7c42c19d9d87c0d6a5b896235d9 100644 (file)
@@ -736,7 +736,7 @@ namespace frm
 
         // the SfxMedium is not allowed to be created with an invalid URL, so we have to check this first
         INetURLObject aUrl(rURL);
-        if (INetProtocol::NotValid == aUrl.GetProtocol())
+        if (INetProtocol::NotValid == aUrl.GetProtocol() || aUrl.IsExoticProtocol())
             // we treat an invalid URL like we would treat no URL
             return;
 
index 977ed98518fe300f807766770ecd0d4aa959a391..13a9e00a2eaad9639ca90c1bf7cc87df7887241f 100644 (file)
@@ -526,8 +526,11 @@ bool LinkManager::GetGraphicFromAny(const OUString& rMimeType,
             sReferer = sh->GetMedium()->GetName();
 
         OUString sURL = rValue.get<OUString>();
-        if (!SvtSecurityOptions::isUntrustedReferer(sReferer))
+        if (!SvtSecurityOptions::isUntrustedReferer(sReferer) &&
+            !INetURLObject(sURL).IsExoticProtocol())
+        {
             rGraphic = vcl::graphic::loadFromURL(sURL, pParentWin);
+        }
         if (rGraphic.IsNone())
             rGraphic.SetDefaultType();
         rGraphic.setOriginURL(sURL);
index cbf3727cd77547af1878d2ea7621cf9bc2fa227f..9f592854917aca1bc3b9c6b9fffc860557fff28b 100644 (file)
@@ -672,7 +672,7 @@ IMAGE_SETEVENT:
     bool bNeedWidth = (!bPercentWidth && !nWidth) || bRelWidthScale;
     bool bRelHeightScale = bPercentHeight && nHeight == SwFormatFrameSize::SYNCED;
     bool bNeedHeight = (!bPercentHeight && !nHeight) || bRelHeightScale;
-    if ((bNeedWidth || bNeedHeight) && !m_bFuzzing && allowAccessLink(*m_xDoc))
+    if ((bNeedWidth || bNeedHeight) && !m_bFuzzing && allowAccessLink(*m_xDoc) && !aGraphicURL.IsExoticProtocol())
     {
         GraphicDescriptor aDescriptor(aGraphicURL);
         if (aDescriptor.Detect(/*bExtendedInfo=*/true))
index 260fc13012ff2e73c1c44000b36bb35783efbd44..483edcc83427eedcff9030b39097563c2e6b68a1 100644 (file)
@@ -32,6 +32,7 @@
 #include <controls/formattedcontrol.hxx>
 #include <toolkit/controls/unocontrols.hxx>
 #include <toolkit/helper/property.hxx>
+#include <tools/urlobj.hxx>
 #include <toolkit/helper/macros.hxx>
 
 // for introspection
@@ -67,7 +68,7 @@ css::uno::Reference< css::graphic::XGraphic >
 ImageHelper::getGraphicFromURL_nothrow( const OUString& _rURL )
 {
     uno::Reference< graphic::XGraphic > xGraphic;
-    if ( _rURL.isEmpty() )
+    if (_rURL.isEmpty() || INetURLObject(_rURL).IsExoticProtocol())
         return xGraphic;
 
     try
index 947c653a52e2e052d118e1c7a94ee49763bd8014..ad672f61c68c2d0c70791788c44a9d6c194806ee 100644 (file)
@@ -4832,6 +4832,7 @@ bool INetURLObject::IsExoticProtocol() const
     return m_eScheme == INetProtocol::Slot ||
            m_eScheme == INetProtocol::Macro ||
            m_eScheme == INetProtocol::Uno ||
+           m_eScheme == INetProtocol::VndSunStarExpand ||
            isSchemeEqualTo(u"vnd.sun.star.script") ||
            isSchemeEqualTo(u"service");
 }
index 3b848817e891096ad3b35fd6225d995619e2b3c5..e88fa31c3968c45d30afebcae2d2efb07a58edea 100644 (file)
@@ -334,6 +334,9 @@ bool MediaDescriptor::impl_openStreamWithPostData( const css::uno::Reference< cs
 /*-----------------------------------------------*/
 bool MediaDescriptor::impl_openStreamWithURL( const OUString& sURL, bool bLockFile )
 {
+    if (INetURLObject(sURL).IsExoticProtocol())
+        return false;
+
     OUString referer(getUnpackedValueOrDefault(PROP_REFERRER, OUString()));
     if (SvtSecurityOptions::isUntrustedReferer(referer)) {
         return false;
index d208c7d81e727ca4de3d8b7fa79b033936fe6046..d1a9a2436bd0e2d946829aae40b5b06d97b75481 100644 (file)
@@ -524,10 +524,16 @@ ErrCode GraphicFilter::CanImportGraphic( std::u16string_view rMainUrl, SvStream&
 ErrCode GraphicFilter::ImportGraphic( Graphic& rGraphic, const INetURLObject& rPath,
                                      sal_uInt16 nFormat, sal_uInt16 * pDeterminedFormat, GraphicFilterImportFlags nImportFlags )
 {
-    ErrCode nRetValue = ERRCODE_GRFILTER_FORMATERROR;
     SAL_WARN_IF( rPath.GetProtocol() == INetProtocol::NotValid, "vcl.filter", "GraphicFilter::ImportGraphic() : ProtType == INetProtocol::NotValid" );
 
     OUString    aMainUrl( rPath.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
+    if (rPath.IsExoticProtocol())
+    {
+        SAL_WARN("vcl.filter", "GraphicFilter::ImportGraphic(), ignore exotic protocol: " << aMainUrl);
+        return ERRCODE_GRFILTER_FORMATERROR;
+    }
+
+    ErrCode nRetValue = ERRCODE_GRFILTER_FORMATERROR;
     std::unique_ptr<SvStream> xStream(::utl::UcbStreamHelper::CreateStream( aMainUrl, StreamMode::READ | StreamMode::SHARE_DENYNONE ));
     if (xStream)
     {