Better handling of empty/incomplete content stream
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 8 Jun 2010 22:39:49 +0000 (22:39 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 8 Jun 2010 22:39:49 +0000 (22:39 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1417 59b500cc-1b3d-0410-9834-0bbf25fbcc57

android/src/com/google/zxing/client/android/encode/QRCodeEncoder.java

index 5d1bbf8..ab2e421 100755 (executable)
@@ -139,8 +139,16 @@ final class QRCodeEncoder {
       Uri uri = (Uri)intent.getExtras().getParcelable(Intent.EXTRA_STREAM);
       InputStream stream = activity.getContentResolver().openInputStream(uri);
       int length = stream.available();
+      if (length <= 0) {
+        Log.w(TAG, "Content stream is empty");
+        return false;
+      }
       byte[] vcard = new byte[length];
       int bytesRead = stream.read(vcard, 0, length);
+      if (bytesRead < length) {
+        Log.w(TAG, "Unable to fully read available bytes from content stream");
+        return false;
+      }
       String vcardString = new String(vcard, 0, bytesRead, "UTF-8");
       Log.d(TAG, "Encoding share intent content:");
       Log.d(TAG, vcardString);