JPEG/R: add restriction to max_display_boost input from user
Bug: b/264715926
Change-Id: I82c24c285fb01cab57ec004f1440ac9b5adacc39
(cherry picked from commit 4e49f18a515173523992f359a6a74feeb7b822a7)
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h
index 1ab1dd7..6262e18 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h
+++ b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h
@@ -19,6 +19,10 @@
#include "jpegrerrorcode.h"
+#ifndef FLT_MAX
+#define FLT_MAX 0x1.fffffep127f
+#endif
+
namespace android::jpegrecoverymap {
// Color gamuts for image data
@@ -206,7 +210,8 @@
*
* @param compressed_jpegr_image compressed JPEGR image.
* @param dest destination of the uncompressed JPEGR image.
- * @param max_display_boost (optional) the maximum available boost supported by a display
+ * @param max_display_boost (optional) the maximum available boost supported by a display,
+ * the value must be greater than or equal to 1.0.
* @param exif destination of the decoded EXIF metadata. The default value is NULL where the
decoder will do nothing about it. If configured not NULL the decoder will write
EXIF data into this structure. The format is defined in {@code jpegr_exif_struct}
@@ -235,7 +240,7 @@
*/
status_t decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
jr_uncompressed_ptr dest,
- float max_display_boost = -1.0f,
+ float max_display_boost = FLT_MAX,
jr_exif_ptr exif = nullptr,
jpegr_output_format output_format = JPEGR_OUTPUT_HDR_LINEAR,
jr_uncompressed_ptr recovery_map = nullptr,
diff --git a/libs/jpegrecoverymap/jpegr.cpp b/libs/jpegrecoverymap/jpegr.cpp
index 559ca35..d147130 100644
--- a/libs/jpegrecoverymap/jpegr.cpp
+++ b/libs/jpegrecoverymap/jpegr.cpp
@@ -339,6 +339,10 @@
return ERROR_JPEGR_INVALID_NULL_PTR;
}
+ if (max_display_boost < 1.0f) {
+ return ERROR_JPEGR_INVALID_INPUT_TYPE;
+ }
+
if (output_format == JPEGR_OUTPUT_SDR) {
JpegDecoderHelper jpeg_decoder;
if (!jpeg_decoder.decompressImage(compressed_jpegr_image->data, compressed_jpegr_image->length,
@@ -683,9 +687,7 @@
dest->width = uncompressed_yuv_420_image->width;
dest->height = uncompressed_yuv_420_image->height;
ShepardsIDW idwTable(kMapDimensionScaleFactor);
- float display_boost = max_display_boost > 0 ?
- std::min(max_display_boost, metadata->maxContentBoost)
- : metadata->maxContentBoost;
+ float display_boost = std::min(max_display_boost, metadata->maxContentBoost);
RecoveryLUT recoveryLUT(metadata, display_boost);
JobQueue jobQueue;