summaryrefslogtreecommitdiff
path: root/Build/source/texk/ttfdump
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2013-02-01 13:07:58 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2013-02-01 13:07:58 +0000
commit31793f77341a0ab4435e13e3f735abcb862efcab (patch)
tree63352268c973f7e51fdb709c957d48678e91b85d /Build/source/texk/ttfdump
parent5d3082c811927189b42951f761e383839579b304 (diff)
ttfdump: Avoid segfault for invalid OS/2 PANOSE data
git-svn-id: svn://tug.org/texlive/trunk@29002 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/ttfdump')
-rw-r--r--Build/source/texk/ttfdump/ChangeLog8
-rw-r--r--Build/source/texk/ttfdump/Makefile.am5
-rw-r--r--Build/source/texk/ttfdump/Makefile.in8
-rw-r--r--Build/source/texk/ttfdump/libttf/os2.c31
-rw-r--r--Build/source/texk/ttfdump/tests/bad.otfbin0 -> 1884 bytes
-rw-r--r--Build/source/texk/ttfdump/tests/ttfdump.bad69
-rwxr-xr-xBuild/source/texk/ttfdump/tests/ttfdump.test10
7 files changed, 112 insertions, 19 deletions
diff --git a/Build/source/texk/ttfdump/ChangeLog b/Build/source/texk/ttfdump/ChangeLog
index 190210a0890..a22ca6ba713 100644
--- a/Build/source/texk/ttfdump/ChangeLog
+++ b/Build/source/texk/ttfdump/ChangeLog
@@ -1,3 +1,11 @@
+2013-02-01 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ * libttf/os2.c: Index checking for string array elements.
+ * tests/ttfdump.test: Add a test case for invalid array indices.
+ * tests/bad.otf (new): Additional test input.
+ * tests/ttfdump.bad (new): Expected output..
+ * Makefile.am: Adapted.
+
2013-01-31 Akihiro Sagawa <sagawa.aki@gmail.com>
* include/os2_P.h: Added missing commas to fix an ancient bug.
diff --git a/Build/source/texk/ttfdump/Makefile.am b/Build/source/texk/ttfdump/Makefile.am
index 5c050992c36..99cd12e6a6b 100644
--- a/Build/source/texk/ttfdump/Makefile.am
+++ b/Build/source/texk/ttfdump/Makefile.am
@@ -1,6 +1,6 @@
## Makefile.am for the TeX Live subdirectory texk/ttfdump/
##
-## Copyright (C) 2009-2012 Peter Breitenlohner <tex-live@tug.org>
+## Copyright (C) 2009-2013 Peter Breitenlohner <tex-live@tug.org>
## You may freely use, modify and/or distribute this file.
##
ACLOCAL_AMFLAGS = -I ../../m4
@@ -92,7 +92,9 @@ DISTCLEANFILES =
## tests/ttfdump.test
EXTRA_DIST += \
tests/FonetikaDaniaIwonaeRegular.ttf \
+ tests/bad.otf \
tests/texmfhome.otf \
+ tests/ttfdump.bad \
tests/ttfdump.glyf \
tests/ttfdump.gpos \
tests/ttfdump.gsub \
@@ -101,6 +103,7 @@ EXTRA_DIST += \
DISTCLEANFILES += \
FonetikaDaniaIwonaeRegular.ttf \
texmfhome.otf \
+ bad.otf \
ttftest.*
## Not used
diff --git a/Build/source/texk/ttfdump/Makefile.in b/Build/source/texk/ttfdump/Makefile.in
index 6d49739e6ad..1ee12c4e7a8 100644
--- a/Build/source/texk/ttfdump/Makefile.in
+++ b/Build/source/texk/ttfdump/Makefile.in
@@ -579,14 +579,14 @@ libttf_a_SOURCES = \
EXTRA_DIST = include/stack.h libttf/fixed.c libttf/interp.c \
libttf/stack.c docs/ttfdump.dvi docs/ttfdump.html \
docs/ttfdump.ps $(TESTS) tests/FonetikaDaniaIwonaeRegular.ttf \
- tests/texmfhome.otf tests/ttfdump.glyf tests/ttfdump.gpos \
- tests/ttfdump.gsub tests/ttfdump.head tests/ttfdump.os_2 ILX \
- NOTE README.bg5
+ tests/bad.otf tests/texmfhome.otf tests/ttfdump.bad \
+ tests/ttfdump.glyf tests/ttfdump.gpos tests/ttfdump.gsub \
+ tests/ttfdump.head tests/ttfdump.os_2 ILX NOTE README.bg5
ttfdump_SOURCES = src/ttfdump.c
LDADD = libttf.a $(KPATHSEA_LIBS)
dist_man1_MANS = docs/ttfdump.1
TESTS = tests/ttfdump.test
-DISTCLEANFILES = FonetikaDaniaIwonaeRegular.ttf texmfhome.otf \
+DISTCLEANFILES = FonetikaDaniaIwonaeRegular.ttf texmfhome.otf bad.otf \
ttftest.*
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-am
diff --git a/Build/source/texk/ttfdump/libttf/os2.c b/Build/source/texk/ttfdump/libttf/os2.c
index ab5c95235f6..e78e75811da 100644
--- a/Build/source/texk/ttfdump/libttf/os2.c
+++ b/Build/source/texk/ttfdump/libttf/os2.c
@@ -82,6 +82,13 @@ static void ttfLoadOS2(FILE *fp, OS_2Ptr os2, ULONG offset)
os2->usMaxContext = ttfGetUSHORT(fp);
}
+/* Index checking for string array elements. */
+#define StrFromInd(str, ind) StringFromIndex(str, sizeof(str) / sizeof(str[0]), (int)ind)
+static inline const char *StringFromIndex(const char **str, size_t sz, int ind)
+{
+ return ind >= 0 && ind < sz ? str[ind] : "invalid";
+}
+
void ttfPrintOS2(FILE *fp,OS_2Ptr os2)
{
char buf[80];
@@ -92,9 +99,9 @@ void ttfPrintOS2(FILE *fp,OS_2Ptr os2)
fprintf(fp,"\t 'OS/2' version:\t %d\n",os2->version);
fprintf(fp,"\t xAvgCharWidth:\t\t %d\n",os2->xAvgCharWidth);
fprintf(fp,"\t usWeightClass:\t\t %d \t '%s'\n",os2->usWeightClass,
- WeightClassName[os2->usWeightClass/100 - 1] );
+ StrFromInd(WeightClassName,os2->usWeightClass/100 - 1));
fprintf(fp,"\t usWidthClass:\t\t %d \t '%s'\n",os2->usWidthClass,
- WidthClassName[os2->usWidthClass - 1]);
+ StrFromInd(WidthClassName,os2->usWidthClass - 1));
fprintf(fp,"\t fsType:\t\t %d\n",os2->fsType);
fprintf(fp,"\t ySubscriptXSize:\t %d\n",os2->ySubscriptXSize);
fprintf(fp,"\t ySubscriptYSize:\t %d\n",os2->ySubscriptYSize);
@@ -110,25 +117,25 @@ void ttfPrintOS2(FILE *fp,OS_2Ptr os2)
(os2->sFamilyClass) >> 8,(os2->sFamilyClass) & 0x00ff);
fprintf(fp,"\t PANOSE:\n");
fprintf(fp,"\t\t Family Kind:\t %d \t '%s'\n",os2->panose[0],
- PanoseFamily[os2->panose[0]]);
+ StrFromInd(PanoseFamily,os2->panose[0]));
fprintf(fp,"\t\t Serif Style:\t %d \t '%s'\n",os2->panose[1],
- PanoseSerif[os2->panose[1]]);
+ StrFromInd(PanoseSerif,os2->panose[1]));
fprintf(fp,"\t\t Weight:\t %d \t '%s'\n",os2->panose[2],
- PanoseWeight[os2->panose[2]]);
+ StrFromInd(PanoseWeight,os2->panose[2]));
fprintf(fp,"\t\t Proportion:\t %d \t '%s'\n",os2->panose[3],
- PanoseProportion[os2->panose[3]]);
+ StrFromInd(PanoseProportion,os2->panose[3]));
fprintf(fp,"\t\t Contrast:\t %d \t '%s'\n",os2->panose[4],
- PanoseContrast[os2->panose[4]]);
+ StrFromInd(PanoseContrast,os2->panose[4]));
fprintf(fp,"\t\t Stroke:\t %d \t '%s'\n",os2->panose[5],
- PanoseStroke[os2->panose[5]]);
+ StrFromInd(PanoseStroke,os2->panose[5]));
fprintf(fp,"\t\t Arm Style:\t %d \t '%s'\n",os2->panose[6],
- PanoseArm[os2->panose[6]]);
+ StrFromInd(PanoseArm,os2->panose[6]));
fprintf(fp,"\t\t Lettreform:\t %d \t '%s'\n",os2->panose[7],
- PanoseLetterform[os2->panose[7]]);
+ StrFromInd(PanoseLetterform,os2->panose[7]));
fprintf(fp,"\t\t Midline:\t %d \t '%s'\n",os2->panose[8],
- PanoseMidline[os2->panose[8]]);
+ StrFromInd(PanoseMidline,os2->panose[8]));
fprintf(fp,"\t\t X-height:\t %d \t '%s'\n",os2->panose[9],
- PanoseXHeight[os2->panose[9]]);
+ StrFromInd(PanoseXHeight,os2->panose[9]));
fprintf(fp,"\t Unicode Range 1( Bits 0 - 31 ): \t 0x%08x\n",
os2->ulUnicodeRange1);
fprintf(fp,"\t Unicode Range 2( Bits 32 - 63 ): \t 0x%08x\n",
diff --git a/Build/source/texk/ttfdump/tests/bad.otf b/Build/source/texk/ttfdump/tests/bad.otf
new file mode 100644
index 00000000000..cf95977a7ab
--- /dev/null
+++ b/Build/source/texk/ttfdump/tests/bad.otf
Binary files differ
diff --git a/Build/source/texk/ttfdump/tests/ttfdump.bad b/Build/source/texk/ttfdump/tests/ttfdump.bad
new file mode 100644
index 00000000000..e6394f3e2ca
--- /dev/null
+++ b/Build/source/texk/ttfdump/tests/ttfdump.bad
@@ -0,0 +1,69 @@
+True Type Font File Dumper: v 0.5.5
+Copyright 1996-1998 ollie@ms1.hinet.net
+Dumping File:bad.otf
+
+
+Offset Table
+------------
+ sfnt version: 'OTTO'
+ number of tables: 10
+ 0. 'CFF ' - checksum = 0xedbe4dbb, offset = 0x00000540, len = 499
+ 1. 'FFTM' - checksum = 0x5648ee58, offset = 0x00000734, len = 28
+ 2. 'OS/2' - checksum = 0x55da5fc2, offset = 0x00000110, len = 96
+ 3. 'cmap' - checksum = 0x000d03f5, offset = 0x000003dc, len = 322
+ 4. 'head' - checksum = 0xf1a97fe4, offset = 0x000000ac, len = 54
+ 5. 'hhea' - checksum = 0x04b90210, offset = 0x000000e4, len = 36
+ 6. 'hmtx' - checksum = 0x042b0020, offset = 0x00000750, len = 10
+ 7. 'maxp' - checksum = 0x00035000, offset = 0x00000108, len = 6
+ 8. 'name' - checksum = 0x4777499b, offset = 0x00000170, len = 618
+ 9. 'post' - checksum = 0xff860033, offset = 0x00000520, len = 32
+
+'OS/2' Table - OS/2 and Windows Metrics
+---------------------------------------
+ 'OS/2' version: 3
+ xAvgCharWidth: 525
+ usWeightClass: 500 'Medium'
+ usWidthClass: 5 'Medium'
+ fsType: 0
+ ySubscriptXSize: 650
+ ySubscriptYSize: 699
+ ySubscriptXOffset: 0
+ ySubscriptYOffset: 140
+ ySuperscriptXSize: 650
+ ySuperscriptYSize: 699
+ ySuperscriptXOffset: 0
+ ySuperscriptYOffset: 479
+ yStrikeoutSize: 49
+ yStrikeoutPosition 258
+ sFamilyClass: 0 subclass = 0
+ PANOSE:
+ Family Kind: 6 'invalid'
+ Serif Style: -1 'invalid'
+ Weight: 6 'Medium'
+ Proportion: 9 'Monospaced'
+ Contrast: 0 'Any'
+ Stroke: 0 'Any'
+ Arm Style: 0 'Any'
+ Lettreform: 0 'Any'
+ Midline: 0 'Any'
+ X-height: 0 'Any'
+ Unicode Range 1( Bits 0 - 31 ): 0x00000001
+ Unicode Range 2( Bits 32 - 63 ): 0x00000000
+ Unicode Range 3( Bits 64 - 95 ): 0x00000000
+ Unicode Range 4( Bits 96 - 128 ): 0x00000000
+ achVendID: 'PfEd'
+ fsSelection: 0x0040 'Regular '
+ usFirstCharIndex: 0xffff
+ usLastCharIndex: 0x0000
+ sTypoAscender: 800
+ sTypoDescender: -200
+ sTypoLineGap: 90
+ usWinAscent: 611
+ usWinDescent: 0
+ CodePage Range 1( Bits 0 - 31 ): 0x00000001
+ CodePage Range 2( Bits 32- 63 ): 0x00000000
+ sxHeight: 0
+ sCapHeight: 0
+ usDefaultChar: 0x0020
+ usBreakChar: 0x0020
+ usMaxContext: 1
diff --git a/Build/source/texk/ttfdump/tests/ttfdump.test b/Build/source/texk/ttfdump/tests/ttfdump.test
index 4e5c5fb77cb..7592eaea5b0 100755
--- a/Build/source/texk/ttfdump/tests/ttfdump.test
+++ b/Build/source/texk/ttfdump/tests/ttfdump.test
@@ -1,6 +1,6 @@
#! /bin/sh
-# Copyright (C) 2011, 2012 Peter Breitenlohner <tex-live@tug.org>
+# Copyright (C) 2011-2013 Peter Breitenlohner <tex-live@tug.org>
# You may freely use, modify and/or distribute this file.
TEXMFCNF=$srcdir/../kpathsea
@@ -9,9 +9,10 @@ export TEXMFCNF TTFONTS
failed=
-rm -rf FonetikaDaniaIwonaeRegular.ttf texmfhome.otf ttftest.*
+rm -rf FonetikaDaniaIwonaeRegular.ttf texmfhome.otf ttftest.* bad.*
cp $srcdir/tests/FonetikaDaniaIwonaeRegular.ttf .
cp $srcdir/tests/texmfhome.otf .
+cp $srcdir/tests/bad.otf .
./ttfdump -t glyf -g 1 -o ttftest.glyf FonetikaDaniaIwonaeRegular.ttf \
&& diff -b $srcdir/tests/ttfdump.glyf ttftest.glyf \
@@ -38,6 +39,11 @@ cp $srcdir/tests/texmfhome.otf .
&& echo "ttfdump.os_2 tests OK" \
|| failed="$failed ttfdump.os_2"
+./ttfdump -t OS/2 bad.otf >ttftest.bad \
+ && diff -b $srcdir/tests/ttfdump.bad ttftest.bad \
+ && echo "ttfdump.bad tests OK" \
+ || failed="$failed ttfdump.bad"
+
test -z "$failed" && exit 0
echo "failed tests:$failed"
exit 1