2
0
mirror of https://opendev.org/x/pyghmi synced 2026-01-10 18:22:32 +00:00

Correct issue with multiple uploads of same file to distinct targets

The boundary randomization code failed to account for potential sharing,
producing a mismatch of headers and data.

Change-Id: I74de90b86edf6edd9a20ce07f7d277de75022413
This commit is contained in:
Jarrod Johnson
2025-08-15 15:32:49 -04:00
parent 131d71d788
commit 99af22b694

View File

@@ -98,6 +98,8 @@ class FileDownloader(threading.Thread):
def get_upload_form(filename, data, formname, otherfields, boundary=BND):
if not boundary:
boundary = base64.b64encode(os.urandom(54))[:70]
ffilename = filename.split('/')[-1]
if not formname:
formname = ffilename
@@ -125,8 +127,8 @@ def get_upload_form(filename, data, formname, otherfields, boundary=BND):
formname, ffilename).encode('utf-8'))
form += b'Content-Type: application/octet-stream\r\n\r\n' + data
form += b'\r\n--' + boundary + b'--\r\n'
uploadforms[filename] = form
return form
uploadforms[filename] = form, boundary
return uploadforms[filename]
class SecureHTTPConnection(httplib.HTTPConnection, object):
@@ -334,16 +336,16 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
the file.
:return:
"""
boundary = base64.b64encode(os.urandom(54))[:70]
if data is None:
data = open(filename, 'rb')
ulhdrs = self.stdheaders.copy()
if formwrap:
self._upbuffer = io.BytesIO(get_upload_form(
filename, data, formname, otherfields, boundary))
ulhdrs['Content-Type'] = b'multipart/form-data; boundary=' + boundary
ulhdrs['Content-Length'] = len(uploadforms[filename])
self.ulsize = len(uploadforms[filename])
guf = get_upload_form(
filename, data, formname, otherfields, boundary=None)
self._upbuffer = io.BytesIO(guf[0])
ulhdrs['Content-Type'] = b'multipart/form-data; boundary=' + guf[1]
ulhdrs['Content-Length'] = len(uploadforms[filename][0])
self.ulsize = len(uploadforms[filename][0])
else:
canseek = True
try: