Unnecessary loop, or potential data corruption issue, in Paszlib/Zipper (TDeflater.Compress)
Original Reporter info from Mantis: Lawrence_NZ
-
Reporter name: Lawrence Curwood
Original Reporter info from Mantis: Lawrence_NZ
- Reporter name: Lawrence Curwood
Description:
In line 1000 - 1001 of zipper.pp, TDeflater.Compress method writes data from memory (Buf) to a TCompressionStream (C) using the following loop:
while (NewCount>0) do
NewCount:=NewCount-C.Write(Buf^,NewCount);
In the event that TCompressionStream.Write writes less than NewCount bytes at once, the loop would then write the same source data from Buf^ again until the full write size is satisfied. (i.e. the Buf^ pointer is not advanced to account for the number of bytes written during each iteration).
Steps to reproduce:
I haven't been able to reproduce an issue on Windows (as .Write always returns the full amount in a single call), but if TCompressionStream.Write is actually guaranteed to satisfy a complete Write of any size in a single call under all platforms/conditions, the "while (NewCount > 0) do" loop is unnecessary.. and if not guaranteed, it's a potential bug.
Mantis conversion info:
- Mantis ID: 39024
- Build: current
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 49518 (#15f25da1)
- Target version: 4.0.0