From 1f14ef7747c2eade2eae3ef2f0486036037b08bf Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 5 Jan 2022 16:18:59 +0700 Subject: [PATCH] Fix infinite loop when handling utf-8 --- judge/utils/problem_data.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/judge/utils/problem_data.py b/judge/utils/problem_data.py index e22aa4f..b0a187b 100644 --- a/judge/utils/problem_data.py +++ b/judge/utils/problem_data.py @@ -286,7 +286,11 @@ def get_problem_case(problem, files): s.decode('utf-8') break except UnicodeDecodeError: - s += f.read(1) + next_char = f.read(1) + if next_char: + s += next_char + else: + raise Exception('File %s is not able to decode in utf-8' % file) qs = get_visible_content(s) cache.set(cache_key, qs, 86400) result[file] = qs