[fidl][go] Fix for case of too few handles

This fixes failures in OptionalXUnionInStructPresentInvalidNumHandles
in Ic5b2a8b9642b2a5519d97d02ad6a3f92a343e2a9 due to a handle being
read when no handles are specified.

In this fix, the unmarshaler defers validating the number of handles
to the inner decoder. This keeps the same ordering of errors as
before and avoids multiple checks for the same error.

Bug: 81180
Change-Id: Ia605140fe3d805ea2f57d325735b422d7493a848
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/go/+/558481
Reviewed-by: Mitchell Kember <mkember@google.com>
Commit-Queue: Benjamin Prosnitz <bprosnitz@google.com>
diff --git a/src/syscall/zx/fidl/encoding_new.go b/src/syscall/zx/fidl/encoding_new.go
index 5e84f32..3834b89 100644
--- a/src/syscall/zx/fidl/encoding_new.go
+++ b/src/syscall/zx/fidl/encoding_new.go
@@ -1424,8 +1424,10 @@
 			if header.handleCount != 1 {
 				return false, newValueError(ErrInvalidNumHandlesInEnvelope, header.handleCount)
 			}
-			innerDecoderHandleInfos = []zx.HandleInfo{in.handleInfos[0]}
-			in.handleInfos = in.handleInfos[1:]
+			if len(in.handleInfos) > 0 {
+				innerDecoderHandleInfos = []zx.HandleInfo{in.handleInfos[0]}
+				in.handleInfos = in.handleInfos[1:]
+			}
 		}
 		d := decoder{
 			buffer:      header.byteValue,