Skip to content

Commit 71fcfc0

Browse files
committed
Added regression test for calling Done after calling one of those CalcStream methods internally calling Done raising an exception. The bug had been reported by private mail.
1 parent 85aab4e commit 71fcfc0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Unit Tests/Tests/TestDECHash.pas

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5582,7 +5582,6 @@ procedure THash_TestBase.DoTestCalcStreamNoDoneMulti(HashClass: TDECHash);
55825582
ProgressCalled := true;
55835583
end, true);
55845584

5585-
55865585
Hash := HashClass.DigestAsBytes;
55875586

55885587
if (i = FTestData.Count-1) then

Unit Tests/Tests/TestDECHashSHA3.pas

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ TestTHash_SHA3_224 = class(TestTHash_SHA3_Base)
151151
procedure TestIdentity;
152152
procedure TestFinalByteLength;
153153
procedure TestFinalByteLengthOverflow;
154+
procedure TestRegressionDoneCalledTwice;
154155
end;
155156

156157
// Test methods for class THash_SHA3_256
@@ -648,6 +649,36 @@ procedure TestTHash_SHA3_224.TestIsPasswordHash;
648649
CheckNotEquals(true, FHash.IsPasswordHash);
649650
end;
650651

652+
procedure TestTHash_SHA3_224.TestRegressionDoneCalledTwice;
653+
var
654+
Hash : THash_SHA3_224;
655+
Stream : TMemoryStream;
656+
Result : TBytes;
657+
begin
658+
// Regression test for a bug reported by Harry Rogers via private e-mail.
659+
// The failure was that Done raisedn an exception when called after calling
660+
// one of the CalcFile or CalcStream variants which automatically call Done
661+
// at the end.
662+
Hash := THash_SHA3_224.Create;
663+
try
664+
Stream := TMemoryStream.Create;
665+
try
666+
Stream.WriteData($af);
667+
Stream.Seek(0, TSeekOrigin.soBeginning);
668+
669+
Hash.CalcStream(Stream, 1, Result, nil);
670+
Hash.Done;
671+
672+
CheckEquals(RawByteString('1545e234dd648d51afe85b758f865c4855715cccf276eeb004a37a74'),
673+
BytesToRawString(TFormat_HEXL.Encode(Result)));
674+
finally
675+
Stream.Free;
676+
end;
677+
finally
678+
Hash.Free;
679+
end;
680+
end;
681+
651682
{ TestTHash_SHA3_256 }
652683

653684
procedure TestTHash_SHA3_256.ConfigHashClass(HashClass: TDECHash;

0 commit comments

Comments
 (0)