From 6d08991cae2872adc529517eaedec3943852c52b Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Wed, 28 Jun 2023 13:48:55 +0900 Subject: [PATCH] vndk snapshot update: read txt file with utf-8 encoding VNDK snapshot updater reads license text files. To avoid unexpected text files to be read, explicitly set the encoding type and ignore if failed to read. Bug: 288846788 Test: add binary to read and see if it is ignored Change-Id: I7e3d0bbdc6c692ef7dbc6d8bf9d53c67003d0f90 --- vndk/snapshot/collect_licenses.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vndk/snapshot/collect_licenses.py b/vndk/snapshot/collect_licenses.py index f8b0ef29f..5a4a5b1a9 100644 --- a/vndk/snapshot/collect_licenses.py +++ b/vndk/snapshot/collect_licenses.py @@ -82,9 +82,13 @@ class LicenseCollector(object): def check_licenses(self, filepath): """ Read a license text file and find the license_kinds. """ - with open(filepath, 'r') as file_to_check: - file_string = file_to_check.read() - self.read_and_check_licenses(file_string, LICENSE_KEYWORDS) + with open(filepath, 'rt', encoding='utf-8') as file_to_check: + try: + file_string = file_to_check.read() + self.read_and_check_licenses(file_string, LICENSE_KEYWORDS) + except UnicodeDecodeError: + # Read text files only. + return def run(self, module=''): """ search licenses in vndk snapshots