Skip to content

gainmap: validate destination layout before applying gain map - #464

Draft
gregbenz wants to merge 1 commit into
google:mainfrom
gregbenz:codex/fix-applygainmap-destination-validation
Draft

gainmap: validate destination layout before applying gain map#464
gregbenz wants to merge 1 commit into
google:mainfrom
gregbenz:codex/fix-applygainmap-destination-validation

Conversation

@gregbenz

Copy link
Copy Markdown
Contributor

Summary

  • Require the destination width and height passed to applyGainMap() to match the SDR input/output dimensions.
  • Validate the packed destination stride against the width actually processed by the write loop.
  • Document the destination layout contract and add regression coverage for mismatched dimensions, insufficient stride, and valid row padding.

Why

applyGainMap() processes sdr_intent->w by sdr_intent->h pixels, but the existing validation only checks whether the packed stride is at least dest->w. A destination descriptor with smaller logical dimensions can therefore pass validation even though processing and raw-pointer writes continue over the full SDR extent.

Related: #367. This PR addresses the same destination-buffer validation issue by rejecting inconsistent destination dimensions and stride before CPU or GLES dispatch. Raw plane writes do not throw std::out_of_range, so validation is performed at the descriptor boundary.

Compatibility

The destination's logical dimensions must describe the generated output, so dest->w and dest->h must equal sdr_intent->w and sdr_intent->h. Callers may still use row padding by setting the packed destination stride greater than or equal to the output width.

The descriptor does not expose allocation capacity, so callers remain responsible for providing storage large enough for the declared stride and height.

Testing

  • JpegRTest.ApplyGainMapInvalidArgs
  • Complete default unit-test suite
  • Complete AddressSanitizer unit-test suite
  • Complete AVIF-enabled unit-test suite
  • UltraHdrApiTest.Avif* (3 tests)
  • git diff --check upstream/main...HEAD

All checks pass.

@google-cla

google-cla Bot commented Aug 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant