소스 검색

Don't try to decode when checking clone bundles

This fix exception with python3 with stack-trace:

error: Cannot fetch platform_external_grpc-grpc-java.git (UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 640: invalid start byte)

[...]
  File "[...]project.py", line 2255, in _IsValidBundle
    if f.read(16) == '# v2 git bundle\n':
  File "/usr/lib/python3.5/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)

Even if we ask 16 characters, python buffered decoder will try to decode more in the buffer

The patch works for python2 and python3, and open the file in byte mode so that decoding is not attemped

Signed-off-by: Pierre Tardy <tardyp@gmail.com>
Change-Id: I837ae3c5cd724b34670fc2a84e853431f482b20d
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/224642
Reviewed-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
Pierre Tardy 6 년 전
부모
커밋
2b7daff8cb
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      project.py

+ 2 - 2
project.py

@@ -2261,8 +2261,8 @@ class Project(object):
 
   def _IsValidBundle(self, path, quiet):
     try:
-      with open(path) as f:
-        if f.read(16) == '# v2 git bundle\n':
+      with open(path, 'rb') as f:
+        if f.read(16) == b'# v2 git bundle\n':
           return True
         else:
           if not quiet: