Commit de6d9710 authored by Patrick D. Hunt's avatar Patrick D. Hunt
Browse files

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
parent de0fe6d9
......@@ -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)
......
......@@ -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);
}
......
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment