Harden oatdump like we did dexdump.

Bug: 6936283
Change-Id: Ia6bae922b2603e1a2539fe6f2c3b1d69c7594736
diff --git a/src/utils.cc b/src/utils.cc
index 6b93da8..0416e37 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -312,6 +312,9 @@
 }
 
 std::string PrettyField(uint32_t field_idx, const DexFile& dex_file, bool with_type) {
+  if (field_idx >= dex_file.NumFieldIds()) {
+    return StringPrintf("<<invalid-field-idx-%d>>", field_idx);
+  }
   const DexFile::FieldId& field_id = dex_file.GetFieldId(field_idx);
   std::string result;
   if (with_type) {
@@ -325,6 +328,9 @@
 }
 
 std::string PrettyType(uint32_t type_idx, const DexFile& dex_file) {
+  if (type_idx >= dex_file.NumTypeIds()) {
+    return StringPrintf("<<invalid-type-idx-%d>>", type_idx);
+  }
   const DexFile::TypeId& type_id = dex_file.GetTypeId(type_idx);
   return PrettyDescriptor(dex_file.GetTypeDescriptor(type_id));
 }
@@ -383,6 +389,9 @@
 }
 
 std::string PrettyMethod(uint32_t method_idx, const DexFile& dex_file, bool with_signature) {
+  if (method_idx >= dex_file.NumMethodIds()) {
+    return StringPrintf("<<invalid-method-idx-%d>>", method_idx);
+  }
   const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx);
   std::string result(PrettyDescriptor(dex_file.GetMethodDeclaringClassDescriptor(method_id)));
   result += '.';