From: Urban Wallasch Date: Thu, 4 Apr 2019 15:52:24 +0000 (+0200) Subject: * Fixed partially initialized buffer bug in content type detection for short files. X-Git-Tag: v0.1~2 X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=7e5dcdbfdf4b96eb57c84460e4e95d9757e2b188;p=gogopherd.git * Fixed partially initialized buffer bug in content type detection for short files. --- diff --git a/gogopherd.go b/gogopherd.go index 934ce7c..14feca4 100644 --- a/gogopherd.go +++ b/gogopherd.go @@ -130,10 +130,11 @@ func guessFiletype(path string) (string, error) { defer f.Close() // Get the content buffer := make([]byte, 512) - _, err = f.Read(buffer) + n, err := f.Read(buffer) if check(err, "Read "+path) != nil { return "i", err } + buffer = buffer[:n] contentType := http.DetectContentType(buffer) //tracer.Print("Content Type " + path + " == "+ contentType) shortType := strings.Split(contentType, ";")[0]