Don't crash on invalid string/type ids.

Bug: http://code.google.com/p/android/issues/detail?id=35934
Change-Id: I7bf31f6c80c794beb3554ad2f60ed5ebbca0c65e
diff --git a/dexdump/DexDump.cpp b/dexdump/DexDump.cpp
index 31fd1f8..6ecf671 100644
--- a/dexdump/DexDump.cpp
+++ b/dexdump/DexDump.cpp
@@ -764,12 +764,21 @@
                 width, index);
         break;
     case kIndexTypeRef:
-        outSize = snprintf(buf, bufSize, "%s // type@%0*x",
-                getClassDescriptor(pDexFile, index), width, index);
+        if (index < pDexFile->pHeader->typeIdsSize) {
+            outSize = snprintf(buf, bufSize, "%s // type@%0*x",
+                               getClassDescriptor(pDexFile, index), width, index);
+        } else {
+            outSize = snprintf(buf, bufSize, "<type?> // type@%0*x", width, index);
+        }
         break;
     case kIndexStringRef:
-        outSize = snprintf(buf, bufSize, "\"%s\" // string@%0*x",
-                dexStringById(pDexFile, index), width, index);
+        if (index < pDexFile->pHeader->stringIdsSize) {
+            outSize = snprintf(buf, bufSize, "\"%s\" // string@%0*x",
+                               dexStringById(pDexFile, index), width, index);
+        } else {
+            outSize = snprintf(buf, bufSize, "<string?> // string@%0*x",
+                               width, index);
+        }
         break;
     case kIndexMethodRef:
         {