Skip to content

Commit

Permalink
Increase value buffer size for payload decoding, make sure overflows …
Browse files Browse the repository at this point in the history
…are shown. (#28873)

* Add overflow marker and make buffer for value output huge

* Fix comment

* Fix unit tests
  • Loading branch information
andy31415 authored and pull[bot] committed Nov 6, 2023
1 parent e2afc00 commit f7ed8aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/lib/format/protocol_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ void PrettyPrintCurrentValue(const TLVReader & reader, chip::StringBuilderBase &
out.AddFormat(" | 0x%08" PRIX64, value);
}
}

out.AddMarkerIfOverflow();
}

} // namespace
Expand Down
4 changes: 2 additions & 2 deletions src/lib/format/tests/TestDecoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
TestSampleData(inSuite, params, secure_channel_pase_pake1,
// clang-format off
"pase_pake1\n"
" pA: hex:0422ABC7A84352850456BD4A510905FE6BB782A0863A9382550E1228020801B22EEC4102C60F80082842B9739705FCD37F134651442A41E3723DFFE0278\n"
" pA: hex:0422ABC7A84352850456BD4A510905FE6BB782A0863A9382550E1228020801B22EEC4102C60F80082842B9739705FCD37F134651442A41E3723DFFE0...\n"
// clang-format on
);
TestSampleData(inSuite, params, secure_channel_pase_pake2,
// clang-format off
"pase_pake2\n"
" pB: hex:04B6A44A3347C6B77900A3674CA19F40F25F056F8CB344EC1B4FA7888B9E6B570B7010431C5D0BE4021FE74A96C40721765FDA6802BE8DFDF5624332275\n"
" pB: hex:04B6A44A3347C6B77900A3674CA19F40F25F056F8CB344EC1B4FA7888B9E6B570B7010431C5D0BE4021FE74A96C40721765FDA6802BE8DFDF5624332...\n"
" cB: hex:40E7452275E38AEBAF0E0F6FAB33A1B0CB5AEB5E824230DD40D0071DC7E55C87\n"
// clang-format on
);
Expand Down
18 changes: 10 additions & 8 deletions src/tracing/json/json_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <tracing/json/json_tracing.h>

#include <lib/address_resolve/TracingStructs.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/ErrorStr.h>
#include <lib/support/StringBuilder.h>
#include <transport/TracingStructs.h>
Expand Down Expand Up @@ -54,7 +55,7 @@ using chip::StringBuilder;

using namespace chip::Decoders;

using PayloadDecoderType = chip::Decoders::PayloadDecoder<64, 256>;
using PayloadDecoderType = chip::Decoders::PayloadDecoder<64, 2048>;

/// Figures out a unique name within a json object.
///
Expand Down Expand Up @@ -226,15 +227,16 @@ void DecodePayloadData(::Json::Value & value, chip::ByteSpan payload, Protocols:

#if MATTER_LOG_JSON_DECODE_FULL

PayloadDecoderType decoder(PayloadDecoderInitParams()
.SetProtocolDecodeTree(chip::TLVMeta::protocols_meta)
.SetClusterDecodeTree(chip::TLVMeta::clusters_meta)
.SetProtocol(protocolId)
.SetMessageType(messageType));
// As PayloadDecoder is quite large (large strings buffers), we place it in heap
auto decoder = chip::Platform::MakeUnique<PayloadDecoderType>(PayloadDecoderInitParams()
.SetProtocolDecodeTree(chip::TLVMeta::protocols_meta)
.SetClusterDecodeTree(chip::TLVMeta::clusters_meta)
.SetProtocol(protocolId)
.SetMessageType(messageType));

decoder.StartDecoding(payload);
decoder->StartDecoding(payload);

value["decoded"] = GetPayload(decoder);
value["decoded"] = GetPayload(*decoder);
#endif // MATTER_LOG_JSON_DECODE_FULL
}

Expand Down

0 comments on commit f7ed8aa

Please sign in to comment.