zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1176154 - in /zookeeper/branches/branch-3.3: CHANGES.txt src/java/main/org/apache/zookeeper/server/persistence/Util.java src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java
Date Tue, 27 Sep 2011 01:11:05 GMT
Author: mahadev
Date: Tue Sep 27 01:11:05 2011
New Revision: 1176154

URL: http://svn.apache.org/viewvc?rev=1176154&view=rev
Log:
ZOOKEEPER-1189. For an invalid snapshot file(less than 10bytes size) RandomAccessFile stream
is leaking. (Rakesh R via mahadev)

Modified:
    zookeeper/branches/branch-3.3/CHANGES.txt
    zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/Util.java
    zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java

Modified: zookeeper/branches/branch-3.3/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/CHANGES.txt?rev=1176154&r1=1176153&r2=1176154&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.3/CHANGES.txt Tue Sep 27 01:11:05 2011
@@ -22,6 +22,9 @@ BUGFIXES:
   
   ZOOKEEPER-1160. test timeouts are too small (breed via camille)
  
+  ZOOKEEPER-1189. For an invalid snapshot file(less than 10bytes size)
+  RandomAccessFile stream is leaking. (Rakesh R via mahadev)
+ 
 Release 3.3.3 - 2011-02-23
 Backward compatible changes:
 

Modified: zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/Util.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/Util.java?rev=1176154&r1=1176153&r2=1176154&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/Util.java
(original)
+++ zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/Util.java
Tue Sep 27 01:11:05 2011
@@ -163,12 +163,12 @@ public class Util {
 
         // Check for a valid snapshot
         RandomAccessFile raf = new RandomAccessFile(f, "r");
-        // including the header and the last / bytes
-        // the snapshot should be atleast 10 bytes
-        if (raf.length() < 10) {
-            return false;
-        }
         try {
+            // including the header and the last / bytes
+            // the snapshot should be atleast 10 bytes
+            if (raf.length() < 10) {
+                return false;
+            }
             raf.seek(raf.length() - 5);
             byte bytes[] = new byte[5];
             int readlen = 0;

Modified: zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java?rev=1176154&r1=1176153&r2=1176154&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java
(original)
+++ zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java
Tue Sep 27 01:11:05 2011
@@ -19,12 +19,14 @@
 package org.apache.zookeeper.server;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
 import junit.framework.TestCase;
 
 import org.apache.zookeeper.server.persistence.FileTxnLog;
 import org.apache.zookeeper.server.persistence.Util;
+import org.apache.zookeeper.test.ClientBase;
 import org.junit.Test;
 import org.junit.Assert;
 
@@ -114,4 +116,25 @@ public class ZooKeeperServerTest extends
         }
     }
 
+    @Test
+    public void testInvalidSnapshot() {
+        File f = null;
+        File tmpFileDir = null;
+        try {
+            tmpFileDir = ClientBase.createTmpDir();
+            f = new File(tmpFileDir, "snapshot.0");
+            if (!f.exists()) {
+                f.createNewFile();
+            }
+            Assert.assertFalse("Snapshot file size is greater than 9 bytes",
+                    Util.isValidSnapshot(f));
+            Assert.assertTrue("Can't delete file", f.delete());
+        } catch (IOException e) {
+        } finally {
+            if (null != tmpFileDir) {
+                ClientBase.recursiveDelete(tmpFileDir);
+            }
+        }
+    }
+
 }



Mime
View raw message