From 5951e3043f8d9567bfcd6e0f328ae057e1dfad11 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 20 May 2022 23:34:44 -0400 Subject: [PATCH] sync: handle smartsync HTML responses better If the server responds with an HTML page, we should show that to the user instead of crashing with XML errors. Bug: https://crbug.com/gerrit/15936 Change-Id: I52e6b781c3bb6a6c9f6ecbe2e0907044876cdc8d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/337519 Reviewed-by: Raman Tenneti Tested-by: Mike Frysinger --- subcmds/sync.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/subcmds/sync.py b/subcmds/sync.py index 507d1c94..a2b376bc 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -28,6 +28,7 @@ import time import urllib.error import urllib.parse import urllib.request +import xml.parsers.expat import xmlrpc.client try: @@ -1431,11 +1432,16 @@ class PersistentTransport(xmlrpc.client.Transport): raise p, u = xmlrpc.client.getparser() - while 1: - data = response.read(1024) - if not data: - break + # Response should be fairly small, so read it all at once. + # This way we can show it to the user in case of error (e.g. HTML). + data = response.read() + try: p.feed(data) + except xml.parsers.expat.ExpatError as e: + raise IOError( + f'Parsing the manifest failed: {e}\n' + f'Please report this to your manifest server admin.\n' + f'Here is the full response:\n{data.decode("utf-8")}') p.close() return u.close()