OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "minidump/minidump_extensions.h" | 21 #include "minidump/minidump_extensions.h" |
22 #include "snapshot/minidump/minidump_string_reader.h" | 22 #include "snapshot/minidump/minidump_string_reader.h" |
23 | 23 |
24 namespace crashpad { | 24 namespace crashpad { |
25 namespace internal { | 25 namespace internal { |
26 | 26 |
27 bool ReadMinidumpSimpleStringDictionary( | 27 bool ReadMinidumpSimpleStringDictionary( |
28 FileReaderInterface* file_reader, | 28 FileReaderInterface* file_reader, |
29 const MINIDUMP_LOCATION_DESCRIPTOR& location, | 29 const MINIDUMP_LOCATION_DESCRIPTOR& location, |
30 std::map<std::string, std::string>* dictionary) { | 30 std::map<std::string, std::string>* dictionary) { |
| 31 dictionary->clear(); |
| 32 |
31 if (location.Rva == 0) { | 33 if (location.Rva == 0) { |
32 dictionary->clear(); | |
33 return true; | 34 return true; |
34 } | 35 } |
35 | 36 |
36 if (location.DataSize < sizeof(MinidumpSimpleStringDictionary)) { | 37 if (location.DataSize < sizeof(MinidumpSimpleStringDictionary)) { |
37 LOG(ERROR) << "simple_string_dictionary size mismatch"; | 38 LOG(ERROR) << "simple_string_dictionary size mismatch"; |
38 return false; | 39 return false; |
39 } | 40 } |
40 | 41 |
41 if (!file_reader->SeekSet(location.Rva)) { | 42 if (!file_reader->SeekSet(location.Rva)) { |
42 return false; | 43 return false; |
43 } | 44 } |
44 | 45 |
45 uint32_t entry_count; | 46 uint32_t entry_count; |
46 if (!file_reader->ReadExactly(&entry_count, sizeof(entry_count))) { | 47 if (!file_reader->ReadExactly(&entry_count, sizeof(entry_count))) { |
47 return false; | 48 return false; |
48 } | 49 } |
49 | 50 |
50 if (location.DataSize != | 51 if (location.DataSize != |
51 entry_count * sizeof(MinidumpSimpleStringDictionaryEntry)) { | 52 sizeof(MinidumpSimpleStringDictionary) + |
| 53 entry_count * sizeof(MinidumpSimpleStringDictionaryEntry)) { |
52 LOG(ERROR) << "simple_string_dictionary size mismatch"; | 54 LOG(ERROR) << "simple_string_dictionary size mismatch"; |
53 return false; | 55 return false; |
54 } | 56 } |
55 | 57 |
56 std::vector<MinidumpSimpleStringDictionaryEntry> entries(entry_count); | 58 std::vector<MinidumpSimpleStringDictionaryEntry> entries(entry_count); |
57 if (!file_reader->ReadExactly(&entries[0], | 59 if (!file_reader->ReadExactly(&entries[0], |
58 entry_count * sizeof(entries[0]))) { | 60 entry_count * sizeof(entries[0]))) { |
59 return false; | 61 return false; |
60 } | 62 } |
61 | 63 |
62 std::map<std::string, std::string> local_dictionary; | 64 std::map<std::string, std::string> local_dictionary; |
63 for (const MinidumpSimpleStringDictionaryEntry& entry : entries) { | 65 for (const MinidumpSimpleStringDictionaryEntry& entry : entries) { |
64 std::string key; | 66 std::string key; |
65 if (!ReadMinidumpUTF8String(file_reader, entry.key, &key)) { | 67 if (!ReadMinidumpUTF8String(file_reader, entry.key, &key)) { |
66 // Not a hard error, keep trying. | 68 // Not a hard error, keep trying. |
67 continue; | 69 continue; |
68 } | 70 } |
69 | 71 |
70 std::string value; | 72 std::string value; |
71 if (!ReadMinidumpUTF8String(file_reader, entry.value, &value)) { | 73 if (!ReadMinidumpUTF8String(file_reader, entry.value, &value)) { |
72 // Not a hard error, keep trying. | 74 // Not a hard error, keep trying. |
73 continue; | 75 continue; |
74 } | 76 } |
75 | 77 |
76 if (local_dictionary.find(key) != local_dictionary.end()) { | 78 if (dictionary->find(key) != dictionary->end()) { |
77 LOG(WARNING) << "duplicate key " << key << ", discarding value " << value; | 79 LOG(WARNING) << "duplicate key " << key << ", discarding value " << value; |
78 continue; | 80 continue; |
79 } | 81 } |
80 | 82 |
81 local_dictionary.insert(std::make_pair(key, value)); | 83 dictionary->insert(std::make_pair(key, value)); |
82 } | 84 } |
83 | 85 |
84 dictionary->swap(local_dictionary); | |
85 return true; | 86 return true; |
86 } | 87 } |
87 | 88 |
88 } // namespace internal | 89 } // namespace internal |
89 } // namespace crashpad | 90 } // namespace crashpad |
OLD | NEW |