[spirv] Guard against instruction length overflow

This assertion prevents instruction word length overflow from being a
potential security issue due to invalid SPIR-V being generated, and
instead makes it a GPU process crash.

Bug: 366067963
Change-Id: Ieb1186361f6e9129eba62b0109cce7d8f767ea01
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/206717
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/spirv/writer/common/binary_writer.cc b/src/tint/lang/spirv/writer/common/binary_writer.cc
index 921751a..56bd5a7 100644
--- a/src/tint/lang/spirv/writer/common/binary_writer.cc
+++ b/src/tint/lang/spirv/writer/common/binary_writer.cc
@@ -59,6 +59,7 @@
 }
 
 void BinaryWriter::ProcessInstruction(const Instruction& inst) {
+    TINT_ASSERT(inst.WordLength() < 65536);
     out_.push_back(inst.WordLength() << 16 | static_cast<uint32_t>(inst.Opcode()));
     for (const auto& op : inst.Operands()) {
         ProcessOp(op);