[PATCH] be conservative on allowed temp font names
authorCaolán McNamara <caolan.mcnamara@collabora.com>
Fri, 8 Nov 2024 16:51:47 +0000 (16:51 +0000)
committerRene Engelhard <rene@debian.org>
Tue, 18 Mar 2025 17:53:50 +0000 (18:53 +0100)
Change-Id: Iefdc1a8c9b4c7e8c08c84f747f8287ac3c419839
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176236
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Tested-by: Jenkins
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178289
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Gbp-Pq: Name be-coservative-about-allowed-font-names.diff

vcl/source/gdi/embeddedfontshelper.cxx

index 34d227e5f5b27d402da0ae7bad32ddc7f4425118..ed5c656c46cde81cfc1ba4ab89f05fe0826906ce 100644 (file)
@@ -19,6 +19,7 @@
 #include <vcl/svapp.hxx>
 #include <vcl/embeddedfontshelper.hxx>
 #include <com/sun/star/io/XInputStream.hpp>
+#include <comphelper/storagehelper.hxx>
 
 #include <font/PhysicalFontFaceCollection.hxx>
 #include <font/PhysicalFontCollection.hxx>
@@ -191,10 +192,6 @@ void EmbeddedFontsHelper::activateFonts()
 
 OUString EmbeddedFontsHelper::fileUrlForTemporaryFont( const OUString& fontName, const char* extra )
 {
-    OUString path = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}";
-    rtl::Bootstrap::expandMacros( path );
-    path += "/user/temp/embeddedfonts/fromdocs/";
-    osl::Directory::createPath( path );
     OUString filename = fontName;
     static int uniqueCounter = 0;
     if( strcmp( extra, "?" ) == 0 )
@@ -202,6 +199,17 @@ OUString EmbeddedFontsHelper::fileUrlForTemporaryFont( const OUString& fontName,
     else
         filename += OStringToOUString( extra, RTL_TEXTENCODING_ASCII_US );
     filename += ".ttf"; // TODO is it always ttf?
+
+    if (!::comphelper::OStorageHelper::IsValidZipEntryFileName(filename, false))
+    {
+        SAL_WARN( "vcl.fonts", "Cannot use filename: " << filename << " for temporary font");
+        filename = "font" + OUString::number(uniqueCounter++) + ".ttf";
+    }
+
+    OUString path = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}";
+    rtl::Bootstrap::expandMacros( path );
+    path += "/user/temp/embeddedfonts/fromdocs/";
+    osl::Directory::createPath( path );
     return path + filename;
 }