Skip to content

Apache Lucene open-source search software

SOLR-7971: Reduce memory allocated by JavaBinCodec to encode large strings by an amount equal to the string.length()

Shalin Shekhar Mangar2330786c5a4f
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 237a172556b..ef834bd7db6 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -168,6 +168,10 @@ Optimizations
are more efficient especially when cluster has a mix of collections in stateFormat=1
and stateFormat=2. (Scott Blum, shalin)
+* SOLR-7971: Reduce memory allocated by JavaBinCodec to encode large strings by an amount
+ equal to the string.length().
+ (yonik, Steve Rowe, shalin)
+
Other Changes
----------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
index 456b2762e5f..b5401b76b05 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
@@ -614,7 +614,7 @@ public class JavaBinCodec {
return;
}
int end = s.length();
- int maxSize = end * 4;
+ int maxSize = end * 3; // 3 is enough, see SOLR-7971
if (bytes == null || bytes.length < maxSize) bytes = new byte[maxSize];
int sz = ByteUtils.UTF16toUTF8(s, 0, end, bytes, 0);