From 8cd48574a755bea86243e9f9eabaee341ecf9c60 Mon Sep 17 00:00:00 2001 From: Gilles Debunne Date: Thu, 15 Jul 2010 18:06:36 -0700 Subject: [PATCH] Fixed bug in BitmapFactory.decodeStream Downloading images over a slow connection could result in errors and null images. The JavaInputStreamAdaptor::do_skip method was correctly called in a loop (to handle the EOF case using read()), but the amount that was skipped at each time was not decreased by the amount already skipped. Bug http://code.google.com/p/android/issues/detail?id=6066 Cherry picked from master CL57808 Change-Id: Ie6856898b21ba31de1209e1f995b4ae784c919b9 --- .../android/graphics/CreateJavaOutputStreamAdaptor.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp index a285def804a62..007757f4361f5 100644 --- a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp +++ b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp @@ -52,7 +52,7 @@ public: return 0; } - if (n <= 0) { + if (n < 0) { // n == 0 should not be possible, see InputStream read() specifications. break; // eof } @@ -76,17 +76,19 @@ public: size_t doSkip(size_t size) { JNIEnv* env = fEnv; + jlong skipped = env->CallLongMethod(fJavaInputStream, gInputStream_skipMethodID, (jlong)size); if (env->ExceptionCheck()) { env->ExceptionDescribe(); env->ExceptionClear(); - SkDebugf("------- available threw an exception\n"); + SkDebugf("------- skip threw an exception\n"); return 0; } if (skipped < 0) { skipped = 0; } + return (size_t)skipped; } @@ -115,7 +117,7 @@ public: */ size_t amountSkipped = 0; do { - size_t amount = this->doSkip(size); + size_t amount = this->doSkip(size - amountSkipped); if (0 == amount) { char tmp; amount = this->doRead(&tmp, 1);