[RFC,3/6] libcamera: yaml_parser: Increase sentinel to 100k
diff mbox series

Message ID 20240712052920.33396-4-umang.jain@ideasonboard.com
State Not Applicable
Headers show
Series
  • converter_dw100: Add vertex map support
Related show

Commit Message

Umang Jain July 12, 2024, 5:29 a.m. UTC
From: Xavier Roumegue <xavier.roumegue@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@oss.nxp.com>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 src/libcamera/yaml_parser.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Jacopo Mondi July 24, 2024, 1:13 p.m. UTC | #1
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@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@oss.nxp.com>
> Signed-off-by: Umang Jain <umang.jain@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
>
Laurent Pinchart Aug. 2, 2024, 10:36 p.m. UTC | #2
On Wed, Jul 24, 2024 at 03:13:21PM +0200, Jacopo Mondi wrote:
> I admin I have no idea how good or bad 100k is as a limit

Do we really need 100k ?

> On Fri, Jul 12, 2024 at 10:59:17AM GMT, Umang Jain wrote:
> > From: Xavier Roumegue <xavier.roumegue@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@oss.nxp.com>
> > Signed-off-by: Umang Jain <umang.jain@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;

s/maxSentinel/kMaxSentinel/

static constexpr ?

> > +
> >  	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;
> >  }

Patch
diff mbox series

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;
 }