From 49aef0cdc87d2a9624eaf916324b9ba845230195 Mon Sep 17 00:00:00 2001 From: Arnar Bjarni Arnarson Date: Thu, 19 Feb 2026 20:30:58 +0000 Subject: [PATCH 1/3] Don't crash on non UTF-8 input files in the modified file checks. --- problemtools/verifyproblem.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/problemtools/verifyproblem.py b/problemtools/verifyproblem.py index ccd09ef8..62263d70 100644 --- a/problemtools/verifyproblem.py +++ b/problemtools/verifyproblem.py @@ -1166,13 +1166,19 @@ def collect_flags(group: TestCaseGroup, flags: set[str]) -> None: def modified_input_validates(applicable, modifier): for testcase in self.problem.testdata.get_all_testcases(): - with open(testcase.infile) as infile: - infile_data = infile.read() - if not applicable(infile_data): + try: + with open(testcase.infile) as infile: + infile_data = infile.read() + if not applicable(infile_data): + continue + except UnicodeDecodeError: continue - with open(file_name, 'wb') as f: - f.write(modifier(infile_data).encode('utf8')) + try: + with open(file_name, 'wb') as f: + f.write(modifier(infile_data).encode('utf8')) + except UnicodeDecodeError: + continue for flags_str in all_flags: flags = flags_str.split() From ae833503f4ef1b794643835af8c0df886a0b9438 Mon Sep 17 00:00:00 2001 From: Arnar Bjarni Arnarson Date: Mon, 2 Mar 2026 11:33:06 +0000 Subject: [PATCH 2/3] Change to UnicodeEncodeError on write --- problemtools/verifyproblem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problemtools/verifyproblem.py b/problemtools/verifyproblem.py index 62263d70..3e416da9 100644 --- a/problemtools/verifyproblem.py +++ b/problemtools/verifyproblem.py @@ -1177,7 +1177,7 @@ def modified_input_validates(applicable, modifier): try: with open(file_name, 'wb') as f: f.write(modifier(infile_data).encode('utf8')) - except UnicodeDecodeError: + except UnicodeEncodeError: continue for flags_str in all_flags: From 156044c6c4d3ce2edc4540d96e8832a03bf51b8c Mon Sep 17 00:00:00 2001 From: Arnar Bjarni Arnarson Date: Mon, 2 Mar 2026 12:38:57 +0000 Subject: [PATCH 3/3] Remove second try/except --- problemtools/verifyproblem.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/problemtools/verifyproblem.py b/problemtools/verifyproblem.py index 3e416da9..f2e91304 100644 --- a/problemtools/verifyproblem.py +++ b/problemtools/verifyproblem.py @@ -1174,11 +1174,8 @@ def modified_input_validates(applicable, modifier): except UnicodeDecodeError: continue - try: - with open(file_name, 'wb') as f: - f.write(modifier(infile_data).encode('utf8')) - except UnicodeEncodeError: - continue + with open(file_name, 'wb') as f: + f.write(modifier(infile_data).encode('utf8')) for flags_str in all_flags: flags = flags_str.split()