From 119b7732cc3ba672d7865bf5640839304164735e Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 9 Jun 2022 16:29:29 +0100 Subject: [PATCH] SVG: strip timestamp to make compressed gzip reproducible we tell GzipFile to write the MTIME field to zero so that the compressed output is reproducible and doesn't change depending on when the data is compressed. --- Lib/fontTools/ttLib/tables/S_V_G_.py | 4 +++- Tests/ttLib/tables/S_V_G__test.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/ttLib/tables/S_V_G_.py b/Lib/fontTools/ttLib/tables/S_V_G_.py index d49afdca0..49e98d034 100644 --- a/Lib/fontTools/ttLib/tables/S_V_G_.py +++ b/Lib/fontTools/ttLib/tables/S_V_G_.py @@ -110,7 +110,9 @@ class table_S_V_G_(DefaultTable.DefaultTable): if (allCompressed or doc.compressed) and not docBytes.startswith(b"\x1f\x8b"): import gzip bytesIO = BytesIO() - with gzip.GzipFile(None, "w", fileobj=bytesIO) as gzipper: + # mtime=0 strips the useless timestamp and makes gzip output reproducible; + # equivalent to `gzip -n` + with gzip.GzipFile(None, "w", fileobj=bytesIO, mtime=0) as gzipper: gzipper.write(docBytes) gzipped = bytesIO.getvalue() if len(gzipped) < len(docBytes): diff --git a/Tests/ttLib/tables/S_V_G__test.py b/Tests/ttLib/tables/S_V_G__test.py index 9a6e33e30..4c40556e2 100644 --- a/Tests/ttLib/tables/S_V_G__test.py +++ b/Tests/ttLib/tables/S_V_G__test.py @@ -16,7 +16,7 @@ def dump(table, ttFont=None): def compress(data: bytes) -> bytes: buf = io.BytesIO() - with gzip.GzipFile(None, "w", fileobj=buf) as gz: + with gzip.GzipFile(None, "w", fileobj=buf, mtime=0) as gz: gz.write(data) return buf.getvalue()