If size is deferred, then constrain how much of the request body to read
This commit is contained in:
parent
a366b00e3e
commit
8c3ceebcfc
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -504,6 +505,18 @@ func (handler *UnroutedHandler) writeChunk(id string, info FileInfo, w http.Resp
|
||||||
}
|
}
|
||||||
|
|
||||||
maxSize := info.Size - offset
|
maxSize := info.Size - offset
|
||||||
|
// If the upload's length is deferred and the PATCH request does not contain the Content-Length
|
||||||
|
// header (which is allowed if 'Transfer-Encoding: chunked' is used), we still need to set limits for
|
||||||
|
// the body size.
|
||||||
|
if info.SizeIsDeferred {
|
||||||
|
if handler.config.MaxSize > 0 {
|
||||||
|
// Ensure that the upload does not exceed the maximum upload size
|
||||||
|
maxSize = handler.config.MaxSize - offset
|
||||||
|
} else {
|
||||||
|
// If no upload limit is given, we allow arbitrary sizes
|
||||||
|
maxSize = math.MaxInt64
|
||||||
|
}
|
||||||
|
}
|
||||||
if length > 0 {
|
if length > 0 {
|
||||||
maxSize = length
|
maxSize = length
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue