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

Function TestSliceLimitEnforcement

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

Source from the content-addressed store, hash-verified

10)
11
12func TestSliceLimitEnforcement(t *testing.T) {
13 data := UnlimitedData{}
14
15 // Test slice limit with DecodeMsg (using big_slice which is []string)
16 t.Run("DecodeMsg_SliceLimit", func(t *testing.T) {
17 buf := msgp.AppendMapHeader(nil, 1)
18 buf = msgp.AppendString(buf, "big_slice")
19 buf = msgp.AppendArrayHeader(buf, 150) // Exceeds limit of 100
20
21 reader := msgp.NewReader(bytes.NewReader(buf))
22 err := data.DecodeMsg(reader)
23 if err != msgp.ErrLimitExceeded {
24 t.Errorf("Expected ErrLimitExceeded, got %v", err)
25 }
26 })
27
28 // Test slice limit with UnmarshalMsg
29 t.Run("UnmarshalMsg_SliceLimit", func(t *testing.T) {
30 buf := msgp.AppendMapHeader(nil, 1)
31 buf = msgp.AppendString(buf, "big_slice")
32 buf = msgp.AppendArrayHeader(buf, 150) // Exceeds limit of 100
33
34 _, err := data.UnmarshalMsg(buf)
35 if err != msgp.ErrLimitExceeded {
36 t.Errorf("Expected ErrLimitExceeded, got %v", err)
37 }
38 })
39
40 // Test that slices within limit work fine
41 t.Run("SliceWithinLimit", func(t *testing.T) {
42 buf := msgp.AppendMapHeader(nil, 1)
43 buf = msgp.AppendString(buf, "big_slice")
44 buf = msgp.AppendArrayHeader(buf, 50) // Within limit
45 for i := 0; i < 50; i++ {
46 buf = msgp.AppendString(buf, "test")
47 }
48
49 _, err := data.UnmarshalMsg(buf)
50 if err != nil {
51 t.Errorf("Unexpected error for slice within limit: %v", err)
52 }
53 })
54}
55
56func TestMapLimitEnforcement(t *testing.T) {
57 data := LimitTestData{}

Callers

nothing calls this directly

Calls 6

AppendMapHeaderFunction · 0.92
AppendStringFunction · 0.92
AppendArrayHeaderFunction · 0.92
NewReaderFunction · 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…