Skip to content

Commit

Permalink
Ignore non-context tags in IM encoding instead of erroring out. (#17665)
Browse files Browse the repository at this point in the history
We don't want to preclude future encoding evolution using non-context
tags here (or expanding the set of what's considered to be a context
tag in some way that would not be detected as a context tag by downrev
code).
  • Loading branch information
bzbarsky-apple authored Apr 27, 2022
1 parent 4b985dd commit 4432d08
Show file tree
Hide file tree
Showing 30 changed files with 1,985 additions and 496 deletions.
5 changes: 4 additions & 1 deletion src/app/MessageDef/AttributeDataIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/AttributePathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/AttributeReportIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ CHIP_ERROR AttributeReportIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/AttributeStatusIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ CHIP_ERROR AttributeStatusIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/ClusterPathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ CHIP_ERROR ClusterPathIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/CommandDataIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ CHIP_ERROR CommandDataIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());

switch (tagNum)
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/CommandPathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrExit(chip::TLV::IsContextTag(reader.GetTag()), err = CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
switch (chip::TLV::TagNumFromTag(reader.GetTag()))
{
case kCsTag_EndpointId:
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/CommandStatusIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ CHIP_ERROR CommandStatusIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/DataVersionFilterIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ CHIP_ERROR DataVersionFilterIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/EventDataIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/EventFilterIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ CHIP_ERROR EventFilterIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/EventPathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ CHIP_ERROR EventPathIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/EventReportIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ CHIP_ERROR EventReportIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/EventStatusIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ CHIP_ERROR EventStatusIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/InvokeRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/InvokeResponseIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ CHIP_ERROR InvokeResponseIB::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/InvokeResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/ReadRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/ReportDataMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
10 changes: 8 additions & 2 deletions src/app/MessageDef/StatusIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ CHIP_ERROR StatusIB::Parser::DecodeStatusIB(StatusIB & aStatusIB) const
reader.Init(mReader);
while (CHIP_NO_ERROR == reader.Next())
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
switch (TLV::TagNumFromTag(reader.GetTag()))
{
case to_underlying(Tag::kStatus):
Expand Down Expand Up @@ -75,7 +78,10 @@ CHIP_ERROR StatusIB::Parser::CheckSchemaValidity() const
reader.Init(mReader);
while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
if (!(TagPresenceMask & (1 << to_underlying(Tag::kStatus))))
{
TagPresenceMask |= (1 << to_underlying(Tag::kStatus));
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/StatusResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ CHIP_ERROR StatusResponseMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
switch (TLV::TagNumFromTag(reader.GetTag()))
{
case to_underlying(Tag::kStatus):
Expand Down
6 changes: 5 additions & 1 deletion src/app/MessageDef/StructParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ CHIP_ERROR StructParser::CheckSchemaOrdering() const
bool first = true;
while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
// Just skip over non-context tags, for forward compat.
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
if (first || (preTagNum < tagNum))
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/SubscribeRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/SubscribeResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ CHIP_ERROR SubscribeResponseMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/TimedRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ CHIP_ERROR TimedRequestMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/WriteRequestMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ CHIP_ERROR WriteRequestMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/MessageDef/WriteResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ CHIP_ERROR WriteResponseMessage::Parser::CheckSchemaValidity() const

while (CHIP_NO_ERROR == (err = reader.Next()))
{
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), err = CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
switch (tagNum)
{
Expand Down
5 changes: 4 additions & 1 deletion src/app/zap-templates/partials/cluster-objects-struct.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
err = reader.EnterContainer(outer);
ReturnErrorOnFailure(err);
while ((err = reader.Next()) == CHIP_NO_ERROR) {
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
switch (TLV::TagNumFromTag(reader.GetTag()))
{
{{#zcl_struct_items}}
Expand Down
10 changes: 8 additions & 2 deletions src/app/zap-templates/templates/app/cluster-objects-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
ReturnErrorOnFailure(reader.EnterContainer(outer));
while ((err = reader.Next()) == CHIP_NO_ERROR) {
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
switch (TLV::TagNumFromTag(reader.GetTag()))
{
{{#zcl_command_arguments}}
Expand Down Expand Up @@ -111,7 +114,10 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
ReturnErrorOnFailure(reader.EnterContainer(outer));
while ((err = reader.Next()) == CHIP_NO_ERROR) {
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
if (!TLV::IsContextTag(reader.GetTag()))
{
continue;
}
switch (TLV::TagNumFromTag(reader.GetTag()))
{
{{#zcl_event_fields}}
Expand Down
Loading

0 comments on commit 4432d08

Please sign in to comment.