Traces: temporary patch to log zlib message on failure

Bug: b/296921272
Change-Id: I0111889dba2f57650caf26a0b86a6669b231f956
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4833616
Reviewed-by: Cody Northrop <cnorthrop@google.com>
Commit-Queue: Roman Lavrov <romanl@google.com>
diff --git a/util/capture/frame_capture_test_utils.cpp b/util/capture/frame_capture_test_utils.cpp
index 63d9923..47b63d1 100644
--- a/util/capture/frame_capture_test_utils.cpp
+++ b/util/capture/frame_capture_test_utils.cpp
@@ -33,6 +33,46 @@
     doc->ParseStream(inWrapper);
     return !doc->HasParseError();
 }
+
+// Branched from:
+// https://crsrc.org/c/third_party/zlib/google/compression_utils_portable.cc;drc=9fc44ce454cc889b603900ccd14b7024ea2c284c;l=167
+// Unmodified other than inlining ZlibStreamWrapperType and z_stream arg to access .msg
+int GzipUncompressHelperPatched(Bytef *dest,
+                                uLongf *dest_length,
+                                const Bytef *source,
+                                uLong source_length,
+                                z_stream &stream)
+{
+    stream.next_in  = static_cast<z_const Bytef *>(const_cast<Bytef *>(source));
+    stream.avail_in = static_cast<uInt>(source_length);
+    if (static_cast<uLong>(stream.avail_in) != source_length)
+        return Z_BUF_ERROR;
+
+    stream.next_out  = dest;
+    stream.avail_out = static_cast<uInt>(*dest_length);
+    if (static_cast<uLong>(stream.avail_out) != *dest_length)
+        return Z_BUF_ERROR;
+
+    stream.zalloc = static_cast<alloc_func>(0);
+    stream.zfree  = static_cast<free_func>(0);
+
+    int err = inflateInit2(&stream, MAX_WBITS + 16);
+    if (err != Z_OK)
+        return err;
+
+    err = inflate(&stream, Z_FINISH);
+    if (err != Z_STREAM_END)
+    {
+        inflateEnd(&stream);
+        if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
+            return Z_DATA_ERROR;
+        return err;
+    }
+    *dest_length = stream.total_out;
+
+    err = inflateEnd(&stream);
+    return err;
+}
 }  // namespace
 
 bool LoadTraceNamesFromJSON(const std::string jsonFilePath, std::vector<std::string> *namesOut)
@@ -222,13 +262,15 @@
 
         mBinaryData.resize(uncompressedSize + 1);  // +1 to make sure .data() is valid
         uLong destLen = uncompressedSize;
+        z_stream stream;
         int zResult =
-            zlib_internal::GzipUncompressHelper(mBinaryData.data(), &destLen, compressedData.data(),
-                                                static_cast<uLong>(compressedData.size()));
+            GzipUncompressHelperPatched(mBinaryData.data(), &destLen, compressedData.data(),
+                                        static_cast<uLong>(compressedData.size()), stream);
 
         if (zResult != Z_OK)
         {
-            std::cerr << "Failure to decompressed binary data: " << zResult << "\n";
+            std::cerr << "Failure to decompressed binary data: " << zResult
+                      << " msg=" << (stream.msg ? stream.msg : "nil") << "\n";
             exit(1);
         }
     }