UweRaabe/EncryptedZipFile

better end of stream handling

Opened this issue · 0 comments

Hello,

on a french forum I had a chance to look at the code. I think that there's a better way to handle the way ZDecompressionStream.Read() handles the end of stream (by reset Stream.Position to the real end of data)

  1. add a FMaxRead: UInt64 member to TCryptStream
  2. init the member in InitHeader:
    FMaxRead := Stream.Position + ZipHeader.CompressedSize;
  3. limit the Read method to never read after FMaxRead
function TDecryptStream.Read(var Buffer; Count: Integer): Integer;
var
  P: PByte;
  I: Integer;
begin
  I := FStream.Position + Count;
  if I > FMaxRead then
    Dec(Count, I - FMaxRead);

with this change, ZDecompressionStream will never read after the end of the compressed data, si TZDecompressionStream will not change Stream.Position ;)