Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: snapshot/minidump/minidump_simple_string_dictionary_reader.cc

Issue 932153003: Add ProcessSnapshotMinidump, the beginning of the minidump variant of the Snapshot family (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "snapshot/minidump/minidump_simple_string_dictionary_reader.h"
16
17 #include <vector>
18 #include <utility>
19
20 #include "base/logging.h"
21 #include "minidump/minidump_extensions.h"
22 #include "snapshot/minidump/minidump_string_reader.h"
23
24 namespace crashpad {
25 namespace internal {
26
27 bool ReadMinidumpSimpleStringDictionary(
28 FileReaderInterface* file_reader,
29 const MINIDUMP_LOCATION_DESCRIPTOR& location,
30 std::map<std::string, std::string>* dictionary) {
31 if (location.Rva == 0) {
32 dictionary->clear();
33 return true;
34 }
35
36 if (location.DataSize < sizeof(MinidumpSimpleStringDictionary)) {
37 LOG(ERROR) << "simple_string_dictionary size mismatch";
38 return false;
39 }
40
41 FileOffset original_offset = file_reader->SeekGet();
42 if (original_offset < 0) {
43 return false;
44 }
45
46 if (!file_reader->SeekSet(location.Rva)) {
47 return false;
48 }
49
50 MinidumpSimpleStringDictionary simple_string_dictionary_base;
51 if (!file_reader->ReadExactly(&simple_string_dictionary_base,
52 sizeof(simple_string_dictionary_base))) {
53 return false;
54 }
55
56 if (location.DataSize !=
57 simple_string_dictionary_base.count *
58 sizeof(simple_string_dictionary_base.entries[0])) {
59 LOG(ERROR) << "simple_string_dictionary size mismatch";
60 return false;
61 }
62
63 std::vector<MinidumpSimpleStringDictionaryEntry> entries(
64 simple_string_dictionary_base.count);
65 if (!file_reader->ReadExactly(
66 &entries[0],
67 simple_string_dictionary_base.count * sizeof(entries[0]))) {
68 return false;
69 }
70
71 std::map<std::string, std::string> local_dictionary;
72 for (const MinidumpSimpleStringDictionaryEntry& entry : entries) {
73 std::string key;
74 if (!ReadMinidumpUTF8String(file_reader, entry.key, &key)) {
75 // Not a hard error, keep trying.
76 continue;
77 }
78
79 std::string value;
80 if (!ReadMinidumpUTF8String(file_reader, entry.value, &value)) {
81 // Not a hard error, keep trying.
82 continue;
83 }
84
85 if (local_dictionary.find(key) != local_dictionary.end()) {
86 LOG(WARNING) << "duplicate key " << key << ", discarding value " << value;
87 continue;
88 }
89
90 local_dictionary.insert(std::make_pair(key, value));
91 }
92
93 if (!file_reader->SeekSet(original_offset)) {
94 return false;
95 }
96
97 dictionary->swap(local_dictionary);
98 return true;
99 }
100
101 } // namespace internal
102 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698