diff --git a/internal/scraper/modified.go b/internal/scraper/modified.go index 9f52f4d..3a0e447 100644 --- a/internal/scraper/modified.go +++ b/internal/scraper/modified.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "math" "os" "path/filepath" "sort" @@ -55,8 +56,23 @@ func buildModifiedEvents(path string, newData []byte, kind, scopeKind string, sc } oldMap := mapRawByID(oldPage.Results) - ids := make([]int64, 0, len(oldMap)+len(newMap)) - seen := make(map[int64]struct{}, len(oldMap)+len(newMap)) + const maxTrackedItems = 1_000_000 + + oldLen := len(oldMap) + newLen := len(newMap) + if oldLen > maxTrackedItems || newLen > maxTrackedItems { + return nil, fmt.Errorf("too many tracked items to build modified events") + } + if oldLen > math.MaxInt-newLen { + return nil, fmt.Errorf("too many tracked items to build modified events") + } + combinedLen := oldLen + newLen + if combinedLen > maxTrackedItems { + return nil, fmt.Errorf("too many tracked items to build modified events") + } + + ids := make([]int64, 0, combinedLen) + seen := make(map[int64]struct{}, combinedLen) for id := range oldMap { seen[id] = struct{}{} ids = append(ids, id)