[v5,11/36] ipa: libipa: lsc_polynomial: Fix polynomial parsing error
diff mbox series

Message ID 20260708-libipa-algorithms-v5-11-0759d0359f52@ideasonboard.com
State Superseded
Headers show
Series
  • ipa: libipa: Introduce libipa algorithms
Related show

Commit Message

Jacopo Mondi July 8, 2026, 3:50 p.m. UTC
If any of the polynomial component is missing in the tuning file the
ValueNode::Accessor<ipa::LscPolynomial> specialization emits an
error message but continues and dereferences a potentially
invalid object.

Fix it by returning std::nullopt if a polynomial component is missing.

The caller already checks if the returned value is valid or not, causing
the algorithm initialization to fail if the tuning file is invalid.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/libipa/lsc_polynomial.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Kieran Bingham July 9, 2026, 1:04 p.m. UTC | #1
Quoting Jacopo Mondi (2026-07-08 16:50:53)
> If any of the polynomial component is missing in the tuning file the
> ValueNode::Accessor<ipa::LscPolynomial> specialization emits an
> error message but continues and dereferences a potentially
> invalid object.
> 
> Fix it by returning std::nullopt if a polynomial component is missing.
> 
> The caller already checks if the returned value is valid or not, causing
> the algorithm initialization to fail if the tuning file is invalid.
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>


Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/ipa/libipa/lsc_polynomial.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/ipa/libipa/lsc_polynomial.h b/src/ipa/libipa/lsc_polynomial.h
> index d7d9ae42e360..a0d27c4b21d6 100644
> --- a/src/ipa/libipa/lsc_polynomial.h
> +++ b/src/ipa/libipa/lsc_polynomial.h
> @@ -94,9 +94,11 @@ struct ValueNode::Accessor<ipa::LscPolynomial> {
>                 std::optional<double> k3 = obj["k3"].get<double>();
>                 std::optional<double> k4 = obj["k4"].get<double>();
>  
> -               if (!(cx && cy && k0 && k1 && k2 && k3 && k4))
> +               if (!(cx && cy && k0 && k1 && k2 && k3 && k4)) {
>                         LOG(LscPolynomial, Error)
>                                 << "Polynomial is missing a parameter";
> +                       return std::nullopt;
> +               }
>  
>                 return ipa::LscPolynomial(*cx, *cy, *k0, *k1, *k2, *k3, *k4);
>         }
> 
> -- 
> 2.54.0
>
Stefan Klug July 13, 2026, 1:19 p.m. UTC | #2
Hi Jacopo,

Quoting Jacopo Mondi (2026-07-08 17:50:53)
> If any of the polynomial component is missing in the tuning file the
> ValueNode::Accessor<ipa::LscPolynomial> specialization emits an
> error message but continues and dereferences a potentially
> invalid object.
> 
> Fix it by returning std::nullopt if a polynomial component is missing.
> 
> The caller already checks if the returned value is valid or not, causing
> the algorithm initialization to fail if the tuning file is invalid.
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>  src/ipa/libipa/lsc_polynomial.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/ipa/libipa/lsc_polynomial.h b/src/ipa/libipa/lsc_polynomial.h
> index d7d9ae42e360..a0d27c4b21d6 100644
> --- a/src/ipa/libipa/lsc_polynomial.h
> +++ b/src/ipa/libipa/lsc_polynomial.h
> @@ -94,9 +94,11 @@ struct ValueNode::Accessor<ipa::LscPolynomial> {
>                 std::optional<double> k3 = obj["k3"].get<double>();
>                 std::optional<double> k4 = obj["k4"].get<double>();
>  
> -               if (!(cx && cy && k0 && k1 && k2 && k3 && k4))
> +               if (!(cx && cy && k0 && k1 && k2 && k3 && k4)) {
>                         LOG(LscPolynomial, Error)
>                                 << "Polynomial is missing a parameter";
> +                       return std::nullopt;

Good point.

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>

Regards,
Stefan

> +               }
>  
>                 return ipa::LscPolynomial(*cx, *cy, *k0, *k1, *k2, *k3, *k4);
>         }
> 
> -- 
> 2.54.0
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/lsc_polynomial.h b/src/ipa/libipa/lsc_polynomial.h
index d7d9ae42e360..a0d27c4b21d6 100644
--- a/src/ipa/libipa/lsc_polynomial.h
+++ b/src/ipa/libipa/lsc_polynomial.h
@@ -94,9 +94,11 @@  struct ValueNode::Accessor<ipa::LscPolynomial> {
 		std::optional<double> k3 = obj["k3"].get<double>();
 		std::optional<double> k4 = obj["k4"].get<double>();
 
-		if (!(cx && cy && k0 && k1 && k2 && k3 && k4))
+		if (!(cx && cy && k0 && k1 && k2 && k3 && k4)) {
 			LOG(LscPolynomial, Error)
 				<< "Polynomial is missing a parameter";
+			return std::nullopt;
+		}
 
 		return ipa::LscPolynomial(*cx, *cy, *k0, *k1, *k2, *k3, *k4);
 	}