aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-11-25 01:59:29 +0900
committerOphestra <cat@gensokyo.uk>2025-11-25 01:59:29 +0900
commitd92de1c70977308c5d9a5c5be325f1b27be2c2f4 (patch)
tree6f6b3752180dab543fca6baf40239c85edabf792
parent5bcafcf73421cfdd8c80a0a0daec9ac09d8784e2 (diff)
internal/pipewire: check for trailing garbage
This is useful during development. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--internal/pipewire/pod.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/pipewire/pod.go b/internal/pipewire/pod.go
index e81d81bc..ff82c72f 100644
--- a/internal/pipewire/pod.go
+++ b/internal/pipewire/pod.go
@@ -172,6 +172,17 @@ type UnmarshalSetError struct{ Type reflect.Type }
func (u *UnmarshalSetError) Error() string { return "cannot set: " + u.Type.String() }
+// A TrailingGarbageError describes extra bytes after decoding
+// has completed during [Unmarshal].
+type TrailingGarbageError struct{ Data []byte }
+
+func (e *TrailingGarbageError) Error() string {
+ if len(e.Data) < 8 {
+ return "got " + strconv.Itoa(len(e.Data)) + " bytes of trailing garbage"
+ }
+ return "data has extra values starting with type " + strconv.Itoa(int(binary.NativeEndian.Uint32(e.Data[4:])))
+}
+
// unmarshalValue implements [Unmarshal] on [reflect.Value].
func unmarshalValue(data []byte, v reflect.Value, sizeP *Word) error {
switch v.Kind() {
@@ -201,6 +212,10 @@ func unmarshalValue(data []byte, v reflect.Value, sizeP *Word) error {
// already bounds checked by the successful unmarshalValue call
data = data[8+fieldWireSize+paddingSize:]
}
+
+ if len(data) != 0 {
+ return &TrailingGarbageError{data}
+ }
return nil
case reflect.Pointer: