Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd3f6373 authored by Ram Mohan's avatar Ram Mohan Committed by Dichen Zhang
Browse files

ultrahdr: Fix nan occurence during xmp generation

The default value of hdr white nits is zero, making log content boost
to nan in certain scenarios. This can cause decode to fail on select
architectures

Bug: 285545078
Test: ./ultrahdr_enc_fuzzer

Change-Id: I72064d4f04c25d6f3c951f5c20b0b674e675d541
parent 7fbf5f1a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -256,7 +256,7 @@ void JpegHDRFuzzer::process() {
                        } else if (tf == ULTRAHDR_TF_PQ) {
                            metadata.maxContentBoost = kPqMaxNits / kSdrWhiteNits;
                        } else {
                            metadata.maxContentBoost = 0;
                            metadata.maxContentBoost = 1.0f;
                        }
                        metadata.minContentBoost = 1.0f;
                        status = jpegHdr.encodeJPEGR(&jpegImg, &jpegGainMap, &metadata, &jpegImgR);
+7 −1
Original line number Diff line number Diff line
@@ -726,7 +726,7 @@ status_t JpegR::generateGainMap(jr_uncompressed_ptr uncompressed_yuv_420_image,
  map_data.reset(reinterpret_cast<uint8_t*>(dest->data));

  ColorTransformFn hdrInvOetf = nullptr;
  float hdr_white_nits = 0.0f;
  float hdr_white_nits = kSdrWhiteNits;
  switch (hdr_tf) {
    case ULTRAHDR_TF_LINEAR:
      hdrInvOetf = identityConversion;
@@ -1067,6 +1067,12 @@ status_t JpegR::appendGainMap(jr_compressed_ptr compressed_jpeg_image,
    return ERROR_JPEGR_INVALID_NULL_PTR;
  }

  if (metadata->minContentBoost < 1.0f || metadata->maxContentBoost < metadata->minContentBoost) {
    ALOGE("received bad value for content boost min %f, max %f", metadata->minContentBoost,
           metadata->maxContentBoost);
    return ERROR_JPEGR_INVALID_INPUT_TYPE;
  }

  const string nameSpace = "http://ns.adobe.com/xap/1.0/";
  const int nameSpaceLength = nameSpace.size() + 1;  // need to count the null terminator