From d09d4296da2cb91a5186c570025e66939777fb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 16 Oct 2014 13:36:21 +0200 Subject: Silently fail on import on key import with ArrayIndexOutOfBoundsException --- .../sufficientlysecure/keychain/pgp/UncachedKeyRing.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java index 2b2fbf4c2..a3ddd5325 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -41,6 +41,7 @@ import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Utf8Util; +import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -160,11 +161,15 @@ public class UncachedKeyRing { } try { - while(stream.available() > 0) { + while (stream.available() > 0) { // if there are no objects left from the last factory, create a new one if (mObjectFactory == null) { - mObjectFactory = new PGPObjectFactory(PGPUtil.getDecoderStream(stream), - new JcaKeyFingerprintCalculator()); + InputStream in = PGPUtil.getDecoderStream(stream); + if (!BufferedInputStream.class.isInstance(in)) { + in = new BufferedInputStream(in); + } + + mObjectFactory = new PGPObjectFactory(in, new JcaKeyFingerprintCalculator()); } // go through all objects in this block @@ -184,9 +189,10 @@ public class UncachedKeyRing { mObjectFactory = null; } } catch (IOException e) { - Log.e(Constants.TAG, "IOException while processing stream", e); + Log.e(Constants.TAG, "IOException while processing stream. ArmoredInputStream CRC check failed?", e); + } catch (ArrayIndexOutOfBoundsException e) { + Log.e(Constants.TAG, "ArmoredInputStream decode failed, symbol is not in decodingTable!", e); } - } @Override -- cgit v1.2.3