Skip to content

Commit b7c7937

Browse files
committed
add font file check
1 parent b9f62c4 commit b7c7937

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

adafruit_framebuf.py

Lines changed: 4 additions & 0 deletions
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)