Fix infinite loop in SFTP file reading#76
Open
spencerjanssen wants to merge 1 commit intoportnov:masterfrom
Open
Fix infinite loop in SFTP file reading#76spencerjanssen wants to merge 1 commit intoportnov:masterfrom
spencerjanssen wants to merge 1 commit intoportnov:masterfrom
Conversation
In particular when the reported size of the remote file changes between sftpFstat and completion of the read loop.
Owner
|
Could you please elaborate a bit what the patch does and why. I currently do not have some test suite for this code, so I have to rely on basic logic understanding :) |
Author
|
So the old code:
The problem is that: the size of the file may change in the course of our loop. If the file is truncated the code gets stuck in an infinite loop where each read gets 0 bytes and we never reach N. The new code doesn't rely on the reported size of the file. Instead, it reads chunks in a loop terminating once |
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.
I ran into this issue working with an SFTP server which always reports an inaccurate file size. However, I think this code is problematic in other scenarios such as the file being truncated mid-read.