From: "Fan, ZhijuX" <zhijux.fan@intel.com>
To: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Gao, Liming" <liming.gao@intel.com>,
"Feng, Bob C" <bob.c.feng@intel.com>
Subject: [PATCH] BaseTools:Coding problems caused by special characters
Date: Fri, 29 Mar 2019 05:53:40 +0000 [thread overview]
Message-ID: <FAD0D7E0AE0FA54D987F6E72435CAFD50AF37259@SHSMSX101.ccr.corp.intel.com> (raw)
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1670
During BaseTools compiling under Chinese or Japanese
language Windows, python exception occurring.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbd
in position 3528: ordinal not in range(128)
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
---
BaseTools/Source/C/Makefiles/NmakeSubdirs.py | 2 +-
BaseTools/Source/Python/Capsule/GenerateCapsule.py | 8 ++++----
BaseTools/Source/Python/Common/Misc.py | 2 +-
BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py | 2 +-
.../Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py | 6 +++---
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/BaseTools/Source/C/Makefiles/NmakeSubdirs.py b/BaseTools/Source/C/Makefiles/NmakeSubdirs.py
index 29bb5dfa72..abcbea89a4 100644
--- a/BaseTools/Source/C/Makefiles/NmakeSubdirs.py
+++ b/BaseTools/Source/C/Makefiles/NmakeSubdirs.py
@@ -44,7 +44,7 @@ def RunCommand(WorkDir=None, *Args, **kwargs):
stdout, stderr = p.communicate()
message = ""
if stdout is not None:
- message = stdout.decode() #for compatibility in python 2 and 3
+ message = stdout.decode(encoding='utf-8', errors='ignore') #for compatibility in python 2 and 3
if p.returncode != 0:
raise RuntimeError("Error while execute command \'{0}\' in direcotry {1}\n{2}".format(" ".join(Args), WorkDir, message))
diff --git a/BaseTools/Source/Python/Capsule/GenerateCapsule.py b/BaseTools/Source/Python/Capsule/GenerateCapsule.py
index 7b08918857..5ce5daef68 100644
--- a/BaseTools/Source/Python/Capsule/GenerateCapsule.py
+++ b/BaseTools/Source/Python/Capsule/GenerateCapsule.py
@@ -94,7 +94,7 @@ def SignPayloadSignTool (Payload, ToolPath, PfxFile):
if Process.returncode != 0:
shutil.rmtree (TempDirectoryName)
- print (Result[1].decode())
+ print (Result[1].decode(encoding='utf-8', errors='ignore'))
raise ValueError ('GenerateCapsule: error: signtool failed.')
#
@@ -132,12 +132,12 @@ def SignPayloadOpenSsl (Payload, ToolPath, SignerPrivateCertFile, OtherPublicCer
try:
Process = subprocess.Popen (Command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
Result = Process.communicate(input = Payload)
- Signature = Result[0]
+ Signature = Result[0].decode(encoding='utf-8', errors='ignore')
except:
raise ValueError ('GenerateCapsule: error: can not run openssl.')
if Process.returncode != 0:
- print (Result[1].decode())
+ print (Result[1].decode(encoding='utf-8', errors='ignore'))
raise ValueError ('GenerateCapsule: error: openssl failed.')
return Signature
@@ -186,7 +186,7 @@ def VerifyPayloadOpenSsl (Payload, CertData, ToolPath, SignerPrivateCertFile, Ot
if Process.returncode != 0:
shutil.rmtree (TempDirectoryName)
- print (Result[1].decode())
+ print (Result[1].decode(encoding='utf-8', errors='ignore'))
raise ValueError ('GenerateCapsule: error: openssl failed.')
shutil.rmtree (TempDirectoryName)
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index c7daf5417c..47f8e45222 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1032,7 +1032,7 @@ def ParseFieldValue (Value):
p.stderr.close()
if err:
raise BadExpression("DevicePath: %s" % str(err))
- out = out.decode()
+ out = out.decode(encoding='utf-8', errors='ignore')
Size = len(out.split())
out = ','.join(out.split())
return '{' + out + '}', Size
diff --git a/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py b/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py
index 003f052a90..706bf28e14 100644
--- a/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py
+++ b/BaseTools/Source/Python/Pkcs7Sign/Pkcs7Sign.py
@@ -122,7 +122,7 @@ if __name__ == '__main__':
if Process.returncode != 0:
print('ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH')
sys.exit(Process.returncode)
- print(Version[0].decode())
+ print(Version[0].decode(encoding='utf-8', errors='ignore'))
#
# Read input file into a buffer and save input filename
diff --git a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
index c0b661d03c..3cc14e3bb9 100644
--- a/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
+++ b/BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256GenerateKeys.py
@@ -84,7 +84,7 @@ if __name__ == '__main__':
if Process.returncode != 0:
print('ERROR: Open SSL command not available. Please verify PATH or set OPENSSL_PATH')
sys.exit(Process.returncode)
- print(Version[0].decode())
+ print(Version[0].decode(encoding='utf-8', errors='ignore'))
args.PemFileName = []
@@ -125,7 +125,7 @@ if __name__ == '__main__':
# Extract public key from private key into STDOUT
#
Process = subprocess.Popen('%s rsa -in %s -modulus -noout' % (OpenSslCommand, Item), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
- PublicKeyHexString = Process.communicate()[0].split(b'=')[1].strip()
+ PublicKeyHexString = Process.communicate()[0].decode(encoding='utf-8', errors='ignore').split(b'=')[1].strip()
if Process.returncode != 0:
print('ERROR: Unable to extract public key from private key')
sys.exit(Process.returncode)
@@ -138,7 +138,7 @@ if __name__ == '__main__':
#
Process = subprocess.Popen('%s dgst -sha256 -binary' % (OpenSslCommand), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
Process.stdin.write (PublicKey)
- PublicKeyHash = PublicKeyHash + Process.communicate()[0]
+ PublicKeyHash = PublicKeyHash + Process.communicate()[0].decode(encoding='utf-8', errors='ignore')
if Process.returncode != 0:
print('ERROR: Unable to extract SHA 256 hash of public key')
sys.exit(Process.returncode)
--
2.14.1.windows.1
next reply other threads:[~2019-03-29 5:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-29 5:53 Fan, ZhijuX [this message]
2019-04-01 2:25 ` [PATCH] BaseTools:Coding problems caused by special characters Feng, Bob C
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=FAD0D7E0AE0FA54D987F6E72435CAFD50AF37259@SHSMSX101.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox