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 13:36:12 UTC

svn commit: r1852451 - in /jackrabbit/oak/trunk/oak-store-document/src: main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java

Author: reschke
Date: Tue Jan 29 13:36:12 2019
New Revision: 1852451

URL: http://svn.apache.org/viewvc?rev=1852451&view=rev
Log:
OAK-8007: RDBDocumentStore: potential off-heap memory leakage due to unclosed GzipInputStream

Modified:
    jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
    jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java

Modified: jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java?rev=1852451&r1=1852450&r2=1852451&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java Tue Jan 29 13:36:12 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/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java?rev=1852451&r1=1852450&r2=1852451&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java Tue Jan 29 13:36:12 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) {
+        }
+    }
 }