[CLOSED] Improvements to TSHA256's Stream, StreamHexa and StreamBase64 routines lazarus / 64-FPC development ---------------------------------------------------------------------- lagprogramming · 2023-08-11 09:48 packages/fcl-hash/src/fpsha256.pp has the following routines: 1/3 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i class 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/3 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i class 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/3 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i class 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: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i diff --git a/packages/fcl-hash/src/fpsha256.pp b/packages/fcl- hash/src/fpsha256.ppindex 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; ---------------------------------------------------------------------- AlexTP · 2023-08-11 10:07 Posted to https://gitlab.com/freepascal.org/fpc/source/-/issues/40386