messense / aliyundrive-webdav

阿里云盘 WebDAV 服务
MIT License
9.6k stars 1.09k forks source link

Fix bug in `seek` #838

Closed drewtato closed 1 year ago

drewtato commented 1 year ago

The current implementation of DavFile::seek is incorrect.

https://github.com/messense/aliyundrive-webdav/blob/290718e3fdfae2fb184d0039caacdd68767e878f/src/vfs.rs#L964

SeekFrom::End is supposed to add to the total length. This typically uses either zero or a negative number for pos. This pull request changes - to +.

SeekFrom::End(pos) => (self.file.size as i64 + pos) as u64,

I found this from doing a code search on Github. I also found some implementations of Seek that use this correctly, such as the one from clap.

SeekFrom::End(pos) => (self.items.len() as i64).saturating_add(pos).max(0) as u64,

Hopefully this doesn't break things that were relying on this. There weren't any tests (in rust at least) to verify.