From 2166d6bf99335fd857a3c541b2ec3f3d12d2e1a6 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Tue, 4 Feb 2025 00:45:53 +0000
Subject: [PATCH] Data: Fix compressible padding detection and expansion

---
 core/java/src/net/i2p/data/KeysAndCert.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/core/java/src/net/i2p/data/KeysAndCert.java b/core/java/src/net/i2p/data/KeysAndCert.java
index 70c6760d2a..0b8a6c05f6 100644
--- a/core/java/src/net/i2p/data/KeysAndCert.java
+++ b/core/java/src/net/i2p/data/KeysAndCert.java
@@ -132,7 +132,7 @@ public class KeysAndCert extends DataStructureImpl {
             return _padding;
         byte[] rv = new byte[PAD_COMP_LEN * _paddingBlocks];
         for (int i = 0; i <_paddingBlocks; i++) {
-            System.arraycopy(_padding, 0, _paddingBlocks, i * PAD_COMP_LEN, PAD_COMP_LEN);
+            System.arraycopy(_padding, 0, rv, i * PAD_COMP_LEN, PAD_COMP_LEN);
         }
         return rv;
     }
@@ -196,11 +196,11 @@ public class KeysAndCert extends DataStructureImpl {
     private void compressPadding() {
         _paddingBlocks = 0;
         // > 32 and a mult. of 32
-        if (_padding == null || (_padding.length & (2 * PAD_COMP_LEN) - 1) != PAD_COMP_LEN)
+        if (_padding == null || _padding.length <= 32 || (_padding.length & (PAD_COMP_LEN - 1)) != 0)
             return;
         int blks = _padding.length / PAD_COMP_LEN;
         for (int i = 1; i < blks; i++) {
-            if (!DataHelper.eq(_padding, 0, _padding, i, PAD_COMP_LEN)) {
+            if (!DataHelper.eq(_padding, 0, _padding, i * PAD_COMP_LEN, PAD_COMP_LEN)) {
                 return;
             }
         }
-- 
GitLab