From de897b45a3b52dcf0bc692a0ca7f7296844ad0a8 Mon Sep 17 00:00:00 2001 From: SET Date: Fri, 14 Aug 2020 18:40:25 -0300 Subject: [PATCH] Made the SCH bitmap parser stronger --- kiplot/kicad/v5_sch.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kiplot/kicad/v5_sch.py b/kiplot/kicad/v5_sch.py index 773b2fa5..2094b294 100644 --- a/kiplot/kicad/v5_sch.py +++ b/kiplot/kicad/v5_sch.py @@ -857,20 +857,20 @@ class SchematicBitmap(object): # Position line = _get_line(f) res = _split_space(line) + if res and res[0] != 'Pos': + raise SchFileError('Missing bitmap position', line) if len(res) != 3: raise SchFileError('Malformed bitmap position', line) - if res[0] != 'Pos': - raise SchFileError('Missing bitmap position', line) bmp = SchematicBitmap() bmp.x = int(res[1]) bmp.y = int(res[2]) # Scale line = _get_line(f) res = _split_space(line) + if res and res[0] != 'Scale': + raise SchFileError('Missing bitmap scale', line) if len(res) != 2: raise SchFileError('Malformed bitmap scale', line) - if res[0] != 'Scale': - raise SchFileError('Missing bitmap scale', line) bmp.scale = float(res[1].replace(',', '.')) # Data line = _get_line(f) @@ -880,7 +880,10 @@ class SchematicBitmap(object): bmp.data = b'' while line != 'EndData': res = _split_space(line) - bmp.data += bytes([int(b, 16) for b in res]) + try: + bmp.data += bytes([int(b, 16) for b in res]) + except ValueError: + raise SchFileError('Malformed bitmap data', line) line = _get_line(f) # End of bitmap line = _get_line(f)