Skip to content

Commit 4d90433

Browse files
authored
tp: fix pigweed detokenization with truncated formatting args (#5918)
1 parent 5e10a2f commit 4d90433

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/trace_processor/importers/proto/pigweed_detokenizer.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,21 @@ DetokenizedString::DetokenizedString(
216216
std::string DetokenizedString::Format() const {
217217
const auto args = format_string_.args();
218218
const auto fmt = format_string_.template_str();
219-
if (args.size() == 0) {
219+
if (args.empty()) {
220220
return fmt;
221221
}
222222

223223
std::string result;
224-
225224
result.append(fmt.substr(0, args[0].begin));
226225

227226
for (size_t i = 0; i < args.size(); i++) {
228-
result.append(args_formatted_[i]);
227+
// args_formatted_ can be shorter than args if the payload was truncated
228+
// before all expected arguments could be parsed.
229+
if (i < args_formatted_.size()) {
230+
result.append(args_formatted_[i]);
231+
} else {
232+
result.append("<ERROR>");
233+
}
229234
if (i < args.size() - 1) {
230235
result.append(fmt.substr(args[i].end, args[i + 1].begin - args[i].end));
231236
} else {

0 commit comments

Comments
 (0)