revive sftfuzzer for a different code path

Change-Id: Idd2d422c54707262bb76069640e7e251489debfe
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/743
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
(cherry picked from commit acfe01e58b870f9414fc5b09c2c7abcc8bc5f764)
Cherry-pick note: the fuzzer has been adapted to test
4c3c87e79d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204900
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
This commit is contained in:
Caolán McNamara
2026-05-13 16:18:54 +02:00
committed by Xisco Fauli
parent 7f05f27f5b
commit daca39681e
9 changed files with 135 additions and 6 deletions
+8 -6
View File
@@ -116,15 +116,17 @@ mkdir -p afl-testcases && cd afl-testcases/ && tar xf $SRC/afl_testcases.tgz &&
zip -q $SRC/webpfuzzer_seed_corpus.zip afl-testcases/webp*/full/images/*
# TTF/OTF/SFT
# using github's svn view to use svn export as a hack to just export part of the git repo
# svn support turned off now: https://github.blog/2023-01-20-sunsetting-subversion-support/
# and git sparse checkout is a total pain
#svn export --force -q https://github.com/khaledhosny/ots/trunk/tests/fonts $SRC/sample-sft-fonts/ots
#svn export --force -q https://github.com/unicode-org/text-rendering-tests/trunk/fonts/ $SRC/sample-sft-fonts/unicode-org
#svn export --force -q https://github.com/harfbuzz/harfbuzz/trunk/test/shape/data/in-house/fonts $SRC/sample-sft-fonts/harfbuzz
mkdir -p $SRC/sample-sft-fonts/adobe
curl --no-progress-meter -S \
-C - -o $SRC/sample-sft-fonts/adobe/AdobeVFPrototype.otf https://github.com/adobe-fonts/adobe-variable-font-prototype/releases/download/1.005a/AdobeVFPrototype.otf
git clone --depth 1 --filter=blob:none --sparse https://github.com/khaledhosny/ots.git && \
cd ots && git sparse-checkout set tests/fonts && cd .. && \
cp -r ots/tests/fonts $SRC/sample-sft-fonts/ots && rm -rf ots
git clone --depth 1 --filter=blob:none --sparse https://github.com/harfbuzz/harfbuzz.git && \
cd harfbuzz && git sparse-checkout set test/shape/data/in-house/fonts && cd .. && \
cp -r harfbuzz/test/shape/data/in-house/fonts $SRC/sample-sft-fonts/harfbuzz && rm -rf harfbuzz
# exclude very large fonts that are slow to process under sanitizers
find $SRC/sample-sft-fonts -size +1M -delete
zip -qr $SRC/sftfuzzer_seed_corpus.zip $SRC/sample-sft-fonts
# PDF
+4
View File
@@ -20,6 +20,10 @@ $(eval $(call gb_Executable_set_include,fftester,\
-I$(SRCDIR)/vcl/inc \
))
$(eval $(call gb_Executable_use_externals,fftester,\
harfbuzz \
))
$(eval $(call gb_Executable_use_libraries,fftester,\
tl \
sal \
+45
View File
@@ -0,0 +1,45 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
#
# This file is part of the Collabora Office 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,sftfuzzer))
$(eval $(call gb_Executable_use_api,sftfuzzer,\
offapi \
udkapi \
))
$(eval $(call gb_Executable_use_externals,sftfuzzer,\
$(fuzzer_externals) \
))
$(eval $(call gb_Executable_set_include,sftfuzzer,\
$$(INCLUDE) \
-I$(SRCDIR)/vcl/inc \
))
$(eval $(call gb_Executable_use_libraries,sftfuzzer,\
$(fuzzer_core_libraries) \
))
$(eval $(call gb_Executable_use_static_libraries,sftfuzzer,\
$(fuzzer_statics) \
))
$(eval $(call gb_Executable_add_exception_objects,sftfuzzer,\
vcl/workben/sftfuzzer \
))
$(eval $(call gb_Executable_add_libs,sftfuzzer,\
$(LIB_FUZZING_ENGINE) \
))
# vim: set noet sw=4 ts=4:
+1
View File
@@ -215,6 +215,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
Executable_mtpfuzzer \
Executable_htmlfuzzer \
Executable_eotfuzzer \
Executable_sftfuzzer \
Executable_dbffuzzer \
Executable_webpfuzzer \
Executable_zipfuzzer \
+2
View File
@@ -185,4 +185,6 @@ public:
} // namespace vcl
int VCL_DLLPUBLIC TestFontParsing(const void* data, sal_uInt32 size);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+15
View File
@@ -207,4 +207,19 @@ FontWeight TrueTypeFont::getFontWeight() const
} // namespace vcl
int TestFontParsing(const void* data, sal_uInt32 size)
{
// Exercise TrueType/OpenType parsing
if (data && size > 0)
{
FontSubsetInfo aInfo;
aInfo.m_nFontType = FontType::TYPE1_PFB;
std::vector<sal_uInt8> aOutBuffer;
vcl::ConvertCFFfontToType1(static_cast<const unsigned char*>(data), size, aOutBuffer,
aInfo);
}
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+9
View File
@@ -1700,6 +1700,15 @@ void CffContext::readDictOp()
ValType nVal = fReal;
push(nVal);
}
else
{
// bytes 22-27, 31 and 255 are reserved in CFF DICT encoding
// (Adobe Technical Note #5176, section 4 "DICT Data")
// https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf
// skip to avoid infinite loop
SAL_WARN("vcl.fonts.cff", "undefined CFF DICT byte: " << int(c));
++mpReadPtr;
}
}
void CffContext::read2push()
+8
View File
@@ -61,6 +61,7 @@
#include <filter/DxfReader.hxx>
#include <filter/WebpReader.hxx>
#include <filter/XpmReader.hxx>
#include <font/TrueTypeFont.hxx>
#include <osl/file.hxx>
#include <osl/module.hxx>
#include <osl/process.h>
@@ -262,6 +263,13 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
aFileStream.ReadBytes(aData.data(), aData.size());
ret = TestEOT(aData.data(), aData.size());
}
else if (strcmp(argv[2], "sft") == 0)
{
SvFileStream aFileStream(out, StreamMode::READ);
std::vector<sal_uInt8> aData(aFileStream.remainingSize());
aFileStream.ReadBytes(aData.data(), aData.size());
ret = TestFontParsing(aData.data(), aData.size());
}
#ifndef DISABLE_DYNLOADING
else if ((strcmp(argv[2], "doc") == 0) || (strcmp(argv[2], "ww8") == 0))
{
+43
View File
@@ -0,0 +1,43 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the Collabora Office 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 <font/TrueTypeFont.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 TestFontParsing(data, size);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */