From 32e786ad2a18c5e7f30177302bf482b67735a988 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 12 Sep 2017 18:59:21 +0000 Subject: [PATCH] [sancov] coverage-report-server.py: ServerHandler(): open file as UTF8 Summary: This is nessesary in Python3. Everywhere else we assume that encoding is UTF8. If we don't specify it here, the defaults from the environment will be used, which may result in ASCII decoder being used. And if the file is non-ASCII, then it will crash: ``` File "/usr/local/bin/coverage-report-server.py", line 168, in do_GET for line_no, line in enumerate(f, start=1)]) File "/usr/local/bin/coverage-report-server.py", line 165, in ["{line} ".format( File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 106: ordinal not in range(128) ``` Fixes https://bugs.llvm.org/show_bug.cgi?id=33548 Now, how would i add a testcase here? Reviewers: m.ostapenko, kcc Reviewed By: kcc Subscribers: kcc, llvm-commits Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D37661 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313063 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/sancov/coverage-report-server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/sancov/coverage-report-server.py b/tools/sancov/coverage-report-server.py index 428276f95d3..a2e161d0de5 100755 --- a/tools/sancov/coverage-report-server.py +++ b/tools/sancov/coverage-report-server.py @@ -160,7 +160,7 @@ class ServerHandler(http.server.BaseHTTPRequestHandler): linemap = self.symcov_data.compute_linemap(filename) - with open(filepath, 'r') as f: + with open(filepath, 'r', encoding='utf8') as f: content = "\n".join( ["{line} ".format( line=html.escape(line.rstrip()),