avoid two NPEs on corrupt fragments

This commit is contained in:
zzz
2008-12-04 00:09:52 +00:00
parent 321f11c055
commit e9f27c60dd
2 changed files with 5 additions and 0 deletions

View File

@ -372,6 +372,8 @@ public class FragmentHandler {
int fragmentCount = msg.getFragmentCount();
// toByteArray destroys the contents of the message completely
byte data[] = msg.toByteArray();
if (data == null)
throw new I2NPMessageException("null data"); // fragments already released???
if (_log.shouldLog(Log.DEBUG))
_log.debug("RECV(" + data.length + "): " + Base64.encode(data)
+ " " + _context.sha().calculateHash(data).toBase64());

View File

@ -189,6 +189,9 @@ public class FragmentedMessage {
int size = 0;
for (int i = 0; i <= _highFragmentNum; i++) {
ByteArray ba = _fragments[i];
// NPE seen here, root cause unknown
if (ba == null)
throw new IllegalStateException("wtf, don't get the completed size when we're not complete - null fragment i=" + i + " of " + _highFragmentNum);
size += ba.getValid();
}
return size;