mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
Merge pull request #25436 from smarterclayton/defend_proto
Add a defensive sanity check to protobuf marshal
This commit is contained in:
commit
1616239b4a
@ -16,6 +16,10 @@ limitations under the License.
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ProtobufMarshaller interface {
|
||||
MarshalTo(data []byte) (int, error)
|
||||
}
|
||||
@ -44,6 +48,11 @@ func (m *Unknown) NestedMarshalTo(data []byte, b ProtobufMarshaller, size uint64
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if uint64(n2) != size {
|
||||
// programmer error: the Size() method for protobuf does not match the results of MarshalTo, which means the proto
|
||||
// struct returned would be wrong.
|
||||
return 0, fmt.Errorf("the Size() value of %T was %d, but NestedMarshalTo wrote %d bytes to data", b, size, n2)
|
||||
}
|
||||
i += n2
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user