Fixed off-by-1 buffer error
authorpkanavos <pkanavos@gmail.com>
Wed, 12 Sep 2012 15:38:20 +0000 (18:38 +0300)
committerpkanavos <pkanavos@gmail.com>
Wed, 12 Sep 2012 15:38:20 +0000 (18:38 +0300)
trunk/Pithos.Core/Agents/BlockUpdater.cs
trunk/Pithos.Network/BlockHashAlgorithms.cs

index b39ca18..394e555 100644 (file)
@@ -172,8 +172,8 @@ namespace Pithos.Core.Agents
                             block = buffer;\r
                         else\r
                         {\r
-                            block=new byte[lastByteIndex];\r
-                            Buffer.BlockCopy(buffer,0,block,0,lastByteIndex);\r
+                            block=new byte[lastByteIndex+1];\r
+                            Buffer.BlockCopy(buffer,0,block,0,lastByteIndex+1);\r
                         }\r
                         var binHash = hasher.Digest(block);\r
                         var hash = binHash.ToHashString();\r
index f94f45c..f7bc02a 100644 (file)
@@ -308,8 +308,8 @@ namespace Pithos.Network
                                                                 hash = hasher.Digest(buffer[idx]);\r
                                                             else\r
                                                             {\r
-                                                                var buf=new byte[lastByteIndex];\r
-                                                                Buffer.BlockCopy(buffer[idx],0,buf,0,lastByteIndex);\r
+                                                                var buf=new byte[lastByteIndex+1];\r
+                                                                Buffer.BlockCopy(buffer[idx],0,buf,0,lastByteIndex+1);\r
                                                                 hash = hasher.Digest(buf);\r
                                                             }\r
 \r