MCPcopy
hub / github.com/tinylib/msgp / TestAllowNilSecurityLimits

Function TestAllowNilSecurityLimits

_generated/limits_test.go:1022–1168  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1020}
1021
1022func TestAllowNilSecurityLimits(t *testing.T) {
1023 // Test that allownil fields still enforce security limits properly
1024
1025 t.Run("AllowNil_BytesExceedLimit_UnmarshalMsg", func(t *testing.T) {
1026 data := AllowNilTestData{}
1027
1028 // Try to send bytes that exceed file limit (100)
1029 buf := msgp.AppendMapHeader(nil, 1)
1030 buf = msgp.AppendString(buf, "nil_slice") // Uses file limit (100)
1031 buf = msgp.AppendBytes(buf, make([]byte, 150)) // Exceeds limit
1032
1033 _, err := data.UnmarshalMsg(buf)
1034 if err != msgp.ErrLimitExceeded {
1035 t.Errorf("Expected ErrLimitExceeded for allownil bytes exceeding limit, got %v", err)
1036 }
1037 })
1038
1039 t.Run("AllowNil_BytesExceedLimit_DecodeMsg", func(t *testing.T) {
1040 data := AllowNilTestData{}
1041
1042 // Try to send bytes that exceed file limit (100)
1043 buf := msgp.AppendMapHeader(nil, 1)
1044 buf = msgp.AppendString(buf, "nil_slice") // Uses file limit (100)
1045 buf = msgp.AppendBytes(buf, make([]byte, 150)) // Exceeds limit
1046
1047 reader := msgp.NewReader(bytes.NewReader(buf))
1048 err := data.DecodeMsg(reader)
1049 if !errors.Is(err, msgp.ErrLimitExceeded) {
1050 t.Errorf("Expected ErrLimitExceeded for allownil bytes exceeding limit, got %v", err)
1051 }
1052 })
1053
1054 t.Run("AllowNil_SliceExceedFieldLimit_UnmarshalMsg", func(t *testing.T) {
1055 data := AllowNilTestData{}
1056
1057 // Try to send slice that exceeds field limit
1058 buf := msgp.AppendMapHeader(nil, 1)
1059 buf = msgp.AppendString(buf, "nil_tight_slice") // Field limit = 5
1060 buf = msgp.AppendArrayHeader(buf, 8) // Exceeds field limit
1061 for i := 0; i < 8; i++ {
1062 buf = msgp.AppendInt(buf, i)
1063 }
1064
1065 _, err := data.UnmarshalMsg(buf)
1066 if err != msgp.ErrLimitExceeded {
1067 t.Errorf("Expected ErrLimitExceeded for allownil slice exceeding field limit, got %v", err)
1068 }
1069 })
1070
1071 t.Run("AllowNil_SliceExceedFieldLimit_DecodeMsg", func(t *testing.T) {
1072 data := AllowNilTestData{}
1073
1074 // Try to send slice that exceeds field limit
1075 buf := msgp.AppendMapHeader(nil, 1)
1076 buf = msgp.AppendString(buf, "nil_tight_slice") // Field limit = 5
1077 buf = msgp.AppendArrayHeader(buf, 8) // Exceeds field limit
1078 for i := 0; i < 8; i++ {
1079 buf = msgp.AppendInt(buf, i)

Callers

nothing calls this directly

Calls 8

AppendMapHeaderFunction · 0.92
AppendStringFunction · 0.92
AppendBytesFunction · 0.92
NewReaderFunction · 0.92
AppendArrayHeaderFunction · 0.92
AppendIntFunction · 0.92
UnmarshalMsgMethod · 0.65
DecodeMsgMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…