From 8a4236fe6b3cf6e6c0fc649054c9180c4146775e Mon Sep 17 00:00:00 2001 From: caternuson Date: Sat, 2 Nov 2019 22:02:17 -0700 Subject: [PATCH] catch small int overflow --- adafruit_framebuf.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 9fbad45..ba1115b 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -396,13 +396,17 @@ def __init__(self, font_name='font5x8.bin'): # Note that only fonts up to 8 pixels tall are currently supported. try: self._font = open(self.font_name, 'rb') + 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) except OSError: 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) + except OverflowError: + # os.stat can throw this on boards without long int support + # just hope the font file is valid and press on + pass def deinit(self): """Close the font file as cleanup."""