Skip to content

Enforce disk usage limit when spilling part to disk - #37285

Merged
bclozel merged 2 commits into
spring-projects:7.0.xfrom
hunseonglee:gh-35099
Sep 17, 2026
Merged

bclozel merged 2 commits into
spring-projects:7.0.xfrom
hunseonglee:gh-35099

Conversation

@hunseonglee

Copy link
Copy Markdown
Contributor

Previously, PartGenerator only enforced maxDiskUsagePerPart for body buffers that arrived after a part had switched to file storage (IdleFileState#body). The content accumulated in memory that triggered the switch was carried into CreateFileState and written to disk without any check against maxDiskUsagePerPart. As a result, a part whose last body buffer caused the in-memory overflow was accepted in full, even when its total size exceeded the configured disk usage limit — matching the reproduction in gh-35099 (max-in-memory-size=1KB, max-disk-usage-per-part=1KB, 1030-byte upload accepted).

This PR checks the accumulated byte count against maxDiskUsagePerPart in InMemoryState#switchToFile before the temp file is created, and emits a DataBufferLimitException with the same message as the existing check for subsequent buffers. Buffers held by the state are released before emitting the error, keeping the leak checks in DefaultPartHttpMessageReaderTests green.

The added regression test drives files.multipart (100-byte parts, 64-byte buffers) with maxInMemorySize=90 / maxDiskUsagePerPart=99, so the spill-over itself exceeds the disk limit; it fails on main with onNext(DefaultFilePart) instead of the expected error.

Closes gh-35099

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 16, 2026
@bclozel bclozel self-assigned this Sep 16, 2026
@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 16, 2026
@bclozel bclozel added this to the 7.0.x milestone Sep 16, 2026
@bclozel
bclozel changed the base branch from main to 7.0.x September 17, 2026 14:22
@bclozel bclozel modified the milestones: 7.0.x, 7.0.10 Sep 17, 2026
hunseonglee and others added 2 commits September 17, 2026 16:48
Previously, PartGenerator only enforced maxDiskUsagePerPart for body
buffers that arrived after a part had switched to file storage. The
content accumulated in memory that triggered the switch was written
to disk without any check against maxDiskUsagePerPart. As a result,
a part whose last body buffer caused the in-memory overflow was
accepted in full, even when its total size exceeded the configured
disk usage limit.

This commit checks the accumulated byte count against
maxDiskUsagePerPart before switching to file storage, and emits a
DataBufferLimitException, consistent with the existing check for
subsequent buffers.

Closes spring-projectsgh-35099

Signed-off-by: seonghun lee <harrisleesh@gmail.com>
@bclozel
bclozel merged commit 8107a2b into spring-projects:7.0.x Sep 17, 2026
1 check failed
@bclozel

bclozel commented Sep 17, 2026

Copy link
Copy Markdown
Member

Thanks @harrisleesh !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

max-disk-usage-per-part allows upload of bigger files

3 participants