From e875bd81435bc7627e4eab9a18490583d2cee604 Mon Sep 17 00:00:00 2001 From: Tim Allison Date: Tue, 7 Jan 2020 15:45:07 +0000 Subject: BUG 64015 -- swap out java.util.BitSet for zaxxer's SparseBitSet git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872445 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java | 10 +++++----- src/java/org/apache/poi/poifs/crypt/xor/XOREncryptor.java | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/java/org/apache/poi/poifs') diff --git a/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java b/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java index b98e229d8e..e00b1c2bac 100644 --- a/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java +++ b/src/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java @@ -25,13 +25,13 @@ import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; import java.security.GeneralSecurityException; -import java.util.BitSet; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.ShortBufferException; +import com.zaxxer.sparsebits.SparseBitSet; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSWriterEvent; @@ -56,7 +56,7 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream { private final int chunkBits; private final byte[] chunk; - private final BitSet plainByteFlags; + private final SparseBitSet plainByteFlags; private final File fileOut; private final DirectoryNode dir; @@ -74,7 +74,7 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream { this.chunkSize = chunkSize; int cs = chunkSize == STREAMING ? 4096 : chunkSize; this.chunk = IOUtils.safelyAllocate(cs, MAX_RECORD_LENGTH); - this.plainByteFlags = new BitSet(cs); + this.plainByteFlags = new SparseBitSet(cs); this.chunkBits = Integer.bitCount(cs-1); this.fileOut = TempFile.createTempFile("encrypted_package", "crypt"); this.fileOut.deleteOnExit(); @@ -88,7 +88,7 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream { this.chunkSize = chunkSize; int cs = chunkSize == STREAMING ? 4096 : chunkSize; this.chunk = IOUtils.safelyAllocate(cs, MAX_RECORD_LENGTH); - this.plainByteFlags = new BitSet(cs); + this.plainByteFlags = new SparseBitSet(cs); this.chunkBits = Integer.bitCount(cs-1); this.fileOut = null; this.dir = null; @@ -283,7 +283,7 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream { return chunk; } - protected BitSet getPlainByteFlags() { + protected SparseBitSet getPlainByteFlags() { return plainByteFlags; } diff --git a/src/java/org/apache/poi/poifs/crypt/xor/XOREncryptor.java b/src/java/org/apache/poi/poifs/crypt/xor/XOREncryptor.java index 3b180b20d4..0c1cbf4932 100644 --- a/src/java/org/apache/poi/poifs/crypt/xor/XOREncryptor.java +++ b/src/java/org/apache/poi/poifs/crypt/xor/XOREncryptor.java @@ -21,11 +21,11 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.security.GeneralSecurityException; -import java.util.BitSet; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; +import com.zaxxer.sparsebits.SparseBitSet; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.poifs.crypt.ChunkedCipherOutputStream; import org.apache.poi.poifs.crypt.CryptoFunctions; @@ -139,7 +139,7 @@ public class XOREncryptor extends Encryptor { final int start = Math.max(posInChunk-(recordEnd-recordStart), 0); - final BitSet plainBytes = getPlainByteFlags(); + final SparseBitSet plainBytes = getPlainByteFlags(); final byte[] xorArray = getEncryptionInfo().getEncryptor().getSecretKey().getEncoded(); final byte[] chunk = getChunk(); final byte[] plain = (plainBytes.isEmpty()) ? null : chunk.clone(); -- cgit v1.2.3