Skip to content

Commit 162acd5

Browse files
feat(ffi): Validate the type of user-defined metadata when deserializing the new IR format. (#695)
Co-authored-by: kirkrodrigues <[email protected]>
1 parent 4f0b596 commit 162acd5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

components/core/src/clp/ffi/ir_stream/Deserializer.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ class Deserializer {
4444
* @return A result containing the deserializer or an error code indicating the failure:
4545
* - std::errc::result_out_of_range if the IR stream is truncated
4646
* - std::errc::protocol_error if the IR stream is corrupted
47-
* - std::errc::protocol_not_supported if the IR stream contains an unsupported metadata format
48-
* or uses an unsupported version
47+
* - std::errc::protocol_not_supported if either:
48+
* - the IR stream contains an unsupported metadata format;
49+
* - the IR stream's version is unsupported;
50+
* - or the IR stream's user-defined metadata is not a JSON object.
4951
*/
5052
[[nodiscard]] static auto create(ReaderInterface& reader, IrUnitHandler ir_unit_handler)
5153
-> OUTCOME_V2_NAMESPACE::std_result<Deserializer>;
@@ -168,6 +170,12 @@ auto Deserializer<IrUnitHandler>::create(ReaderInterface& reader, IrUnitHandler
168170
return std::errc::protocol_not_supported;
169171
}
170172

173+
if (metadata_json.contains(cProtocol::Metadata::UserDefinedMetadataKey)
174+
&& false == metadata_json.at(cProtocol::Metadata::UserDefinedMetadataKey).is_object())
175+
{
176+
return std::errc::protocol_not_supported;
177+
}
178+
171179
return Deserializer{std::move(ir_unit_handler), std::move(metadata_json)};
172180
}
173181

0 commit comments

Comments
 (0)