Skip to content

fix(fs): accept uploads without Content-Length - #9636

Merged
okatu-loli merged 2 commits into
AlistGo:mainfrom
CBOSSX:bugfix/fsstream-missing-content-length-20260903T040413Z
Sep 15, 2026
Merged

okatu-loli merged 2 commits into
AlistGo:mainfrom
CBOSSX:bugfix/fsstream-missing-content-length-20260903T040413Z

Conversation

@CBOSSX

@CBOSSX CBOSSX commented Sep 3, 2026

Copy link
Copy Markdown

Summary

  • Fixes: PUT /api/fs/put returns a code 400 strconv.ParseInt error for an empty request whose Content-Length header is absent.
  • Root cause: FsStream reparses the literal Gin header instead of using net/http's normalized Request.ContentLength, so an absent header becomes an empty string and fails before upload handling.
  • A present malformed literal Content-Length is still rejected with code 400 before upload handling.

Closes #9606.

Regression evidence

  • Before: go test ./server/handles -run '^TestFsStreamAcceptsMissingContentLength$' -count=1 -v exited 1

  • After: go test ./server/handles -run '^TestFsStreamAcceptsMissingContentLength$' -count=1 -v exited 0

  • Review regression: go test ./server/handles -run '^TestFsStreamRejectsInvalidContentLength$' -count=1 -v failed on the previous PR head and passes after the follow-up.

Verification

  • go test -vet=off ./server/... -count=1
  • go test -race ./server/handles -count=1
  • go vet ./server/handles
  • git diff --check

Validation notes

  • go test ./server/... -count=1 reaches an unchanged Go 1.25 vet error in server/s3/backend.go; the same error reproduces on base 3e49fa4. Running the server suite with -vet=off passes, and go vet ./server/handles passes.
  • go test -vet=off ./... -count=1 additionally requires local FUSE headers and a running aria2 service, and has an unrelated Windows-path assertion that fails on macOS. The affected server suite passes in full.

Scope

  • 2 files changed, +54 / -5 lines

@skysliences

Copy link
Copy Markdown
Contributor

请修改一下判断逻辑。增加对非法Content-Length的判断。逻辑可行。修改好重新提交pr

@CBOSSX

CBOSSX commented Sep 4, 2026

Copy link
Copy Markdown
Author

已按建议补充非法 Content-Length 校验:缺失字面头时使用 Request.ContentLength,存在字面头时仍通过 strconv.ParseInt 校验,非法值在进入上传逻辑前返回 code 400。新增回归覆盖非法值;缺失/非法两个聚焦用例、server 全套(vet-off)、handles race、handles vet 和质量门禁均通过。

@okatu-loli
okatu-loli merged commit b497664 into AlistGo:main Sep 15, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local driver FsStream (/api/fs/put) fails with strconv.ParseInt error when Content-Length header is absent

3 participants