From ddc3ef8db36574ca7006a7fbed3bfa00bdabe5b6 Mon Sep 17 00:00:00 2001
From: dev <dev@robertfoss.se>
Date: Sat, 4 Apr 2015 00:05:29 +0000
Subject: [PATCH] Removed unnecessry buffering

---
 .../src/net/i2p/data/i2np/I2NPMessageImpl.java  | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java b/router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java
index be6b54aa8e..432a5e8133 100644
--- a/router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java
+++ b/router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java
@@ -199,24 +199,23 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
         cur += DataHelper.DATE_LENGTH;
         int size = (int)DataHelper.fromLong(data, cur, 2);
         cur += 2;
-        //Hash h = new Hash();
-        byte hdata[] = new byte[CHECKSUM_LENGTH];
-        System.arraycopy(data, cur, hdata, 0, CHECKSUM_LENGTH);
-        cur += CHECKSUM_LENGTH;
-        //h.setData(hdata);
 
         if (cur + size > data.length || headerSize + size > maxLen)
-            throw new I2NPMessageException("Payload is too short [" 
+            throw new I2NPMessageException("Payload is too short ["
                                            + "data.len=" + data.length
                                            + "maxLen=" + maxLen
                                            + " offset=" + offset
-                                           + " cur=" + cur 
+                                           + " cur=" + cur
                                            + " wanted=" + size + "]: " + getClass().getSimpleName());
 
         int sz = Math.min(size, maxLen - headerSize);
         byte[] calc = SimpleByteCache.acquire(Hash.HASH_LENGTH);
-        _context.sha().calculateHash(data, cur, sz, calc, 0);
-        boolean eq = DataHelper.eq(hdata, 0, calc, 0, CHECKSUM_LENGTH);
+        
+        // Compare the checksum in data to the checksum of the data after the checksum
+        _context.sha().calculateHash(data, cur + CHECKSUM_LENGTH, sz, calc, 0);
+        boolean eq = DataHelper.eq(data, cur, calc, 0, CHECKSUM_LENGTH);
+        cur += CHECKSUM_LENGTH;
+
         SimpleByteCache.release(calc);
         if (!eq)
             throw new I2NPMessageException("Bad checksum on " + size + " byte I2NP " + getClass().getSimpleName());
-- 
GitLab