Skip to content

Conversation

@klauspost
Copy link
Collaborator

@klauspost klauspost commented Nov 14, 2025

Add //msgp:limit directive to prevent DoS attacks by limiting array/slice and map sizes during msgp serialization/deserialization operations.

Features:

  • Unified directive syntax: //msgp:limit arrays:n maps:n marshal:true/false
  • Applies only to dynamic slices/maps, excludes fixed arrays (compile-time sized)
  • Optional marshal-time enforcement with marshal:true parameter
  • Default limits of math.MaxUint32 when not specified
  • Returns msgp.ErrLimitExceeded when limits exceeded
  • Per-file unique constant generation using CRC32 hash to avoid collisions

Usage examples:

//msgp:limit arrays:100 maps:50 (unmarshal limits only)

//msgp:limit arrays:100 maps:50 marshal:true (both marshal and unmarshal limits)

Fixes #411

Add `//msgp:limit` directive to prevent DoS attacks by limiting array/slice and map sizes during msgp serialization/deserialization operations.

Features:
  - Unified directive syntax: //msgp:limit arrays:n maps:n marshal:true/false
  - Applies only to dynamic slices/maps, excludes fixed arrays (compile-time sized)
  - Optional marshal-time enforcement with marshal:true parameter
  - Default limits of math.MaxUint32 when not specified
  - Returns msgp.ErrLimitExceeded when limits exceeded
  - Per-file unique constant generation using CRC32 hash to avoid collisions

Usage examples:

`//msgp:limit arrays:100 maps:50` (unmarshal limits only)

`//msgp:limit arrays:100 maps:50 marshal:true` (both marshal and unmarshal limits)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SetMaxElements equivalent for msgp.Unmarshaler interface

1 participant