summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-07-23 18:58:06 +0200
committerDimitri Sokolyuk <demon@dim13.org>2018-07-23 18:58:06 +0200
commitfd638228c5eb0b482a5a3df8957efb51e05d8656 (patch)
tree1adcb388883ad7dafb93e955d5064b3c8ec6538b
parent053168f05e6aaf7b95d2b2cd24ba37d919d141b0 (diff)
limit input
-rw-r--r--href.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/href.go b/href.go
index 6db1347..b6c5368 100644
--- a/href.go
+++ b/href.go
@@ -2,6 +2,7 @@ package main
import (
"errors"
+ "io"
"net/http"
"strings"
@@ -31,6 +32,8 @@ func title(n *html.Node) (string, error) {
return "", errNoTitle
}
+const maxLength = 10 * 1024 * 1024 // 10MB
+
func getTitle(uri string) (string, error) {
resp, err := http.Get(uri)
if err != nil {
@@ -43,11 +46,11 @@ func getTitle(uri string) (string, error) {
return "", errNotHTML
}
- if resp.ContentLength > 10*1024*1024 {
+ if resp.ContentLength > maxLength {
return "", errTooBig
}
- r, err := charset.NewReader(resp.Body, ct)
+ r, err := charset.NewReader(io.LimitReader(resp.Body, maxLength), ct)
if err != nil {
return "", err
}