From b7c793787afaf6f355cf55a4dd5b1e48fc0656ca Mon Sep 17 00:00:00 2001 From: Carter Nelson Date: Tue, 13 Aug 2019 23:20:47 +0100 Subject: [PATCH] add font file check --- adafruit_framebuf.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 33ba50a..e6e0a78 100644 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -44,6 +44,7 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_framebuf.git" +import os import struct # Framebuf format constants: @@ -364,6 +365,9 @@ def __init__(self, font_name='font5x8.bin'): print("Could not find font file", font_name) raise self.font_width, self.font_height = struct.unpack('BB', self._font.read(2)) + # simple font file validation check based on expected file size + if 2 + 256 * self.font_width != os.stat(font_name)[6]: + raise RuntimeError("Invalid font file: " + font_name) def deinit(self): """Close the font file as cleanup."""