-
Notifications
You must be signed in to change notification settings - Fork 903
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
Get-FtpFile fails with integer overflow when downloading file more than 2gb in size #1098
Comments
Note also in the log that the local destination file remained locked after the FTP download failed, hindering choco's cleanup. |
That is definitely an issue. Marked for fixing soon. |
Also marking this as up for grabs if you are interested |
I've forked the repo, let me have a quick squiz. Looking at the |
I'm happy to work through with you on this one, though I'd appreciate some guidance on how you think it's best tested. Looking at the code (also thinking of #1099) there is some divergence from
In this issue, I'm concentrating on the first of these only to keep focused. There are two other aspects of these functions:
I'll open some pull requests and look for your comments. JT |
Finally block sounds good. The code in get-ftpfile cane in as a PR copying get-webfile and chamging it to ftp specific I believe. |
OK so I think I've finished messing around with effectively no-op commits on this issue to comply with the CLA correctly. I'll take a look at the file locking issues here. Any reason to have the catch block in there that re-throws the exception? PowerShell doesn't rethrow that nicely, so it would be nice to avoid it. Is this a PowerShell version 1 idiom? What PS versions should I test on? |
PowerShell v2+ |
Get-WebFile was brought in from an external location, so Get-FtpFile was based on that. Some of the code it has may not be the best. |
Can you point this specific bit out so I know we are talking about the same thing? |
Sorry mate, this bit. Write-Host ""
Write-Host "Download of $([System.IO.Path]::GetFileName($fileName)) ($goalFormatted) completed."
} catch {
throw $_.Exception
} finally {
$ErrorActionPreference = $originalEAP
}
$reader.Close() I suggest removing |
There may be something with PowerShell v2 (or really .NET Framework 2.0) where the catch block is not optional (hard to recall offhand though). The big part of that is I just would rather catch and throw (not rethrow), but maybe at the time could not determine how to do that with PowerShell. The real purpose was to ensure that the ErrorActionPreference was reset, so the finally block is the most important part of that. 👍 |
I updated the resource handling on errors, and tested it on PS 2.0 and PS 5.1. I tested it by adding a deliberate throw in the read loop, then attempt to clean up the downloaded file fragment on failure. The call failed, and the file handle was not kept open allowing cleanup to occur. I tried to improve the error handling, but it appears that PS doesn't have great support for chaining errors, so I gave that up. Let me know if there are further modifications I should make. |
Previously, using integers in Get-FtpFile could result in integer stack overflows. Change to long to bring in line with `Get-WebFile` and avoid errors. Removed unnecessary catch block, shifted close of reader and writer to the enclosing finally block. The close calls are wrapped in an empty try/catch as an error here would mask an error thrown from the catch block.
* pr1104: (GH-1098) Get-FtpFile - change int to long / improve error handling
* stable: (GH-1098) Get-FtpFile - change int to long / improve error handling (docs) update generated docs (GH-1187) Get-ChocolateyUnzip - support both archs (GH-1039) Remove quotes before testing path (GH-686) Upgrade Scenarios for Prereleases (GH-686) Upgrade Prereleases (GH-1151) Option - Stop on first package failure (GH-902) Fix: User changed to SYSTEM during env update
This will be included in 0.10.4 |
What You Are Seeing?
When downloading a >2Gb file via ftp with
Get-FtpFile
(called byGet-ChocolateyWebFile
), the following error is observed:What is Expected?
The file should download successfully.
How Did You Get This To Happen? (Steps to Reproduce)
Get-FtpFile
functionOutput Log
https://gist.github.com/jamestelfer/f10314dab426b9e47c447ca3f9db76bd
The text was updated successfully, but these errors were encountered: