fix(webdav): make slice len out of range#1384
Closed
jenken827 wants to merge 2 commits intoOpenListTeam:mainfrom
Closed
fix(webdav): make slice len out of range#1384jenken827 wants to merge 2 commits intoOpenListTeam:mainfrom
jenken827 wants to merge 2 commits intoOpenListTeam:mainfrom
Conversation
Member
|
怎么触发这个bug? |
Member
|
按理说GetSize不会返回-1 Lines 633 to 638 in d465da4 |
Contributor
Author
不好意思,这个问题在最新版本(v4.1.3)已经修复了,我还没来及更新。下次一定注意!
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description / 描述
使用webdav上传文件,触发报错,日志记录(省略连trace)如下
定位到是在创建缓存文件的时候报错的。之前用着没问题,但是随着文件大小增加(目前是2.21KB),出现了报错的情况。
Why is this change required? What problem does it solve?
为什么需要此更改?它解决了什么问题?
打印日志发现在webdav处理入口handlePut方法获取文件大小为-1(官方注释说明这种情况下是unknown),接着会获取请求头“X-File-Size”,仍然获取失败(这个请求头只有针对openlist的webdav服务编程才可以,不具有通用性),后续所有通过f.GetSize()获取到的大小都是-1。
有些存储上传需要文件hash值,这就要先把文件缓存下来,缓存时,会先根据文件大小来判定使用内存缓存还是文件缓存,而文件大小是-1,不大于设定的阈值,导致判定为使用内存缓存,紧接着根据文件大小-1来创建内存缓存,直接panic
本次修改,优化了判定逻辑,在文件大小是-1(unknown)或大于设定的阈值的时候,都使用文件缓存。