Skip to content

Incorrect Seek Operations in SftpFileStream #909

Closed
@lemonyte

Description

@lemonyte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions