]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - group.go
Check size limits and abort if they are violated
[nsscash/nsscash.git] / group.go
index 126ebb0dc349e0127c4ff14f3b61f48cb99cc737..4ca213a0edfabc48fd7a95e4280509c4547c9d5c 100644 (file)
--- a/group.go
+++ b/group.go
@@ -26,6 +26,7 @@ import (
        "sort"
        "strconv"
        "strings"
+       "math"
 
        "github.com/pkg/errors"
 )
@@ -130,6 +131,11 @@ func SerializeGroup(g Group) ([]byte, error) {
        }
        // And the group members concatenated as above
        data.Write(mems.Bytes())
+       // Ensure the offsets can fit the length of this entry
+       if data.Len() > math.MaxUint16 {
+               return nil, fmt.Errorf("group too large to serialize: %v, %v",
+                       data.Len(), g)
+       }
        size := uint16(data.Len())
 
        var res bytes.Buffer // serialized result