浏览代码

Check source content length before getting download buffer

DarthSim 6 年之前
父节点
当前提交
c6145a8e69
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4 0
      download.go

+ 4 - 0
download.go

@@ -125,6 +125,10 @@ func readAndCheckImage(ctx context.Context, res *http.Response) (context.Context
 
 	if res.ContentLength > 0 {
 		contentLength = int(res.ContentLength)
+
+		if conf.MaxSrcFileSize > 0 && contentLength > conf.MaxSrcFileSize {
+			return ctx, func() {}, errSourceFileTooBig
+		}
 	}
 
 	buf := downloadBufPool.Get(contentLength)