From 4c70e14310861561b98c867927e905697519397d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 8 Nov 2013 14:49:23 -0500 Subject: [PATCH] search: add LimitReader around JSON decoding. add some TODOs Change-Id: I98069ef0aeb8c96cdc997c138222e0344981ead8 --- pkg/search/query.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/search/query.go b/pkg/search/query.go index 5238a52cb..cca310563 100644 --- a/pkg/search/query.go +++ b/pkg/search/query.go @@ -20,6 +20,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "log" "net/http" "os" @@ -33,13 +34,7 @@ import ( type SortType int -// TODO: extend/merge/delete this type? probably dups in this package. -type BlobMeta struct { - Ref blob.Ref - Size int - MIMEType string -} - +// TODO: add MarshalJSON and UnmarshalJSON to SortType const ( UnspecifiedSort SortType = iota LastModifiedDesc @@ -48,6 +43,13 @@ const ( CreatedAsc ) +// TODO: extend/merge/delete this type? probably dups in this package. +type BlobMeta struct { + Ref blob.Ref + Size int + MIMEType string +} + type SearchQuery struct { Constraint *Constraint `json:"constraint"` Limit int `json:"limit"` // optional. default is automatic. @@ -55,7 +57,7 @@ type SearchQuery struct { } func (q *SearchQuery) fromHTTP(req *http.Request) error { - dec := json.NewDecoder(req.Body) + dec := json.NewDecoder(io.LimitReader(req.Body, 1<<20)) if err := dec.Decode(q); err != nil { return err }