Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ public override int Read(byte[] buffer, int offset, int count)
int obtained = _stream.Read(_slideBuffer, _slideBufFreePos, lengthToRead);
_slideBufFreePos += obtained;

// Recalculate how much data we now have
byteCount = _slideBufFreePos - _slideBufStartPos;
if (obtained > 0 && obtained < lengthToRead)
{
// less bytes are returned but may not be the end of file. Get more to fill the required length. Eof returns 0 bytes so this is safe
int moreObtained = _stream.Read(_slideBuffer, _slideBufFreePos, lengthToRead - obtained);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only 1 extra read? You could try reading from the inner stream until the buffer is completely filled or the inner stream returns 0 bytes. Seems to be more solid.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs one extra read to fill the required length else it throws error and I don't want to change the logic of lengthToRead. This one works and I tested it. Can you help me how to fix this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to handle the case where the second read returns to little data as well seems reasonable. Would something like Numpsy@c328b3c be reasonable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thats good. I will cancel my PR if that is working and merged. Let me know if there is a new nuget release. Thank you

_slideBufFreePos += moreObtained;
obtained += moreObtained;
}

// Recalculate how much data we now have
byteCount = _slideBufFreePos - _slideBufStartPos;
if (byteCount >= _blockAndAuth)
{
// At least a 16 byte block and an auth code remains.
Expand Down