浏览代码

ZOOKEEPER-201. validate magic number when reading snapshot and transaction

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@706718 13f79535-47bb-0310-9956-ffa450edef68
Patrick D. Hunt 16 年之前
父节点
当前提交
a79aaf38e4

+ 3 - 0
CHANGES.txt

@@ -35,6 +35,9 @@ Backward compatibile changes:
 
   BUGFIXES: 
 
+  ZOOKEEPER-201. validate magic number when reading snapshot and transaction
+  logs (mahadev via phunt)
+
   ZOOKEEPER-200. the magic number for snapshot and log must be different
   (currently same) (phunt)
 

+ 5 - 0
src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java

@@ -94,6 +94,11 @@ public class FileSnap implements SnapShot {
             InputArchive ia) throws IOException {
         FileHeader header = new FileHeader();
         header.deserialize(ia, "fileheader");
+        if (header.getMagic() != SNAP_MAGIC) {
+            throw new IOException("mismatching magic headers "
+                    + header.getMagic() + 
+                    " !=  " + FileSnap.SNAP_MAGIC);
+        }
         SerializeUtils.deserializeSnapshot(dt,ia,sessions);
     }
 

+ 6 - 2
src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java

@@ -384,6 +384,10 @@ public class FileTxnLog implements TxnLog {
             throws IOException{
             FileHeader header= new FileHeader();
             header.deserialize(ia, "fileheader");
+            if (header.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
+                throw new IOException("Invalid magic number " + header.getMagic() 
+                        + " != " + FileTxnLog.TXNLOG_MAGIC);
+            }  
         }
         
         /**
@@ -395,10 +399,10 @@ public class FileTxnLog implements TxnLog {
         protected InputArchive createInputArchive(File logFile) throws IOException {
             if(inputStream==null){
                 inputStream= new FileInputStream(logFile);
-                LOG.info("Created new input stream " + logFile);
+                LOG.debug("Created new input stream " + logFile);
                 ia  = BinaryInputArchive.getArchive(new BufferedInputStream(inputStream));
                 inStreamCreated(ia,inputStream);
-                LOG.info("created new input archive " + logFile);
+                LOG.debug("created new input archive " + logFile);
             }
             return ia;
         }