Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Seek Operations in SftpFileStream #909

Closed
lemonyte opened this issue Jan 5, 2022 · 1 comment · Fixed by #910
Closed

Incorrect Seek Operations in SftpFileStream #909

lemonyte opened this issue Jan 5, 2022 · 1 comment · Fixed by #910
Labels

Comments

@lemonyte
Copy link
Contributor

lemonyte commented Jan 5, 2022

When SftpFileStream.Seek() is called with the origin parameter set to SeekOrigin.End and a negative offset, the resulting position is greater than the size of the stream. This is because the negative offset is subtracted from the total size, instead of added.

newPosn = attributes.Size - offset;

newPosn = attributes.Size - offset;

size   offset
1000 - (-42) = 1042
1000 + (-42) = 958

Failed test using SftpFileStream.Seek():

FluentAssertions.Execution.AssertionFailedException
  HResult=0x80131500
  Message=Expected stream.Seek(-5, SeekOrigin.End) to be 22L, but found 32L.

Furthermore, the tests for SftpFileStream only cover cases with the origin set to SeekOrigin.Begin, and not SeekOrigin.Current or SeekOrigin.End.

@lemonyte
Copy link
Contributor Author

lemonyte commented Jan 5, 2022

Opened a pull request fixing the issue. (#910)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants