summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorDave Borowitz <dborowitz@google.com>2013-06-03 12:15:23 -0700
committerDave Borowitz <dborowitz@google.com>2013-06-04 00:12:01 +0000
commit91f3ba5a3f6e3c76577b94c0a6c31974d5a3f077 (patch)
treef24f107433374a5ae8264af2dbfbf01b59703dc8 /project.py
parent710d4b03911bc6fc0b313af56e81b957ccae2348 (diff)
downloadgit-repo-91f3ba5a3f6e3c76577b94c0a6c31974d5a3f077.tar.gz
Ensure clone.bundle files have proper header
Server auth middleware may return a 200 from a clone.bundle request that is not a bundle file, but instead a login or access denied page. Instead of just checking the file size, actually check the first few bytes of the file to ensure it is a bundle file before proceeding. Change-Id: Icea07567c568a24fd838e5cf974c58f9e4abd7c0
Diffstat (limited to 'project.py')
-rw-r--r--project.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/project.py b/project.py
index 5a7a6ca8..18e1131d 100644
--- a/project.py
+++ b/project.py
@@ -1804,7 +1804,7 @@ class Project(object):
1804 return False 1804 return False
1805 1805
1806 if os.path.exists(tmpPath): 1806 if os.path.exists(tmpPath):
1807 if curlret == 0 and os.stat(tmpPath).st_size > 16: 1807 if curlret == 0 and self._IsValidBundle(tmpPath):
1808 os.rename(tmpPath, dstPath) 1808 os.rename(tmpPath, dstPath)
1809 return True 1809 return True
1810 else: 1810 else:
@@ -1813,6 +1813,17 @@ class Project(object):
1813 else: 1813 else:
1814 return False 1814 return False
1815 1815
1816 def _IsValidBundle(self, path):
1817 try:
1818 with open(path) as f:
1819 if f.read(16) == '# v2 git bundle\n':
1820 return True
1821 else:
1822 print("Invalid clone.bundle file; ignoring.", file=sys.stderr)
1823 return False
1824 except OSError:
1825 return False
1826
1816 def _Checkout(self, rev, quiet=False): 1827 def _Checkout(self, rev, quiet=False):
1817 cmd = ['checkout'] 1828 cmd = ['checkout']
1818 if quiet: 1829 if quiet: