Skip to content

Commit b60ca78

Browse files
committed
Moved creation of RubyString inside generateString, this avoid to keep alive a reference to a 2GB Java String
1 parent 3e0f488 commit b60ca78

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

logstash-core/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ tasks.register("javaTests", Test) {
124124
exclude '/org/logstash/plugins/factory/PluginFactoryExtTest.class'
125125
exclude '/org/logstash/execution/ObservedExecutionTest.class'
126126

127-
maxHeapSize = "12g"
127+
maxHeapSize = "10g"
128+
jvmArgs '-XX:+HeapDumpOnOutOfMemoryError'
128129

129130
jacoco {
130131
enabled = true

logstash-core/src/test/java/org/logstash/common/BufferedTokenizerExtWithSizeLimitTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,25 @@ public void giveMultipleSegmentsThatGeneratesMultipleBufferFullErrorsThenIsAbleT
117117
@Test
118118
public void givenMaliciousInputExtractDoesntOverflow() {
119119
assertEquals("Xmx must equals to what's defined in the Gradle's javaTests task",
120-
12L * GB, Runtime.getRuntime().maxMemory());
120+
10L * GB, Runtime.getRuntime().maxMemory());
121121

122122
// re-init the tokenizer with big sizeLimit
123123
initSUTWithSizeLimit((int) (2L * GB) - 3);
124124
// Integer.MAX_VALUE is 2 * GB
125-
String bigFirstPiece = generateString("a", Integer.MAX_VALUE - 1024);
126-
sut.extract(context, RubyUtil.RUBY.newString(bigFirstPiece));
125+
RubyString bigFirstPiece = generateString("a", Integer.MAX_VALUE - 1024);
126+
sut.extract(context, bigFirstPiece);
127127

128128
// add another small fragment to trigger int overflow
129129
// sizeLimit is (2^32-1)-3 first segment length is (2^32-1) - 1024 second is 1024 +2
130-
// so the combined length of first and second is > sizeLimit and should throw an expection
130+
// so the combined length of first and second is > sizeLimit and should throw an exception
131131
// but because of overflow it's negative and happens to be < sizeLimit
132132
Exception thrownException = assertThrows(IllegalStateException.class, () -> {
133-
sut.extract(context, RubyUtil.RUBY.newString(generateString("a", 1024 + 2)));
133+
sut.extract(context, generateString("a", 1024 + 2));
134134
});
135135
assertThat(thrownException.getMessage(), containsString("input buffer full"));
136136
}
137137

138-
private String generateString(String fill, int size) {
139-
return fill.repeat(size);
138+
private RubyString generateString(String fill, int size) {
139+
return RubyUtil.RUBY.newString(fill.repeat(size));
140140
}
141141
}

0 commit comments

Comments
 (0)