external/fontconfig: Silence UBSan nullptr-with-offset

...during CppunitTest_cppcanvas_test,

> fcserialize.c:166:54: runtime error: applying zero offset to null pointer
>  #0 in FcSerializeResize at workdir/UnpackedTarball/fontconfig/src/fcserialize.c:166:54
>  #1 in FcSerializeSet at workdir/UnpackedTarball/fontconfig/src/fcserialize.c:204:7
>  #2 in FcSerializeAlloc at workdir/UnpackedTarball/fontconfig/src/fcserialize.c:228:10
>  #3 in FcStrSerializeAlloc at workdir/UnpackedTarball/fontconfig/src/fcserialize.c:274:12
>  #4 in FcDirCacheBuild at workdir/UnpackedTarball/fontconfig/src/fccache.c:1255:10
>  #5 in FcDirCacheScan at workdir/UnpackedTarball/fontconfig/src/fcdir.c:360:13
>  #6 in FcDirCacheRead at workdir/UnpackedTarball/fontconfig/src/fcdir.c:462:10
>  #7 in FcConfigAddDirList at workdir/UnpackedTarball/fontconfig/src/fccfg.c:516:10
>  #8 in FcConfigAppFontAddDir at workdir/UnpackedTarball/fontconfig/src/fccfg.c:2891:10
>  #9 in psp::PrintFontManager::addFontconfigDir(rtl::OString const&) at vcl/unx/generic/fontmanager/fontconfig.cxx:745:20
>  #10 in psp::PrintFontManager::initialize() at vcl/unx/generic/fontmanager/fontmanager.cxx:683:17
>  #11 in GenericUnixSalData::InitPrintFontManager() at vcl/unx/generic/app/gendata.cxx:65:26
>  #12 in GenericUnixSalData::GetPrintFontManager() at vcl/inc/unx/gendata.hxx💯13
>  #13 in psp::PrintFontManager::get() at vcl/unx/generic/fontmanager/fontmanager.cxx:105:23
>  #14 in GenPspGraphics::GetDevFontListHelper(vcl::font::PhysicalFontCollection*) at vcl/unx/generic/print/genpspgraphics.cxx:248:35
>  #15 in FreeTypeTextRenderImpl::GetDevFontList(vcl::font::PhysicalFontCollection*) at vcl/unx/generic/gdi/freetypetextrender.cxx:110:5
>  #16 in SvpSalGraphics::GetDevFontList(vcl::font::PhysicalFontCollection*) at vcl/headless/svptext.cxx:51:23
>  #17 in OutputDevice::ImplInitFontList() const at vcl/source/outdev/font.cxx:643:17
>  #18 in OutputDevice::ImplNewFont() const at vcl/source/outdev/font.cxx:700:5
>  #19 in OutputDevice::InitFont() const at vcl/source/outdev/font.cxx:660:10
>  #20 in OutputDevice::GetTextHeight() const at vcl/source/outdev/text.cxx:899:10
>  #21 in vcl::Window::GetTextHeight() const at vcl/source/window/window3.cxx:65:65
>  #22 in vcl::Window::ImplInitAppFontData(vcl::Window const*) at vcl/source/window/window.cxx:1188:40
>  #23 in vcl::Window::ImplInit(vcl::Window*, long, SystemParentData*) at vcl/source/window/window.cxx:1182:9
>  #24 in ImplBorderWindow::ImplInit(vcl::Window*, long, BorderWindowStyle, SystemParentData*) at vcl/source/window/brdwin.cxx:1557:13
>  #25 in ImplBorderWindow::ImplBorderWindow(vcl::Window*, SystemParentData*, long, BorderWindowStyle) at vcl/source/window/brdwin.cxx:1586:5
>  #26 in VclPtrInstance<ImplBorderWindow>::VclPtrInstance<vcl::Window*&, SystemParentData*&, long&, BorderWindowStyle&>(vcl::Window*&, SystemParentData*&, long&, BorderWindowStyle&) at include/vcl/vclptr.hxx:280:39
>  #27 in WorkWindow::ImplInit(vcl::Window*, long, SystemParentData*) at vcl/source/window/wrkwin.cxx:51:38
>  #28 in WorkWindow::WorkWindow(vcl::Window*, long) at vcl/source/window/wrkwin.cxx:95:5
>  #29 in ScopedVclPtrInstance<WorkWindow>::ScopedVclPtrInstance<std::nullptr_t, long const&>(std::nullptr_t&&, long const&) at include/vcl/vclptr.hxx:412:45
>  #30 in CanvasTest::testComposite() at cppcanvas/qa/unit/test.cxx:38:38

Change-Id: I90c86931ae5d4dfb32a1a95a5eb660484b54f09a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148287
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann 2023-03-05 23:41:16 +01:00
parent 5d4749b5c2
commit 7e2d269bad

View file

@ -9,3 +9,14 @@
/*
* Scan file files to build font patterns
--- src/fcserialize.c
+++ src/fcserialize.c
@@ -163,7 +163,7 @@
size_t old_used = serialize->buckets_used;
size_t old_count = serialize->buckets_count;
FcSerializeBucket *old_buckets = serialize->buckets;
- FcSerializeBucket *old_buckets_end = old_buckets + old_count;
+ FcSerializeBucket *old_buckets_end = old_count == 0 ? old_buckets : old_buckets + old_count;
FcSerializeBucket *new_buckets = malloc (new_count * sizeof (*old_buckets));
if (!new_buckets)