You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2019/01/29 17:48:45 UTC
svn commit: r1852465 - in /jackrabbit/oak/branches/1.10: ./
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/
oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/
Author: reschke
Date: Tue Jan 29 17:48:44 2019
New Revision: 1852465
URL: http://svn.apache.org/viewvc?rev=1852465&view=rev
Log:
OAK-8007: RDBDocumentStore: potential off-heap memory leakage due to unclosed GzipInputStream (ported to 2.10)
Modified:
jackrabbit/oak/branches/1.10/ (props changed)
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java
Propchange: jackrabbit/oak/branches/1.10/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 29 17:48:44 2019
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1851451,1852052,1852084
+/jackrabbit/oak/trunk:1851451,1852052,1852084,1852451
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java?rev=1852465&r1=1852464&r2=1852465&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java (original)
+++ jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java Tue Jan 29 17:48:44 2019
@@ -343,14 +343,15 @@ public class RDBDocumentSerializer {
try {
if (bdata.length >= 2 && bdata[0] == GZIPSIG[0] && bdata[1] == GZIPSIG[1]) {
// GZIP
- ByteArrayInputStream bis = new ByteArrayInputStream(bdata);
- GZIPInputStream gis = new GZIPInputStream(bis, 65536);
- return IOUtils.toString(gis, "UTF-8");
+ try (GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bdata), 65536)) {
+ return IOUtils.toString(gis, "UTF-8");
+ }
} else {
return IOUtils.toString(bdata, "UTF-8");
}
- } catch (IOException e) {
- throw new RuntimeException(e);
+ } catch (IOException ex) {
+ LOG.debug("Unexpected exception while processing blob data", ex);
+ throw new RuntimeException(ex);
}
}
}
Modified: jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java?rev=1852465&r1=1852464&r2=1852465&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java (original)
+++ jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java Tue Jan 29 17:48:44 2019
@@ -23,9 +23,12 @@ import static org.junit.Assert.assertNul
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
+import java.util.zip.GZIPOutputStream;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
@@ -85,6 +88,19 @@ public class RDBDocumentSerializerTest {
}
@Test
+ public void testSimpleBlobGzipped() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ GZIPOutputStream gos = new GZIPOutputStream(bos);
+ gos.write("{}".getBytes("UTF-8"));
+ gos.close();
+ RDBRow row = new RDBRow("_foo", 0L, false, 1l, 2l, 3l, 0L, 0L, 0L, "\"blob\"", bos.toByteArray());
+ NodeDocument doc = this.ser.fromRow(Collection.NODES, row);
+ assertEquals("_foo", doc.getId());
+ assertEquals(false, doc.hasBinary());
+ assertEquals(2L, doc.getModCount().longValue());
+ }
+
+ @Test
public void testSimpleBlob2() throws UnsupportedEncodingException {
RDBRow row = new RDBRow("_foo", 0L, false, 1l, 2l, 3l, 0L, 0L, 0L, "\"blob\"",
"{\"s\":\"string\", \"b\":true, \"i\":1}".getBytes("UTF-8"));
@@ -204,4 +220,15 @@ public class RDBDocumentSerializerTest {
}
}
}
+
+ @Test
+ public void testInvalidGzip() {
+ try {
+ byte[] bytes = { 31, -117, 1, 2, 3, 4 };
+ RDBRow row = new RDBRow("_foo", 0L, false, 1l, 2l, 3l, 0L, 0L, 0L, "\"blob\"", bytes);
+ this.ser.fromRow(Collection.NODES, row);
+ fail("should fail");
+ } catch (DocumentStoreException expected) {
+ }
+ }
}