From c44d14ac8965b1b84c89cffc14954c2946ed0bdc Mon Sep 17 00:00:00 2001 From: Nelson Billing Date: Wed, 10 Aug 2022 13:07:29 -0700 Subject: [PATCH] Fix garbage header being prepended to native symbol uploads. Change-Id: I96887504ad9dc47dda6ebc5be7c193a1eb1f94d1 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3825137 Reviewed-by: Zequan Wu --- src/common/windows/http_upload.cc | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/common/windows/http_upload.cc b/src/common/windows/http_upload.cc index af6f8d9c..2d92fba9 100644 --- a/src/common/windows/http_upload.cc +++ b/src/common/windows/http_upload.cc @@ -357,10 +357,10 @@ namespace { return header; } - bool AppendFileToRequestBody( - const wstring& file_part_name, - const wstring& filename, - string* request_body) { + bool AppendFileToRequestBody(const wstring& file_part_name, + const wstring& filename, + string* request_body, + bool set_content_type = true) { string file_part_name_utf8 = WideToUTF8(file_part_name); if (file_part_name_utf8.empty()) { return false; @@ -371,11 +371,17 @@ namespace { return false; } - request_body->append("Content-Disposition: form-data; " - "name=\"" + file_part_name_utf8 + "\"; " - "filename=\"" + filename_utf8 + "\"\r\n"); - request_body->append("Content-Type: application/octet-stream\r\n"); - request_body->append("\r\n"); + if (set_content_type) { + request_body->append( + "Content-Disposition: form-data; " + "name=\"" + + file_part_name_utf8 + + "\"; " + "filename=\"" + + filename_utf8 + "\"\r\n"); + request_body->append("Content-Type: application/octet-stream\r\n"); + request_body->append("\r\n"); + } vector contents; if (!GetFileContents(filename, &contents)) { @@ -432,7 +438,11 @@ namespace google_breakpad { wstring* response_body, int* response_code) { string request_body; - if (!AppendFileToRequestBody(L"symbol_file", path, &request_body)) { + // Turn off content-type in the body. If content-type is set then binary + // files uploaded to GCS end up with the it prepended to the file + // contents. + if (!AppendFileToRequestBody(L"symbol_file", path, &request_body, + /*set_content_type=*/false)) { return false; }