From 22ad482e57e1a5e8322b6cbabef6f7f3ea890e7d Mon Sep 17 00:00:00 2001 From: smiley Date: Mon, 26 Sep 2022 00:07:06 +0200 Subject: [PATCH] :octocat: QRFpdf: proper value check/clamp --- src/Output/QRFpdf.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Output/QRFpdf.php b/src/Output/QRFpdf.php index 31c686c42..977312446 100644 --- a/src/Output/QRFpdf.php +++ b/src/Output/QRFpdf.php @@ -15,7 +15,7 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\Settings\SettingsContainerInterface; use FPDF; -use function array_values, class_exists, count, is_array; +use function array_values, class_exists, count, is_array, is_numeric, max, min; /** * QRFpdf output module (requires fpdf) @@ -48,14 +48,33 @@ class QRFpdf extends QROutputAbstract{ * @inheritDoc */ protected function moduleValueIsValid($value):bool{ - return is_array($value) && count($value) >= 3; + + if(!is_array($value) || count($value) < 3){ + return false; + } + + // check the first 3 values of the array + for($i = 0; $i < 3; $i++){ + if(!is_numeric($value[$i])){ + return false; + } + } + + return true; } /** * @inheritDoc */ protected function getModuleValue($value):array{ - return array_values($value); + $v = []; + + for($i = 0; $i < 3; $i++){ + // clamp value + $v[] = (int)max(0, min(255, $value[$i])); + } + + return $v; } /**