Avoid getLength in ico decoder.

Only call getLength() if hasLength() returned true. Otherwise, copy the
stream into an SkDynamicMemoryWStream and copy it into alloc'ed space.

Share common code between bmp and ico.

BUG=https://b.corp.google.com/issue?id=8432093
R=djsollen@google.com

Review URL: https://codereview.chromium.org/23330002

git-svn-id: http://skia.googlecode.com/svn/trunk@10850 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/images/SkImageDecoder_libico.cpp b/src/images/SkImageDecoder_libico.cpp
index b14e196..47fa729 100644
--- a/src/images/SkImageDecoder_libico.cpp
+++ b/src/images/SkImageDecoder_libico.cpp
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2006 The Android Open Source Project
  *
@@ -6,10 +5,10 @@
  * found in the LICENSE file.
  */
 
-
+#include "SkColorPriv.h"
 #include "SkImageDecoder.h"
 #include "SkStream.h"
-#include "SkColorPriv.h"
+#include "SkStreamHelpers.h"
 #include "SkTypes.h"
 
 class SkICOImageDecoder : public SkImageDecoder {
@@ -75,13 +74,14 @@
 
 bool SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode)
 {
-    size_t length = stream->getLength();
-    SkAutoMalloc autoMal(length);
-    unsigned char* buf = (unsigned char*)autoMal.get();
-    if (stream->read((void*)buf, length) != length) {
+    SkAutoMalloc autoMal;
+    const size_t length = CopyStreamToStorage(&autoMal, stream);
+    if (0 == length) {
         return false;
     }
 
+    unsigned char* buf = (unsigned char*)autoMal.get();
+
     //these should always be the same - should i use for error checking? - what about files that have some
     //incorrect values, but still decode properly?
     int reserved = read2Bytes(buf, 0);    // 0