Skip to content

gainmapmath: fix OOB reads in encoder pixel processing on odd-dimension images#392

Open
jortles wants to merge 1 commit into
google:mainfrom
jortles:fix/encoder-odd-dimension-oob
Open

gainmapmath: fix OOB reads in encoder pixel processing on odd-dimension images#392
jortles wants to merge 1 commit into
google:mainfrom
jortles:fix/encoder-odd-dimension-oob

Conversation

@jortles

@jortles jortles commented May 18, 2026

Copy link
Copy Markdown

Summary

  • Bug 1 — getP010Pixel UV overflow on odd width: The interleaved chroma index (x & ~0x1) + 1 reads 1 element past the chroma plane when image width is odd and x is the last pixel in a row. Fix: clamp chroma_x so the V sample stays in bounds.
  • Bug 2 — convert_raw_input_to_ycbcr row/column overflow on odd height/width: The 2×2 block loops access row[i+1] and col[j+1] unconditionally, overflowing when height or width is odd. Fix: change loop bounds from i < h to i + 1 < h (and j + 1 < w) so incomplete trailing blocks are skipped. Applied to both the RGBA1010102 and RGBA8888 paths.

The public encoder API (uhdr_enc_set_raw_image) already rejects odd dimensions for P010/YCbCr420, so these are defense-in-depth fixes for internal callers that bypass that validation.

Found by AFL++ fuzzing with a custom pixel-format harness.

Test plan

  • Verify existing unit tests pass (no behavior change for even-dimension images)
  • Confirm ASan-instrumented build no longer triggers OOB on odd-dimension inputs

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented May 18, 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.

…on images

Two heap-buffer-overflow reads exist in internal encoder pixel-processing
functions when image dimensions are odd:

1. getP010Pixel: The interleaved UV chroma index computation
   `(x & ~0x1) + 1` overflows the chroma row when width is odd and x is
   the last pixel. Fix: clamp chroma_x so the V sample index stays within
   the allocated chroma plane.

2. convert_raw_input_to_ycbcr: The 2x2 block loop accesses row i+1 and
   column j+1 unconditionally, reading past the source buffer when height
   or width is odd. Fix: change loop bounds from `i < h` to `i + 1 < h`
   (and likewise for j/w) so incomplete trailing blocks are skipped.

The public encoder API (uhdr_enc_set_raw_image) already rejects odd
dimensions for P010 and YCbCr420 formats, so these are defense-in-depth
fixes for internal callers that bypass that validation.

Found by: AFL++ fuzzing with custom pixel-format harness

Signed-off-by: Anthony Hurtado <amhurtado@pm.me>
@jortles jortles force-pushed the fix/encoder-odd-dimension-oob branch from f4110c3 to a4368db Compare May 18, 2026 14:36
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