Skip to content

Commit

Permalink
cmd/airliftd: fix serving small files (resolves #35)
Browse files Browse the repository at this point in the history
Resolved a misuse of io.ReadFull used to detect MIME type. io.EOF may be
returned if file is smaller than provided buffer.
  • Loading branch information
moshee committed Mar 21, 2021
1 parent d352ba2 commit a15ef7c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/airliftd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,20 @@ func getFile(g *gas.Gas) (int, gas.Outputter) {
if err != nil {
return 500, out.Error(g, err)
}

defer f.Close()

buf := make([]byte, 512)
fi, err := f.Stat()
if err != nil {
return 500, out.Error(g, err)
}

bufsize := 512
fsize := int(fi.Size())
if fsize < bufsize {
bufsize = fsize
}

buf := make([]byte, bufsize)
_, err = io.ReadFull(f, buf)
if err != nil {
return 500, out.Error(g, err)
Expand Down

0 comments on commit a15ef7c

Please sign in to comment.