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

SFTP file stream not working with System.IO.Compression.Zip #1018

Closed
S-Jindal opened this issue Oct 21, 2022 · 2 comments · Fixed by #910
Closed

SFTP file stream not working with System.IO.Compression.Zip #1018

S-Jindal opened this issue Oct 21, 2022 · 2 comments · Fixed by #910

Comments

@S-Jindal
Copy link

I am getting the following error when trying to instantiate a ZipArchive object using Sftp file stream.

message='Exception: System.IO.InvalidDataException: Central Directory corrupt.
[2022-10-21T14:16:36.733Z]  ---> System.IO.IOException: Zip file corrupt: unexpected end of stream reached.
[2022-10-21T14:16:36.734Z]    at System.IO.Compression.ZipHelper.ReadBytes(Stream stream, Byte[] buffer, Int32 bytesToRead)
[2022-10-21T14:16:36.734Z]    at System.IO.Compression.ZipHelper.SeekBackwardsAndRead(Stream stream, Byte[] buffer, Int32& bufferPointer)
[2022-10-21T14:16:36.736Z]    at System.IO.Compression.ZipHelper.SeekBackwardsToSignature(Stream stream, UInt32 signatureToFind, Int32 maxBytesToRead)
[2022-10-21T14:16:36.736Z]    at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory()
[2022-10-21T14:16:36.737Z]    --- End of inner exception stack trace ---
[2022-10-21T14:16:36.737Z]    at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory()
[2022-10-21T14:16:36.738Z]    at System.IO.Compression.ZipArchive..ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen, Encoding entryNameEncoding)
[2022-10-21T14:16:36.739Z]    at System.IO.Compression.ZipArchive..ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen)

Looking at the backtrace, looks like when trying to read from the end of file it is getting this error: Zip file corrupt: unexpected end of stream reached.

my code is simple:

using(var remoteStream = sftpclient.OpenRead(filepath)
using(var zip = new ZipArchive(stream: remoteStream,  mode: ZipArchiveMode.Read, leaveOpen: true))
{
...
}
@S-Jindal
Copy link
Author

@drieseng would you be able to help here? I think you can easily reproduce it on any system with the code above.

@zybexXL
Copy link
Contributor

zybexXL commented Oct 25, 2022

this is fixed in PR #910

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

Successfully merging a pull request may close this issue.

2 participants