From 5d323c17142bc9f3556a578342e06be0412901a4 Mon Sep 17 00:00:00 2001 From: Andrew Chant Date: Mon, 8 Jul 2019 15:53:00 -0700 Subject: [PATCH] Catch unicode decode errors search for kernel ver If a kernel happens to decode to gibberish (including non-ascii bytes), catch the decoding error when searching for the kernel version. Bug: 137041171 Merged-In: Ic035b3a5c8c80025cb3cede7b0fdcf8a2e5a35fd Change-Id: Ic035b3a5c8c80025cb3cede7b0fdcf8a2e5a35fd --- tools/extract_kernel.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/extract_kernel.py b/tools/extract_kernel.py index 16ccb22d47..42561cf0c6 100755 --- a/tools/extract_kernel.py +++ b/tools/extract_kernel.py @@ -47,7 +47,10 @@ def get_version(input_bytes, start_idx): null_idx = input_bytes.find('\x00', start_idx) if null_idx < 0: return None - linux_banner = input_bytes[start_idx:null_idx].decode() + try: + linux_banner = input_bytes[start_idx:null_idx].decode() + except UnicodeDecodeError: + return None mo = re.match(LINUX_BANNER_REGEX, linux_banner) if mo: return mo.group(1)