Skip to content

gainmapmath: restore odd-dimension OOB read fixes reverted by #413 - #459

Open
MajorMurphy wants to merge 1 commit into
google:mainfrom
murphyindustries:fix/restore-odd-dimension-oob-reads
Open

gainmapmath: restore odd-dimension OOB read fixes reverted by #413#459
MajorMurphy wants to merge 1 commit into
google:mainfrom
murphyindustries:fix/restore-odd-dimension-oob-reads

Conversation

@MajorMurphy

Copy link
Copy Markdown
Contributor

Restores the defect fix from #391, originally submitted by @jortles in #392 and landed by @DichenZhang1 as #407 (586ed42).

#413's 07bc6a2 was branched before #407 and reverted all three hunks when it merged nine days later, so v2.0.0, v2.0.1, v2.0.2 and current main all ship the pre-fix code:

  • lib/src/gainmapmath.cpp:432getP010Pixel's chroma index is back to (x & ~0x1) with no clamp, so pixel_v_idx = pixel_u_idx + 1 reads one element past the chroma plane on the last column of an odd-width P010 image.
  • lib/src/gainmapmath.cpp:1320 and :1413convert_raw_input_to_ycbcr's 2×2 block loops are back to i < dst->h / j < dst->w, reading row i + 1 / column j + 1 past the edge on odd dimensions. Both the RGBA1010102 and RGBA8888 paths.

git diff 586ed42 07bc6a2 -- lib/src/gainmapmath.cpp shows the three hunks being undone. The revert looks incidental rather than deliberate — the HEIF/AVIF staging branch predated #407 and carried the older copy of the file forward over it.

#407's test GetP010PixelOddWidth was not reverted and is still in tests/gainmapmath_test.cpp, but it asserts EXPECT_NO_FATAL_FAILURE, which a short read past a heap allocation does not trip outside a sanitizer build. The test and the code it guards were reverted independently, leaving a green guard over absent code.

This is a cherry-pick of 586ed42 onto current main, preserving its original authorship. The test hunk is already present, so only lib/src/gainmapmath.cpp changes (+9 / −5).

One caveat carried over from #407: the loop-bound half skips the trailing incomplete block rather than clamping, so the final row and column of an odd-dimension image are left value-initialized — black with fully saturated chroma — instead of read out of bounds. Clamping the source index the way getP010Pixel now does would fix the values too, but I have kept this to exactly what #407 did so it reads as a pure restoration. Happy to follow up.

Verified to build clean on MSVC 2022 x64 Release; I have not run it under ASan.

…on images (google#407)

* Fix OOB write in applyGainMap by validating destination image pointers, stride, output_ct, and pixel format (b/439639756)

* Fix OOB write in applyGainMap by validating destination image pointers, stride, output_ct, and pixel format (b/439639756)

* gainmapmath: fix OOB reads in encoder pixel processing on odd-dimension images
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.

2 participants