binary/hybrid Marshal() fails if event has any items over the limits.

This commit is contained in:
fiatjaf
2023-12-22 19:33:30 -03:00
parent f1980e8b7a
commit 781aecc6ac
2 changed files with 56 additions and 8 deletions

View File

@@ -1,10 +1,35 @@
package binary
import "math"
import (
"math"
"github.com/nbd-wtf/go-nostr"
)
const (
MaxContentSize = math.MaxUint16
MaxKind = math.MaxUint16
MaxTagCount = math.MaxUint16
MaxTagSize = math.MaxUint16
MaxKind = math.MaxUint16
MaxCreatedAt = math.MaxUint32
MaxContentSize = math.MaxUint16
MaxTagCount = math.MaxUint16
MaxTagItemCount = math.MaxUint8
MaxTagItemSize = math.MaxUint16
)
func EventEligibleForBinaryEncoding(event *nostr.Event) bool {
if len(event.Content) > MaxContentSize || event.Kind > MaxKind || event.CreatedAt > MaxCreatedAt || len(event.Tags) > MaxTagCount {
return false
}
for _, tag := range event.Tags {
if len(tag) > MaxTagItemCount {
return false
}
for _, item := range tag {
if len(item) > MaxTagItemSize {
return false
}
}
}
return true
}