[RFC PATCH 3/6] libcamera: yaml_parser: Increase sentinel to 100k

Jacopo Mondi jacopo.mondi at ideasonboard.com
Wed Jul 24 15:13:21 CEST 2024


I admin I have no idea how good or bad 100k is as a limit

On Fri, Jul 12, 2024 at 10:59:17AM GMT, Umang Jain wrote:
> From: Xavier Roumegue <xavier.roumegue at oss.nxp.com>
>
> Instead of manually increasing the limit, prepare a constexpr
> for maximum sentinel and use that instead.
>
> Signed-off-by: Xavier Roumegue <xavier.roumegue at oss.nxp.com>
> Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
> ---
>  src/libcamera/yaml_parser.cpp | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp
> index 025006bc..09ed75f1 100644
> --- a/src/libcamera/yaml_parser.cpp
> +++ b/src/libcamera/yaml_parser.cpp
> @@ -690,6 +690,8 @@ void YamlParserContext::readValue(std::string &value, EventPtr event)
>  int YamlParserContext::parseDictionaryOrList(YamlObject::Type type,
>  					     const std::function<int(EventPtr event)> &parseItem)
>  {
> +	constexpr unsigned int maxSentinel = 100000;
> +
>  	yaml_event_type_t endEventType = YAML_SEQUENCE_END_EVENT;
>  	if (type == YamlObject::Type::Dictionary)
>  		endEventType = YAML_MAPPING_END_EVENT;
> @@ -698,7 +700,7 @@ int YamlParserContext::parseDictionaryOrList(YamlObject::Type type,
>  	 * Add a safety counter to make sure we don't loop indefinitely in case
>  	 * the YAML file is malformed.
>  	 */
> -	for (unsigned int sentinel = 2000; sentinel; sentinel--) {
> +	for (unsigned int sentinel = maxSentinel; sentinel; sentinel--) {
>  		auto evt = nextEvent();
>  		if (!evt)
>  			return -EINVAL;
> @@ -711,8 +713,9 @@ int YamlParserContext::parseDictionaryOrList(YamlObject::Type type,
>  			return ret;
>  	}
>
> -	LOG(YamlParser, Error) << "The YAML file contains a List or Dictionary"
> -				  " whose size exceeds the parser's limit (1000)";
> +	LOG(YamlParser, Error)
> +		<< "The YAML file contains a List or Dictionary whose size exceeds"
> +		<< " the parser's limit (" << maxSentinel << ")";
>
>  	return -EINVAL;
>  }
> --
> 2.45.0
>


More information about the libcamera-devel mailing list