MapDBLog: clone byte[] before deserializing
- workaround for Kryo buffer underflow case
Change-Id: I0a9566f66fcd6fac3a91dda87f59d01fbed2d43a
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/MapDBLog.java b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/MapDBLog.java
index 0821b4d..3bdbe2a 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/MapDBLog.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/MapDBLog.java
@@ -146,7 +146,7 @@
DB db = txMaker.makeTx();
try {
BTreeMap<Long, byte[]> log = getLogMap(db);
- return log.isEmpty() ? null : verifyNotNull(serializer.decode(log.firstEntry().getValue()));
+ return log.isEmpty() ? null : verifyNotNull(decodeEntry(log.firstEntry().getValue()));
} finally {
db.close();
}
@@ -164,6 +164,13 @@
}
}
+ private <T extends Entry> T decodeEntry(final byte[] bytes) {
+ if (bytes == null) {
+ return null;
+ }
+ return serializer.decode(bytes.clone());
+ }
+
@Override
public <T extends Entry> List<T> getEntries(long from, long to) {
assertIsOpen();
@@ -179,7 +186,7 @@
}
List<T> entries = new ArrayList<>((int) (to - from + 1));
for (long i = from; i <= to; i++) {
- T entry = verifyNotNull(serializer.decode(log.get(i)), "LogEntry %s was null", i);
+ T entry = verifyNotNull(decodeEntry(log.get(i)), "LogEntry %s was null", i);
entries.add(entry);
}
return entries;
@@ -195,7 +202,7 @@
try {
BTreeMap<Long, byte[]> log = getLogMap(db);
byte[] entryBytes = log.get(index);
- return entryBytes == null ? null : verifyNotNull(serializer.decode(entryBytes),
+ return entryBytes == null ? null : verifyNotNull(decodeEntry(entryBytes),
"LogEntry %s was null", index);
} finally {
db.close();
@@ -220,7 +227,7 @@
DB db = txMaker.makeTx();
try {
BTreeMap<Long, byte[]> log = getLogMap(db);
- return log.isEmpty() ? null : verifyNotNull(serializer.decode(log.lastEntry().getValue()));
+ return log.isEmpty() ? null : verifyNotNull(decodeEntry(log.lastEntry().getValue()));
} finally {
db.close();
}