Repository.mk | 1 bin/oss-fuzz-setup.sh | 1 include/vcl/font/EOTConverter.hxx | 2 + vcl/Executable_eotfuzzer.mk | 45 +++++++++++++++++++++++++++++++ vcl/Module_vcl.mk | 1 vcl/qa/cppunit/font/TTFStructureTest.cxx | 18 ++++++------ vcl/source/font/EOTConverter.cxx | 35 +++++++++++++++--------- vcl/workben/eotfuzzer.cxx | 43 +++++++++++++++++++++++++++++ vcl/workben/fftester.cxx | 8 +++++ 9 files changed, 133 insertions(+), 21 deletions(-)
New commits: commit e70cccc17cf1dbe8ff658617ac348bd0a981abc5 Author: Caolán McNamara <[email protected]> AuthorDate: Tue May 27 16:20:23 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Tue May 27 21:28:59 2025 +0200 Hanlder->Handler Change-Id: I5a2a2158bd4c5bf33441bb083129f9b3f8cc069e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185918 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/vcl/qa/cppunit/font/TTFStructureTest.cxx b/vcl/qa/cppunit/font/TTFStructureTest.cxx index d144fb46e36a..c644614244e8 100644 --- a/vcl/qa/cppunit/font/TTFStructureTest.cxx +++ b/vcl/qa/cppunit/font/TTFStructureTest.cxx @@ -35,8 +35,8 @@ CPPUNIT_TEST_FIXTURE(TTFTest, testReadTTFStructure) font::FontDataContainer aContainer(aFontBytes); font::TTFFont aFont(aContainer); - auto pHanlder = aFont.getTableEntriesHandler(); - const font::OS2Table* pOS2 = pHanlder->getOS2Table(); + auto pHandler = aFont.getTableEntriesHandler(); + const font::OS2Table* pOS2 = pHandler->getOS2Table(); CPPUNIT_ASSERT(pOS2); CPPUNIT_ASSERT_EQUAL(sal_uInt16(400), sal_uInt16(pOS2->nWeightClass)); CPPUNIT_ASSERT_EQUAL(sal_uInt16(5), sal_uInt16(pOS2->nWidthClass)); @@ -48,33 +48,33 @@ CPPUNIT_TEST_FIXTURE(TTFTest, testReadTTFStructure) CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), sal_uInt16(pOS2->nUnicodeRange3)); CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), sal_uInt16(pOS2->nUnicodeRange4)); - const font::HeadTable* pHeadTable = pHanlder->getHeadTable(); + const font::HeadTable* pHeadTable = pHandler->getHeadTable(); CPPUNIT_ASSERT(pHeadTable); CPPUNIT_ASSERT_EQUAL(sal_uInt16(1000), sal_uInt16(pHeadTable->nUnitsPerEm)); - auto pNameTableHanlder = pHanlder->getNameTableHandler(); - CPPUNIT_ASSERT(pNameTableHanlder); + auto pNameTableHandler = pHandler->getNameTableHandler(); + CPPUNIT_ASSERT(pNameTableHandler); sal_uInt64 nOffset = 0; sal_uInt16 nLength = 0; - CPPUNIT_ASSERT(pNameTableHanlder->findEnglishUnicodeNameOffset(font::NameID::FamilyName, + CPPUNIT_ASSERT(pNameTableHandler->findEnglishUnicodeNameOffset(font::NameID::FamilyName, nOffset, nLength)); OUString aFamilyName = aFont.getNameTableString(nOffset, nLength); CPPUNIT_ASSERT_EQUAL(u"Ahem"_ustr, aFamilyName); - CPPUNIT_ASSERT(pNameTableHanlder->findEnglishUnicodeNameOffset(font::NameID::FullFontName, + CPPUNIT_ASSERT(pNameTableHandler->findEnglishUnicodeNameOffset(font::NameID::FullFontName, nOffset, nLength)); OUString aFullFontName = aFont.getNameTableString(nOffset, nLength); CPPUNIT_ASSERT_EQUAL(u"Ahem"_ustr, aFullFontName); - CPPUNIT_ASSERT(pNameTableHanlder->findEnglishUnicodeNameOffset(font::NameID::SubfamilyName, + CPPUNIT_ASSERT(pNameTableHandler->findEnglishUnicodeNameOffset(font::NameID::SubfamilyName, nOffset, nLength)); OUString aSubFamilyName = aFont.getNameTableString(nOffset, nLength); CPPUNIT_ASSERT_EQUAL(u"Regular"_ustr, aSubFamilyName); CPPUNIT_ASSERT( - pNameTableHanlder->findEnglishUnicodeNameOffset(font::NameID::Version, nOffset, nLength)); + pNameTableHandler->findEnglishUnicodeNameOffset(font::NameID::Version, nOffset, nLength)); OUString aVersion = aFont.getNameTableString(nOffset, nLength); CPPUNIT_ASSERT_EQUAL(u"Version 1.1"_ustr, aVersion); } diff --git a/vcl/source/font/EOTConverter.cxx b/vcl/source/font/EOTConverter.cxx index 0d9e6a978d16..12d52038a506 100644 --- a/vcl/source/font/EOTConverter.cxx +++ b/vcl/source/font/EOTConverter.cxx @@ -23,7 +23,7 @@ namespace { // Writes padding, length and string data to font output void writeNameTableString(font::TTFFont& rFont, - std::unique_ptr<NameTableHandler>& pNameTableHanlder, + std::unique_ptr<NameTableHandler>& pNameTableHandler, font::NameID eNameID, std::vector<sal_uInt8>& rEotOutput) { sal_uInt64 nOffset = 0; @@ -33,8 +33,8 @@ void writeNameTableString(font::TTFFont& rFont, rEotOutput.push_back(0); rEotOutput.push_back(0); - if (pNameTableHanlder - && pNameTableHanlder->findEnglishUnicodeNameOffset(eNameID, nOffset, nLength)) + if (pNameTableHandler + && pNameTableHandler->findEnglishUnicodeNameOffset(eNameID, nOffset, nLength)) { // Length rEotOutput.push_back(sal_uInt8((nLength + 2) & 0xff)); @@ -78,11 +78,11 @@ bool EOTConverter::convert(std::vector<sal_uInt8>& rEotOutput) pEot->nReserved3 = 0; pEot->nReserved4 = 0; - auto pHanlder = aFont.getTableEntriesHandler(); - if (!pHanlder) + auto pHandler = aFont.getTableEntriesHandler(); + if (!pHandler) return false; - const font::OS2Table* pOS2 = pHanlder->getOS2Table(); + const font::OS2Table* pOS2 = pHandler->getOS2Table(); if (pOS2) { for (sal_uInt32 n = 0; n < 10; n++) @@ -101,18 +101,18 @@ bool EOTConverter::convert(std::vector<sal_uInt8>& rEotOutput) pEot->nCodePageRange2 = pOS2->nCodePageRange2; } - const font::HeadTable* pHeadTable = pHanlder->getHeadTable(); + const font::HeadTable* pHeadTable = pHandler->getHeadTable(); if (pHeadTable) { pEot->nCheckSumAdjustment = pHeadTable->nCheckSumAdjustment; } - auto pNameTableHanlder = pHanlder->getNameTableHandler(); + auto pNameTableHandler = pHandler->getNameTableHandler(); - writeNameTableString(aFont, pNameTableHanlder, font::NameID::FamilyName, rEotOutput); - writeNameTableString(aFont, pNameTableHanlder, font::NameID::SubfamilyName, rEotOutput); - writeNameTableString(aFont, pNameTableHanlder, font::NameID::Version, rEotOutput); - writeNameTableString(aFont, pNameTableHanlder, font::NameID::FullFontName, rEotOutput); + writeNameTableString(aFont, pNameTableHandler, font::NameID::FamilyName, rEotOutput); + writeNameTableString(aFont, pNameTableHandler, font::NameID::SubfamilyName, rEotOutput); + writeNameTableString(aFont, pNameTableHandler, font::NameID::Version, rEotOutput); + writeNameTableString(aFont, pNameTableHandler, font::NameID::FullFontName, rEotOutput); // Padding5 rEotOutput.push_back(0); commit 61eb2261e187989178f660abd42b6d6fa0d34f22 Author: Caolán McNamara <[email protected]> AuthorDate: Tue May 27 09:13:57 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Tue May 27 21:28:47 2025 +0200 add an eot fuzzer Change-Id: I419c3717f168e3bfbdbee2ac4b6b2f1eb2540bd0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185887 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/Repository.mk b/Repository.mk index 546e72f4eddf..731ab85076c4 100644 --- a/Repository.mk +++ b/Repository.mk @@ -167,6 +167,7 @@ $(eval $(call gb_Helper_register_executables_for_install,OOO,brand, \ $(call gb_Helper_optional,FUZZERS,mtpfuzzer) \ $(call gb_Helper_optional,FUZZERS,htmlfuzzer) \ $(call gb_Helper_optional,FUZZERS,sftfuzzer) \ + $(call gb_Helper_optional,FUZZERS,eotfuzzer) \ $(call gb_Helper_optional,FUZZERS,dbffuzzer) \ $(call gb_Helper_optional,FUZZERS,webpfuzzer) \ $(call gb_Helper_optional,FUZZERS,zipfuzzer) \ diff --git a/bin/oss-fuzz-setup.sh b/bin/oss-fuzz-setup.sh index 4df82dd0e050..97f74edc0cfc 100755 --- a/bin/oss-fuzz-setup.sh +++ b/bin/oss-fuzz-setup.sh @@ -170,5 +170,6 @@ cp fodtfuzzer_seed_corpus.zip fodt2pdffuzzer_seed_corpus.zip cp rtffuzzer_seed_corpus.zip rtf2pdffuzzer_seed_corpus.zip cp fodsfuzzer_seed_corpus.zip fods2xlsfuzzer_seed_corpus.zip cp htmlfuzzer_seed_corpus.zip schtmlfuzzer_seed_corpus.zip +cp sftfuzzer_seed_corpus.zip eotfuzzer_seed_corpus.zip echo end downloading dependencies at `date -u` diff --git a/include/vcl/font/EOTConverter.hxx b/include/vcl/font/EOTConverter.hxx index 8695355b3628..cf55420455c5 100644 --- a/include/vcl/font/EOTConverter.hxx +++ b/include/vcl/font/EOTConverter.hxx @@ -64,4 +64,6 @@ public: } // end font namespace +int VCL_DLLPUBLIC TestEOT(const void* data, sal_uInt32 size); + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/Executable_eotfuzzer.mk b/vcl/Executable_eotfuzzer.mk new file mode 100644 index 000000000000..a6a3fc72f9d8 --- /dev/null +++ b/vcl/Executable_eotfuzzer.mk @@ -0,0 +1,45 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +include $(SRCDIR)/vcl/commonfuzzer.mk + +$(eval $(call gb_Executable_Executable,eotfuzzer)) + +$(eval $(call gb_Executable_use_api,eotfuzzer,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_Executable_use_externals,eotfuzzer,\ + $(fuzzer_externals) \ +)) + +$(eval $(call gb_Executable_set_include,eotfuzzer,\ + $$(INCLUDE) \ + -I$(SRCDIR)/vcl/inc \ +)) + +$(eval $(call gb_Executable_use_libraries,eotfuzzer,\ + $(fuzzer_core_libraries) \ +)) + +$(eval $(call gb_Executable_use_static_libraries,eotfuzzer,\ + $(fuzzer_statics) \ +)) + +$(eval $(call gb_Executable_add_exception_objects,eotfuzzer,\ + vcl/workben/eotfuzzer \ +)) + +$(eval $(call gb_Executable_add_libs,eotfuzzer,\ + $(LIB_FUZZING_ENGINE) \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk index b2eeb946bf02..6d02927da307 100644 --- a/vcl/Module_vcl.mk +++ b/vcl/Module_vcl.mk @@ -209,6 +209,7 @@ $(eval $(call gb_Module_add_targets,vcl,\ Executable_mtpfuzzer \ Executable_htmlfuzzer \ Executable_sftfuzzer \ + Executable_eotfuzzer \ Executable_dbffuzzer \ Executable_webpfuzzer \ Executable_zipfuzzer \ diff --git a/vcl/source/font/EOTConverter.cxx b/vcl/source/font/EOTConverter.cxx index 89b1199e2a40..0d9e6a978d16 100644 --- a/vcl/source/font/EOTConverter.cxx +++ b/vcl/source/font/EOTConverter.cxx @@ -165,4 +165,15 @@ bool EOTConverter::convert(std::vector<sal_uInt8>& rEotOutput) } // end font namespace +int TestEOT(const void* data, sal_uInt32 size) +{ + const sal_uInt8* bytes = static_cast<const sal_uInt8*>(data); + std::vector<sal_uInt8> input(bytes, bytes + size); + + std::vector<sal_uInt8> aEOT; + font::FontDataContainer aContainer(input); + font::EOTConverter aConverter(aContainer); + return aConverter.convert(aEOT) ? 1 : 0; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/eotfuzzer.cxx b/vcl/workben/eotfuzzer.cxx new file mode 100644 index 000000000000..7882e73c70ad --- /dev/null +++ b/vcl/workben/eotfuzzer.cxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <vcl/font/EOTConverter.hxx> +#include "commonfuzzer.hxx" + +#include <config_features.h> +#include <osl/detail/component-mapping.h> + +const lib_to_factory_mapping* lo_get_factory_map(void) +{ + static lib_to_factory_mapping map[] = { { 0, 0 } }; + + return map; +} + +const lib_to_constructor_mapping* lo_get_constructor_map(void) +{ + static lib_to_constructor_mapping map[] = { { 0, 0 } }; + + return map; +} + +extern "C" void* lo_get_custom_widget_func(const char*) { return nullptr; } + +extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) +{ + TypicalFuzzerInitialize(argc, argv); + return 0; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + return TestEOT(data, size); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/fftester.cxx b/vcl/workben/fftester.cxx index b78ea9ec9b60..b397d0cdd728 100644 --- a/vcl/workben/fftester.cxx +++ b/vcl/workben/fftester.cxx @@ -47,6 +47,7 @@ #include <vcl/graphicfilter.hxx> #include <vcl/filter/PngImageReader.hxx> #include <vcl/filter/SvmReader.hxx> +#include <vcl/font/EOTConverter.hxx> #include <vcl/svapp.hxx> #include <vcl/virdev.hxx> #include <vcl/wmf.hxx> @@ -261,6 +262,13 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) aFileStream.ReadBytes(aData.data(), aData.size()); ret = TestFontSubset(aData.data(), aData.size()); } + else if (strcmp(argv[2], "eot") == 0) + { + SvFileStream aFileStream(out, StreamMode::READ); + std::vector<sal_uInt8> aData(aFileStream.remainingSize()); + aFileStream.ReadBytes(aData.data(), aData.size()); + ret = TestEOT(aData.data(), aData.size()); + } #ifndef DISABLE_DYNLOADING else if ((strcmp(argv[2], "doc") == 0) || (strcmp(argv[2], "ww8") == 0)) {
