Prevent runtime from using messages with version 127 (#29807)

This commit is contained in:
Alexey Skibin 2023-02-13 10:12:34 -05:00 committed by GitHub
parent b3778d5044
commit cb7fed6fae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 11 deletions

View File

@ -266,18 +266,26 @@ impl<'de> Deserialize<'de> for VersionedMessage {
}))
}
MessagePrefix::Versioned(version) => {
if version == 0 {
Ok(VersionedMessage::V0(seq.next_element()?.ok_or_else(
|| {
// will never happen since tuple length is always 2
de::Error::invalid_length(1, &self)
},
)?))
} else {
Err(de::Error::invalid_value(
match version {
0 => {
Ok(VersionedMessage::V0(seq.next_element()?.ok_or_else(
|| {
// will never happen since tuple length is always 2
de::Error::invalid_length(1, &self)
},
)?))
}
127 => {
// 0xff is used as the first byte of the off-chain messages
// which corresponds to version 127 of the versioned messages.
// This explicit check is added to prevent the usage of version 127
// in the runtime as a valid transaction.
Err(de::Error::custom("off-chain messages are not accepted"))
}
_ => Err(de::Error::invalid_value(
de::Unexpected::Unsigned(version as u64),
&"supported versions: [0]",
))
&"a valid transaction message version",
)),
}
}
}