(t *testing.T)
| 54 | } |
| 55 | |
| 56 | func 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 | |
| 103 | func TestFixedArraysNotLimited(t *testing.T) { |
| 104 | // Test that fixed arrays are not subject to limits |
nothing calls this directly
no test coverage detected
searching dependent graphs…