packages/fcl-hash/src/fpsha256.pp has the following routines:
1/3class procedure TSHA256.Stream(aStream: TStream; out aDigest: TSHA256Digest);
const
BUFFER_SIZE = 64*1024;
var
aLen : LongInt;
Buffer: TBytes;
SHA256: TSHA256;
begin
Buffer:=Nil;
SHA256.Init;
SetLength(Buffer,BUFFER_SIZE);
repeat
aLen:=aStream.Read(Buffer, BUFFER_SIZE);
if aLen = 0 then
Break;
SHA256.Update(PByte(Buffer),aLen);
until aLen=0;
SHA256.Final;
aDigest:=SHA256.Digest;
end;
The condition of the repeat loop regarding the value of
aLen is always fulfilled because if the assigned value is 0 then we have an immediate
break and later the declared
procedure Update(PBuf: PByte; Size: UInt32); overload; receives the
aLen parameter by value.
The proposed patch replaces
until aLen=0; with
until false;2/3class function TSHA256.StreamHexa(aStream: TStream): AnsiString;
begin
Result:='';
StreamHexa(aStream,Result);
end;
The file contains the following declaration:
class procedure StreamHexa(aStream: TStream; out Result: AnsiString); static; overload;According to the above declaration, the proposed patch removes the line
Result:='';3/3class Function TSHA256.StreamBase64(aStream: TStream; isURL : Boolean): AnsiString;
begin
Result:='';
StreamBase64(aStream,isURL,Result);
end;
The file contains the following declaration:
class procedure StreamBase64(aStream: TStream; isURL : Boolean; out Result: AnsiString); static; overload;According to the above declaration, the proposed patch removes the line
Result:='';Here is the patch:
diff --git a/packages/fcl-hash/src/fpsha256.pp b/packages/fcl-hash/src/fpsha256.pp
index 7cb3c8b2d6..80cab79351 100644
--- a/packages/fcl-hash/src/fpsha256.pp
+++ b/packages/fcl-hash/src/fpsha256.pp
@@ -361,7 +361,7 @@ class procedure TSHA256.Stream(aStream: TStream; out aDigest: TSHA256Digest);
if aLen = 0 then
Break;
SHA256.Update(PByte(Buffer),aLen);
- until aLen=0;
+ until false;
SHA256.Final;
aDigest:=SHA256.Digest;
end;
@@ -388,7 +388,6 @@ class procedure TSHA256.StreamHexa(aStream: TStream; out Result: AnsiString);
class function TSHA256.StreamHexa(aStream: TStream): AnsiString;
begin
- Result:='';
StreamHexa(aStream,Result);
end;
@@ -408,7 +407,6 @@ class procedure TSHA256.StreamBase64(aStream: TStream; isURL : Boolean; out Resu
class Function TSHA256.StreamBase64(aStream: TStream; isURL : Boolean): AnsiString;
begin
- Result:='';
StreamBase64(aStream,isURL,Result);
end;