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

Function TestMapLimitEnforcement

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

Source from the content-addressed store, hash-verified

54}
55
56func TestMapLimitEnforcement(t *testing.T) {
57 data := LimitTestData{}
58
59 // Test map limit with DecodeMsg
60 t.Run("DecodeMsg_MapLimit", func(t *testing.T) {
61 buf := msgp.AppendMapHeader(nil, 1)
62 buf = msgp.AppendString(buf, "small_map")
63 buf = msgp.AppendMapHeader(buf, 60) // Exceeds limit of 50
64
65 reader := msgp.NewReader(bytes.NewReader(buf))
66 err := data.DecodeMsg(reader)
67 if err != msgp.ErrLimitExceeded {
68 t.Errorf("Expected ErrLimitExceeded, got %v", err)
69 }
70 })
71
72 // Test map limit with UnmarshalMsg
73 t.Run("UnmarshalMsg_MapLimit", func(t *testing.T) {
74 buf := msgp.AppendMapHeader(nil, 1)
75 buf = msgp.AppendString(buf, "small_map")
76 buf = msgp.AppendMapHeader(buf, 60) // Exceeds limit of 50
77
78 _, err := data.UnmarshalMsg(buf)
79 if err != msgp.ErrLimitExceeded {
80 t.Errorf("Expected ErrLimitExceeded, got %v", err)
81 }
82 })
83
84 // Test that maps within limit work fine
85 t.Run("MapWithinLimit", func(t *testing.T) {
86 buf := msgp.AppendMapHeader(nil, 1)
87 buf = msgp.AppendString(buf, "small_map")
88 buf = msgp.AppendMapHeader(buf, 3) // Within limit
89 buf = msgp.AppendString(buf, "a")
90 buf = msgp.AppendInt(buf, 1)
91 buf = msgp.AppendString(buf, "b")
92 buf = msgp.AppendInt(buf, 2)
93 buf = msgp.AppendString(buf, "c")
94 buf = msgp.AppendInt(buf, 3)
95
96 _, err := data.UnmarshalMsg(buf)
97 if err != nil {
98 t.Errorf("Unexpected error for map within limit: %v", err)
99 }
100 })
101}
102
103func TestFixedArraysNotLimited(t *testing.T) {
104 // Test that fixed arrays are not subject to limits

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…