Repository: vmware/govmomi (go)

Issue:
[BUG] ScsiLun.AlternateName data in vcsim is too large for a signed byte
The ScsiLun alternate name in newer releases (v0.38.0 and newer) of vcsim contains data that doesn't meet the signed byte size. Here is an example of the data:

```xml
<alternateName>
    <namespace>GENERIC_VPD</namespace>
    <namespaceId>5</namespaceId>
    <data>0</data>
    <data>0</data>
    <data>0</data>
    <data>4</data>
    <data>0</data>
    <data>176</data>
    <data>177</data>
    <data>178</data>
</alternateName>
```

Per the [vSphere API](https://[vdc-download.vmware.com/vmwb-repository/dcr-public/c476b64b-c93c-4b21-9d76-be14da0148f9/04ca12ad-59b9-4e1c-8232-fd3d4276e52c/SDK/vsphere-ws/docs/ReferenceGuide/vim.host.ScsiLun.DurableName.html](https://vdc-download.vmware.com/vmwb-repository/dcr-public/c476b64b-c93c-4b21-9d76-be14da0148f9/04ca12ad-59b9-4e1c-8232-fd3d4276e52c/SDK/vsphere-ws/docs/ReferenceGuide/vim.host.ScsiLun.DurableName.html)), this should be an array of `xsd:byte`:
![image](https://github.com/user-attachments/assets/618f95da-d31a-4fd3-a0cf-b5b02d087bd9)

An `xsd:byte` is _called_ a byte, but it is actually a _signed byte_ - between -128 and 127 per the [XSD spec](https://www.w3.org/TR/xmlschema11-2/#byte).

**To Reproduce**
Steps to reproduce the behavior:

1. Launch vcsim using docker on any tag v0.38.0 or newer: `docker run --rm -it -p 8989:8989 vmware/vcsim:v0.38.0`
1. Execute the `WaitForUpdatesEx` SOAP API, as this will return all the inventory, including this malformed data.
1. Inspect the SOAP response, looking for `alternateName` where you'll see the `<data>` fields that contain values that overflow the `xsd:byte` range.

**Expected behavior**
The `<data>` fields in the `alternateName` should fit within the signed byte range of -128 to 127, like this (behavior from v0.37.3):

```xml
<alternateName>
    <namespace>GENERIC_VPD</namespace>
    <namespaceId>5</namespaceId>
    <data>-79</data>
</alternateName>
```


**Affected version**
vcsim:v0.38.0 up until latest v0.46.0

**Additional context**
This worked correctly in older versions of vcsim, up until running with docker using this tag: `vmware/vcsim:v0.38.0`, and I suspect this is related to the fix for #3469.

Pull request description:
fix: vcsim: output signed byte in ByteSlice.MarshalXML
Fixes #3615


Patch:
diff --git a/vim25/types/byte_slice.go b/vim25/types/byte_slice.go
index a19a0bb2..af164400 100644
--- a/vim25/types/byte_slice.go
+++ b/vim25/types/byte_slice.go
@@ -36,7 +36,8 @@ func (b ByteSlice) MarshalXML(e *xml.Encoder, field xml.StartElement) error {
 		Name: field.Name,
 	}
 	for i := range b {
-		if err := e.EncodeElement(b[i], start); err != nil {
+		// Using int8() here to output a signed byte (issue #3615)
+		if err := e.EncodeElement(int8(b[i]), start); err != nil {
 			return err
 		}
 	}


Test patch:
diff --git a/vim25/types/byte_slice_test.go b/vim25/types/byte_slice_test.go
index c0adf19e..22a2761e 100644
--- a/vim25/types/byte_slice_test.go
+++ b/vim25/types/byte_slice_test.go
@@ -43,3 +43,33 @@ func TestByteSlice(t *testing.T) {
 		t.Errorf("out=%#v", out.Byte)
 	}
 }
+
+func TestSignedByteSlice(t *testing.T) {
+	//  int8: <byte>4</byte><byte>-80</byte><byte>-79</byte><byte>-78</byte>
+	// uint8: <byte>4</byte><byte>176</byte><byte>177</byte><byte>178</byte>
+	in := &ArrayOfByte{
+		Byte: []uint8{0x4, 0xb0, 0xb1, 0xb2},
+	}
+
+	res, err := xml.Marshal(in)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	var out struct {
+		Byte []int8 `xml:"byte,omitempty" json:"_value"`
+	}
+
+	// ByteSlice.MarshalXML must output signed byte, otherwise this fails with:
+	// strconv.ParseInt: parsing "176": value out of range
+	if err := xml.Unmarshal(res, &out); err != nil {
+		t.Logf("%s", string(res))
+		t.Fatal(err)
+	}
+
+	for i := range in.Byte {
+		if in.Byte[i] != byte(out.Byte[i]) {
+			t.Errorf("out=%x", out.Byte[i])
+		}
+	}
+}