internal/pipewire: check for trailing garbage
All checks were successful
Test / Create distribution (push) Successful in 36s
Test / Sandbox (push) Successful in 2m14s
Test / Hakurei (push) Successful in 3m18s
Test / Hpkg (push) Successful in 4m8s
Test / Sandbox (race detector) (push) Successful in 4m20s
Test / Hakurei (race detector) (push) Successful in 5m9s
Test / Flake checks (push) Successful in 1m28s
All checks were successful
Test / Create distribution (push) Successful in 36s
Test / Sandbox (push) Successful in 2m14s
Test / Hakurei (push) Successful in 3m18s
Test / Hpkg (push) Successful in 4m8s
Test / Sandbox (race detector) (push) Successful in 4m20s
Test / Hakurei (race detector) (push) Successful in 5m9s
Test / Flake checks (push) Successful in 1m28s
This is useful during development. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
5bcafcf734
commit
d92de1c709
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user