summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/harfbuzz/tests
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-06-17 06:37:38 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-06-17 06:37:38 (GMT)
commitd2c04d76fc26300a33842a2ef52613f189a07c3c (patch)
tree841c2bd8a452a3209dd1d40e0d53f26a2f6674ca /src/3rdparty/harfbuzz/tests
parentf8080432e1307c099aee65153870af7c1677ccba (diff)
parentcc621ba462331ad936f47c44c22030392caa574f (diff)
downloadQt-d2c04d76fc26300a33842a2ef52613f189a07c3c.zip
Qt-d2c04d76fc26300a33842a2ef52613f189a07c3c.tar.gz
Qt-d2c04d76fc26300a33842a2ef52613f189a07c3c.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'src/3rdparty/harfbuzz/tests')
-rw-r--r--src/3rdparty/harfbuzz/tests/fuzzing/fuzz.cc124
-rw-r--r--src/3rdparty/harfbuzz/tests/linebreaking/harfbuzz-qt.cpp25
2 files changed, 126 insertions, 23 deletions
diff --git a/src/3rdparty/harfbuzz/tests/fuzzing/fuzz.cc b/src/3rdparty/harfbuzz/tests/fuzzing/fuzz.cc
new file mode 100644
index 0000000..133577a
--- /dev/null
+++ b/src/3rdparty/harfbuzz/tests/fuzzing/fuzz.cc
@@ -0,0 +1,124 @@
+// This is a fuzzing harness for Harfbuzz. Since Harfbuzz's input is generally
+// expected to be controlled by a remote party it's a possible vector for
+// security issues.
+//
+// Fuzzing is a black-box testing scheme where the black-box (Harfbuzz's shaping
+// engine in this case) is fed random input to see if it will misbehave.
+// Misbehaviours can often be turned into security or crash issues.
+//
+// It's expected that one will generally run this under valgrind in order to get
+// better detection of problems.
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#include "../../src/harfbuzz-shaper.h"
+#include "../../src/harfbuzz-global.h"
+#include "../../src/harfbuzz-gpos.h"
+
+extern "C" {
+#include "../../contrib/harfbuzz-unicode.h"
+#include "../../contrib/harfbuzz-freetype.h"
+}
+
+static FT_Library freetype;
+
+static FT_Face loadFace(const char *path)
+{
+ FT_Face face;
+
+ if (FT_New_Face(freetype, path, /* index */ 0, &face))
+ return 0;
+ return face;
+}
+
+static const int kWidth = 100;
+static const int kHeight = 100;
+
+static int
+usage(const char *argv0) {
+ fprintf(stderr, "Usage: %s <TTF file>\n", argv0);
+ return 1;
+}
+
+int
+main(int argc, char **argv) {
+ FT_Init_FreeType(&freetype);
+
+ if (argc != 2)
+ return usage(argv[0]);
+
+ FT_Face face;
+ if (FT_New_Face(freetype, argv[1], 0 /* face index */, &face)) {
+ fprintf(stderr, "Failed to load font file\n");
+ return 1;
+ }
+
+ HB_Face hbFace = HB_NewFace(face, hb_freetype_table_sfnt_get);
+
+ HB_FontRec hbFont;
+ hbFont.klass = &hb_freetype_class;
+ hbFont.userData = face;
+ hbFont.x_ppem = face->size->metrics.x_ppem;
+ hbFont.y_ppem = face->size->metrics.y_ppem;
+ hbFont.x_scale = face->size->metrics.x_scale;
+ hbFont.y_scale = face->size->metrics.y_scale;
+
+ // This is the maximum number of bytes of input which we'll feed to Harfbuzz
+ // in one shot. We also overload it and make it the size of the output arrays
+ // as well. (Must be a power of two.)
+ static const unsigned kMaxInputBytes = 1024;
+ uint8_t str[kMaxInputBytes];
+
+ HB_ShaperItem shaper_item;
+ shaper_item.kerning_applied = false;
+ shaper_item.string = (HB_UChar16 *) str;
+ shaper_item.stringLength = 0;
+ shaper_item.item.bidiLevel = 0;
+ shaper_item.shaperFlags = 0;
+ shaper_item.font = &hbFont;
+ shaper_item.face = hbFace;
+ shaper_item.glyphIndicesPresent = false;
+ shaper_item.initialGlyphCount = 0;
+
+ HB_Glyph out_glyphs[kMaxInputBytes];
+ HB_GlyphAttributes out_attrs[kMaxInputBytes];
+ HB_Fixed out_advs[kMaxInputBytes];
+ HB_FixedPoint out_offsets[kMaxInputBytes];
+ unsigned short out_logClusters[kMaxInputBytes];
+
+ shaper_item.glyphs = out_glyphs;
+ shaper_item.attributes = out_attrs;
+ shaper_item.advances = out_advs;
+ shaper_item.offsets = out_offsets;
+ shaper_item.log_clusters = out_logClusters;
+ shaper_item.num_glyphs = kMaxInputBytes;
+
+ FILE *urandom = fopen("/dev/urandom", "rb");
+ if (!urandom) {
+ fprintf(stderr, "Cannot open /dev/urandom\n");
+ return 1;
+ }
+
+ for (;;) {
+ uint16_t len;
+ fread(&len, sizeof(len), 1, urandom);
+ len &= (kMaxInputBytes - 1);
+ len &= ~1;
+ fread(str, len, 1, urandom);
+
+ ssize_t iterator = 0;
+
+ for (;;) {
+ if (!hb_utf16_script_run_next(NULL, &shaper_item.item, (uint16_t *) str, len >> 1, &iterator))
+ break;
+
+ HB_ShapeItem(&shaper_item);
+ }
+ }
+
+ HB_FreeFace(hbFace);
+}
diff --git a/src/3rdparty/harfbuzz/tests/linebreaking/harfbuzz-qt.cpp b/src/3rdparty/harfbuzz/tests/linebreaking/harfbuzz-qt.cpp
index ea03052..f0048b7 100644
--- a/src/3rdparty/harfbuzz/tests/linebreaking/harfbuzz-qt.cpp
+++ b/src/3rdparty/harfbuzz/tests/linebreaking/harfbuzz-qt.cpp
@@ -79,30 +79,9 @@ void HB_GetGraphemeAndLineBreakClass(HB_UChar32 ch, HB_GraphemeClass *grapheme,
*lineBreak = (HB_LineBreakClass) prop->line_break_class;
}
-void *HB_Library_Resolve(const char *library, const char *symbol)
+void *HB_Library_Resolve(const char *library, int version, const char *symbol)
{
- return QLibrary::resolve(library, symbol);
-}
-
-void *HB_TextCodecForMib(int mib)
-{
- return QTextCodec::codecForMib(mib);
-}
-
-char *HB_TextCodec_ConvertFromUnicode(void *codec, const HB_UChar16 *unicode, hb_uint32 length, hb_uint32 *outputLength)
-{
- QByteArray data = reinterpret_cast<QTextCodec *>(codec)->fromUnicode((const QChar *)unicode, length);
- // ### suboptimal
- char *output = (char *)malloc(data.length() + 1);
- memcpy(output, data.constData(), data.length() + 1);
- if (outputLength)
- *outputLength = data.length();
- return output;
-}
-
-void HB_TextCodec_FreeResult(char *string)
-{
- free(string);
+ return QLibrary::resolve(library, version, symbol);
}
}