瀏覽代碼

[GINR] Ensure entire git blobs are read

cgars 7 年之前
父節點
當前提交
a6216a6472
共有 1 個文件被更改,包括 3 次插入3 次删除
  1. 3 3
      routes/repo/view.go

+ 3 - 3
routes/repo/view.go

@@ -246,7 +246,9 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 			if blob.Size() > 1024 {
 				d := make([]byte, blob.Size()-
 					1024)
-				r.Read(d)
+				if _, err := io.ReadAtLeast(r, d, int(blob.Size()-1024)); err != nil {
+					log.Error(4., "Could nor read all of a git file:%+v", err)
+				}
 				buf = append(buf, d...)
 			}
 		} else {
@@ -279,8 +281,6 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 			} else {
 				fileContent = content
 			}
-			fileContent = string(buf)
-			log.Trace("Buffer Size is: %d", len(buf))
 			var output bytes.Buffer
 			lines := strings.Split(fileContent, "\n")
 			if len(lines) > setting.UI.MaxLineHighlight {