I would like to restrict the size of the file during multipart uploads. WebFlux provides configuration options:

spring.webflux.multipart.max-in-memory-size=1KB
spring.webflux.multipart.max-disk-usage-per-part=1KB

I would expect the same behaviour as with spring.servlet.multipart.max-file-size in WebMVC. However, WebFlux still allows the uploads of data greater than 1 KB. In some cases the size of file can reach up to 4KB with this setup, but I haven't found a stable reproducer for it yet. For small sizes still bigger than 1KB it is reproducible most of the times.

Example Controller:

  @RestController
  public class UploadController {

    @PostMapping
    public Mono<Long> upload(@RequestPart("file") Mono<FilePart> file) {
        return file.flatMapMany(Part::content)
                .map(DataBuffer::readableByteCount)
                .reduce(0L, Long::sum);
    }
  }

Invocation:
# 1030b is a file of size 1030b
curl -XPOST -F"file=@1030b" localhost:8080  

It looks like DefaultDataBuffer does not consider the properties during allocation. Thus it can fit the whole request after a single read from the underlying stream, and in this case the limit will never be checked.