avoid two NPEs on corrupt fragments
This commit is contained in:
@ -372,6 +372,8 @@ public class FragmentHandler {
|
|||||||
int fragmentCount = msg.getFragmentCount();
|
int fragmentCount = msg.getFragmentCount();
|
||||||
// toByteArray destroys the contents of the message completely
|
// toByteArray destroys the contents of the message completely
|
||||||
byte data[] = msg.toByteArray();
|
byte data[] = msg.toByteArray();
|
||||||
|
if (data == null)
|
||||||
|
throw new I2NPMessageException("null data"); // fragments already released???
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("RECV(" + data.length + "): " + Base64.encode(data)
|
_log.debug("RECV(" + data.length + "): " + Base64.encode(data)
|
||||||
+ " " + _context.sha().calculateHash(data).toBase64());
|
+ " " + _context.sha().calculateHash(data).toBase64());
|
||||||
|
@ -189,6 +189,9 @@ public class FragmentedMessage {
|
|||||||
int size = 0;
|
int size = 0;
|
||||||
for (int i = 0; i <= _highFragmentNum; i++) {
|
for (int i = 0; i <= _highFragmentNum; i++) {
|
||||||
ByteArray ba = _fragments[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();
|
size += ba.getValid();
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
|
Reference in New Issue
Block a user