Skip to content

fix(stream): allow seeking beyond file size per Go convention#2667

Open
Ovear wants to merge 3 commits into
OpenListTeam:mainfrom
Ovear:fix-seek-beyond-filesize
Open

fix(stream): allow seeking beyond file size per Go convention#2667
Ovear wants to merge 3 commits into
OpenListTeam:mainfrom
Ovear:fix-seek-beyond-filesize

Conversation

@Ovear

@Ovear Ovear commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary / 摘要

Go的Seek函数实现(POSIX)允许Seek到超出文件大小的位置,后续由Read返回EOF,部分类库,如sftpd-openlist依赖这个行为。

在Filezilla客户端中使用sftp下载时,当前行为会导致文件无法下载,原因是Seek返回的错误透传给客户端,而不是sftp规范中的返回EOF,导致客户端认为传输失败。

OpenList 错误日志

OpenList/internal/net/request.go:385 github.com/OpenListTeam/OpenList/v4/internal/net.(*downloader).downloadChunk() chunk_5 downloaded                           
OpenList/internal/net/request.go:629 github.com/OpenListTeam/OpenList/v4/internal/net.(*multiReadCloser).Read() read_5 finished current buffer               
sftpd-openlist/server.go:139 github.com/OpenListTeam/sftpd-openlist.ServeChannel() Read EOF, n=28642                            
sftpd-openlist/server.go:53 github.com/OpenListTeam/sftpd-openlist.ServeChannel() CR op=ssh_FXP_READ data len=22               
sftpd-openlist/server.go:62 github.com/OpenListTeam/sftpd-openlist.ServeChannel() Data 00000128000000026632000000000354000000008000 
sftpd-openlist/server.go:102 github.com/OpenListTeam/sftpd-openlist.ServeChannel() Read id=296 handle=f2 offset=55836672 length=32768 
sftpd-openlist/server.go:41 github.com/OpenListTeam/sftpd-openlist.ServeChannel() Sending error: Seek: invalid offset          
sftpd-openlist/server.go:484 github.com/OpenListTeam/sftpd-openlist.writeErrCode() Sending sftp error code ssh_FX_FAILURE       
sftpd-openlist/server.go:53 github.com/OpenListTeam/sftpd-openlist.ServeChannel() CR op=ssh_FXP_READ data len=22               
sftpd-openlist/server.go:62 github.com/OpenListTeam/sftpd-openlist.ServeChannel() Data 00000129000000026632000000000354800000008000 
sftpd-openlist/server.go:102 github.com/OpenListTeam/sftpd-openlist.ServeChannel() Read id=297 handle=f2 offset=55869440 length=32768 
sftpd-openlist/server.go:41 github.com/OpenListTeam/sftpd-openlist.ServeChannel() Sending error: Seek: invalid offset          
sftpd-openlist/server.go:484 github.com/OpenListTeam/sftpd-openlist.writeErrCode() Sending sftp error code ssh_FX_FAILURE   

FileZilla 错误日志

追踪:	Processing SSH_MSG_CHANNEL_DATA, channel=0, size=25
追踪:	Sending SSH_MSG_CHANNEL_DATA (for 27 bytes), seq=26
追踪:	sftp_base::on_read
追踪:	Processing SSH_FXP_STATUS, id=12, len=17
追踪:	Got status SSH_FX_FAILURE
错误:	Could not read from remote file: 收到错误 SSH_FX_FAILURE,没有进一步描述

Remove offset > size guard from RangeReadReadAtSeeker.Seek and DynamicReadAtSeeker.Seek. Go's io.Seeker convention allows seeking past EOF.

  • This PR has breaking changes.
    / 此 PR 包含破坏性变更。
  • This PR changes public API, config, storage format, or migration behavior.
    / 此 PR 修改了公开 API、配置、存储格式或迁移行为。
  • This PR requires corresponding changes in related repositories.
    / 此 PR 需要关联仓库同步修改。

Testing / 测试

  • go test ./...
  • Manual test / 手动测试: 使用FileZilla透过sftp可以正常下载

Checklist / 检查清单

  • I have read CONTRIBUTING.
    / 我已阅读 CONTRIBUTING
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
    / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable.
    / 我已按适用情况使用 gofmtgo fmtprettier 格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable.
    / 我已在适用情况下请求相关维护者或代码所有者审查。

Ovear and others added 2 commits June 27, 2026 17:21
Remove `offset > size` guard from RangeReadReadAtSeeker.Seek and
DynamicReadAtSeeker.Seek. Go's io.Seeker convention allows seeking
past EOF.
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.

2 participants