Skip logging on Win official builds

Skips logging in sandboxed processes on Windows
official builds since the file handles will not
be set properly, causing crashes when we try to
write to stdout/stderr.

Bug: chromium:1429665
Change-Id: Ie70d0cc2e096bd22490dc3538467752b448f213b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127205
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Brian Sheedy <bsheedy@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@google.com>
diff --git a/src/dawn/common/Log.cpp b/src/dawn/common/Log.cpp
index 265d156..c7a180b 100644
--- a/src/dawn/common/Log.cpp
+++ b/src/dawn/common/Log.cpp
@@ -23,6 +23,9 @@
 #if DAWN_PLATFORM_IS(ANDROID)
 #include <android/log.h>
 #endif
+#if DAWN_PLATFORM_IS(WINDOWS)
+#include <windows.h>
+#endif
 
 namespace dawn {
 
@@ -99,6 +102,20 @@
         outputStream = stderr;
     }
 
+#if DAWN_PLATFORM_IS(WINDOWS) && defined(OFFICIAL_BUILD)
+    // If we are in a sandboxed process on an official build, the stdout/stderr
+    // handles are likely not set, so trying to log to them will crash.
+    HANDLE handle;
+    if (outputStream == stderr) {
+        handle = GetStdHandle(STD_ERROR_HANDLE);
+    } else {
+        handle = GetStdHandle(STD_OUTPUT_HANDLE);
+    }
+    if (handle == INVALID_HANDLE_VALUE) {
+        return;
+    }
+#endif  // DAWN_PLATFORM_IS(WINDOWS) && defined(OFFICIAL_BUILD)
+
     // Note: we use fprintf because <iostream> includes static initializers.
     fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str());
     fflush(outputStream);