Skip to content

Commit 8d7f44c

Browse files
authored
Merge pull request #19 from caternuson/iss18
Add font file check
2 parents b9f62c4 + b7c7937 commit 8d7f44c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

adafruit_framebuf.py

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
__version__ = "0.0.0-auto.0"
4545
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_framebuf.git"
4646

47+
import os
4748
import struct
4849

4950
# Framebuf format constants:
@@ -364,6 +365,9 @@ def __init__(self, font_name='font5x8.bin'):
364365
print("Could not find font file", font_name)
365366
raise
366367
self.font_width, self.font_height = struct.unpack('BB', self._font.read(2))
368+
# simple font file validation check based on expected file size
369+
if 2 + 256 * self.font_width != os.stat(font_name)[6]:
370+
raise RuntimeError("Invalid font file: " + font_name)
367371

368372
def deinit(self):
369373
"""Close the font file as cleanup."""

0 commit comments

Comments
 (0)