vcl/inc/fontsubset.hxx | 2 ++ vcl/source/font/font.cxx | 1 + vcl/source/fontsubset/sft.cxx | 31 +++++++++++++++++++++++++++++++ vcl/workben/fftester.cxx | 3 ++- vcl/workben/sftfuzzer.cxx | 5 ++--- 5 files changed, 38 insertions(+), 4 deletions(-)
New commits: commit 237a5e5121a6f12981eb6e4c5a138fc8cfa1c3cf Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Fri Feb 25 15:46:16 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Feb 25 20:56:05 2022 +0100 do more work in sftfuzzer Change-Id: I8a0ae472988f9166dc35eea561a9d5d7084563e6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130539 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/inc/fontsubset.hxx b/vcl/inc/fontsubset.hxx index 1a4c7b80b118..2db54387034e 100644 --- a/vcl/inc/fontsubset.hxx +++ b/vcl/inc/fontsubset.hxx @@ -89,6 +89,8 @@ private: static bool CreateFontSubsetFromType1( const sal_Int32* pOutGlyphWidths ); }; +int VCL_DLLPUBLIC TestFontSubset(const void* data, sal_uInt32 size); + #endif // INCLUDED_VCL_INC_FONTSUBSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/font/font.cxx b/vcl/source/font/font.cxx index 789273aaf40b..16678dd61ac7 100644 --- a/vcl/source/font/font.cxx +++ b/vcl/source/font/font.cxx @@ -30,6 +30,7 @@ #include <impfont.hxx> #include <fontattributes.hxx> +#include <fontsubset.hxx> #include <sft.hxx> #include <algorithm> diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index bfd8c1d5e8e8..999cf07de1d2 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -43,6 +43,7 @@ #include <sal/log.hxx> #include <o3tl/safeint.hxx> #include <osl/endian.h> +#include <fontsubset.hxx> #include <algorithm> namespace vcl @@ -2279,4 +2280,34 @@ bool getTTCoverage( } // namespace vcl +int TestFontSubset(const void* data, sal_uInt32 size) +{ + int nResult = -1; + vcl::TrueTypeFont* pTTF = nullptr; + if (OpenTTFontBuffer(data, size, 0, &pTTF) == vcl::SFErrCodes::Ok) + { + vcl::TTGlobalFontInfo aInfo; + GetTTGlobalFontInfo(pTTF, &aInfo); + + sal_uInt16 aGlyphIds[ 256 ] = {}; + sal_uInt8 aEncoding[ 256 ] = {}; + + for (sal_uInt16 c = 32; c < 256; ++c) + { + aEncoding[c] = c; + aGlyphIds[c] = c - 31; + } + + CreateTTFromTTGlyphs(pTTF, nullptr, aGlyphIds, aEncoding, 256); + + + // cleanup + CloseTTFont( pTTF ); + // success + nResult = 0; + } + + return nResult; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/fftester.cxx b/vcl/workben/fftester.cxx index d69c07708841..3c6645dbb89f 100644 --- a/vcl/workben/fftester.cxx +++ b/vcl/workben/fftester.cxx @@ -69,6 +69,7 @@ #include <rtl/bootstrap.hxx> #include <tools/stream.hxx> #include <vcl/gdimtf.hxx> +#include <fontsubset.hxx> #include "../source/filter/igif/gifread.hxx" #include "../source/filter/ixbm/xbmread.hxx" @@ -525,7 +526,7 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) SvFileStream aFileStream(out, StreamMode::READ); std::vector<sal_uInt8> aData(aFileStream.remainingSize()); aFileStream.ReadBytes(aData.data(), aData.size()); - (void)vcl::Font::identifyFont(aData.data(), aData.size()); + ret = TestFontSubset(aData.data(), aData.size()); } #endif diff --git a/vcl/workben/sftfuzzer.cxx b/vcl/workben/sftfuzzer.cxx index fc951ddc1468..f0a4a9a8cadf 100644 --- a/vcl/workben/sftfuzzer.cxx +++ b/vcl/workben/sftfuzzer.cxx @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <vcl/font.hxx> +#include <fontsubset.hxx> #include "commonfuzzer.hxx" #include <config_features.h> @@ -37,8 +37,7 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - (void)vcl::Font::identifyFont(data, size); - return 0; + return TestFontSubset(data, size); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */