Always output the wire trace with the injected error format

The fuzzers will be updated to always expect this format. If
the fuzzer doesn't do error injection, it will simply skip
these bytes.

Bug: dawn:629
Change-Id: I894e95ce9c1048eda81593219f7fc5d91e123392
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/40121
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
diff --git a/src/utils/WireHelper.cpp b/src/utils/WireHelper.cpp
index 2bdae6d..846fcc7 100644
--- a/src/utils/WireHelper.cpp
+++ b/src/utils/WireHelper.cpp
@@ -38,7 +38,7 @@
             WireServerTraceLayer(const char* dir, dawn_wire::CommandHandler* handler)
                 : dawn_wire::CommandHandler(), mDir(dir), mHandler(handler) {
                 const char* sep = GetPathSeparator();
-                if (mDir.back() != *sep) {
+                if (mDir.size() > 0 && mDir.back() != *sep) {
                     mDir += sep;
                 }
             }
@@ -56,6 +56,12 @@
                 ASSERT(!mFile.is_open());
                 mFile.open(filename,
                            std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
+
+                // Write the initial 8 bytes. This means the fuzzer should never inject an
+                // error.
+                const uint64_t injectedErrorIndex = 0xFFFF'FFFF'FFFF'FFFF;
+                mFile.write(reinterpret_cast<const char*>(&injectedErrorIndex),
+                            sizeof(injectedErrorIndex));
             }
 
             const volatile char* HandleCommands(const volatile char* commands,