Răsfoiți Sursa

Bug Fix for index > 0 in TransformBytes in HashLib4Pascal

- bugfix for index > 0 in transformbytes for murmur3 and siphash.
- also added unit tests for such cases.
- bumped package version number.
-thanks to @HermanSchoenfeld for reporting this bug and @qualialibre for the suggested optimal fix.
Ugochukwu Mmaduekwe 7 ani în urmă
părinte
comite
3f3ed04ca6

+ 4 - 0
src/libraries/hashlib4pascal/HlpMurmurHash3_x64_128.pas

@@ -449,6 +449,10 @@ begin
     begin
       ProcessPendings;
     end;
+  end
+  else
+  begin
+    i := 0;
   end;
 
   nBlocks := len shr 4;

+ 4 - 0
src/libraries/hashlib4pascal/HlpMurmurHash3_x86_128.pas

@@ -493,6 +493,10 @@ begin
     begin
       ProcessPendings;
     end;
+  end
+  else
+  begin
+    i := 0;
   end;
 
   nBlocks := len shr 4;

+ 4 - 3
src/libraries/hashlib4pascal/HlpMurmurHash3_x86_32.pas

@@ -232,7 +232,6 @@ begin
       ...
       idx = 2, len = 6 -> [0, 2[ + [0, 2[ => Block = [2,6[, buf []
       * }
-
 {$IFDEF DEBUG}
     System.Assert(a_index = 0); // nothing would work anyways if a_index is !=0
 {$ENDIF DEBUG}
@@ -250,6 +249,10 @@ begin
       TransformUInt32Fast(k);
       Fm_idx := 0;
     end;
+  end
+  else
+  begin
+    i := 0;
   end;
 
   nBlocks := len shr 2;
@@ -260,7 +263,6 @@ begin
   while i < nBlocks do
   begin
     k := TConverters.ReadBytesAsUInt32LE(ptr_a_data, a_index + (i * 4));
-
     TransformUInt32Fast(k);
 
     System.Inc(i);
@@ -270,7 +272,6 @@ begin
   offset := a_index + (i * 4);
   while offset < (len + a_index) do
   begin
-
     ByteUpdate(a_data[offset]);
     System.Inc(offset);
 

+ 4 - 0
src/libraries/hashlib4pascal/HlpSipHash.pas

@@ -323,6 +323,10 @@ begin
       ProcessBlock(m);
       Fm_idx := 0;
     end;
+  end
+  else
+  begin
+    i := 0;
   end;
 
   iter := Length shr 3;