Skip to content

Commit

Permalink
Added GetLen to streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-matthew committed Jan 29, 2024
1 parent 4a5c358 commit 0a79837
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"mime"
"mime/multipart"
"net"
"net/http"
"net/http/fcgi"
Expand Down Expand Up @@ -243,7 +244,9 @@ func (h handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
return
}

file, err := request.MultipartForm.File[k][0].Open()
var file fupload
file.size = uint64(request.MultipartForm.File[k][0].Size)
file.multipartfile, err = request.MultipartForm.File[k][0].Open()
if err != nil {
httplogContext.Errorf("failed to open stream from %s: %s", k, err)
writer.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -314,6 +317,25 @@ writeStream:
}
}

type fupload struct {
size uint64
multipartfile multipart.File
}

func (f fupload) Read(p []byte) (n int, err error) {
return f.multipartfile.Read(p)
}

func (f fupload) Close() error {
return f.multipartfile.Close()
}

func (f fupload) GetLen() (n uint64, err error) {
return f.size, nil
}

var _ vorlageproc.StreamInput = fupload{}

/*
* Returns true if path will upward transversal (aka transversal attack).
* Returns false if the path does not contain a upward transversal.
Expand Down
3 changes: 3 additions & 0 deletions procload-c-exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func (n2 nilStream) Read(p []byte) (n int, err error) {
func (n2 nilStream) Close() error {
return nil
}
func (n2 nilStream) GetLen() (uint64, error) {
return 0, nilerror
}

var nilstream = nilStream(0)

Expand Down

0 comments on commit 0a79837

Please sign in to comment.