diff --git a/Tests/ttx/data/roundtrip_DSIG_split_at_XML_parse_buffer_size.ttx b/Tests/ttx/data/roundtrip_DSIG_split_at_XML_parse_buffer_size.ttx new file mode 100644 index 000000000..cbab6111d --- /dev/null +++ b/Tests/ttx/data/roundtrip_DSIG_split_at_XML_parse_buffer_size.ttx @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + HelloTestFont + + + TotallyNormal + + + HelloTestFont-TotallyNormal + + + HalloTestFont + + + TotaalNormaal + + + HelloTestFont + + + TotallyNormal + + + HelloTestFont-TotallyNormal + + + HalloTestFont + + + TotaalNormaal + + + + + + + + + + + + + + + + + + + + + + + + + +-----BEGIN PKCS7----- +0000000100000000 +-----END PKCS7----- + + + + diff --git a/Tests/ttx/ttx_test.py b/Tests/ttx/ttx_test.py index d4a27f36b..be009b8aa 100644 --- a/Tests/ttx/ttx_test.py +++ b/Tests/ttx/ttx_test.py @@ -1,7 +1,9 @@ from fontTools.misc.testTools import parseXML from fontTools.misc.timeTools import timestampSinceEpoch from fontTools.ttLib import TTFont, TTLibError +from fontTools.ttLib.tables.DefaultTable import DefaultTable from fontTools import ttx +import base64 import getopt import logging import os @@ -1016,6 +1018,37 @@ def test_main_ttx_compile_stdin_to_stdout(tmp_path): assert outpath.is_file() +def test_roundtrip_DSIG_split_at_XML_parse_buffer_size(tmp_path): + inpath = Path("Tests").joinpath( + "ttx", "data", "roundtrip_DSIG_split_at_XML_parse_buffer_size.ttx" + ) + font = TTFont() + font.importXML(inpath) + font["DMMY"] = DefaultTable(tag="DMMY") + # just enough dummy bytes to hit the cut off point whereby DSIG data gets + # split into two chunks and triggers the bug from + # https://github.com/fonttools/fonttools/issues/2614 + font["DMMY"].data = b"\x01\x02\x03\x04" * 2438 + font.saveXML(tmp_path / "roundtrip_DSIG_split_at_XML_parse_buffer_size.ttx") + + outpath = tmp_path / "font.ttf" + args = [ + sys.executable, + "-m", + "fontTools.ttx", + "-q", + "-o", + str(outpath), + str(tmp_path / "roundtrip_DSIG_split_at_XML_parse_buffer_size.ttx"), + ] + subprocess.run(args, check=True) + + assert outpath.is_file() + assert TTFont(outpath)["DSIG"].signatureRecords[0].pkcs7 == base64.b64decode( + b"0000000100000000" + ) + + # --------------------------- # support functions for tests # ---------------------------