Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion rpc/rpc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rpc

import (
"bytes"
"crypto/rand"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -223,7 +224,15 @@ func (args Arguments) MarshalBinary() (data []byte, err error) {
func (args *Arguments) UnmarshalBinary(data []byte) (err error) {
localmap := map[string]interface{}{}

if err = dec.Unmarshal(data, &localmap); err != nil {
// Decode exactly the FIRST CBOR item and ignore any trailing bytes. CheckPack pads
// every payload-0 to its size limit with random trailing bytes, so the packed buffer
// is one CBOR map followed by pad. fxamacker/cbor v2.4.0's Unmarshal tolerates that
// trailing pad, but v2.7+ made Unmarshal return ExtraneousDataError on remaining bytes
// (UnmarshalFirst became the opt-in tolerant API). A version bump past ~v2.7 would make
// dec.Unmarshal here fail on EVERY padded payload-0, silently orphaning all messaging.
// A Decoder reads a single item and stops, so this is tolerant of the pad in EVERY cbor
// version with no dependency pin — the version-agnostic equivalent of UnmarshalFirst.
if err = dec.NewDecoder(bytes.NewReader(data)).Decode(&localmap); err != nil {
return err
}

Expand Down