From f6b8db1d7cc38705be4d293d76837442db5e6058 Mon Sep 17 00:00:00 2001 From: Jamie Madill Date: Wed, 18 Aug 2021 15:20:10 -0400 Subject: [PATCH] Capture/Replay: Don't access OOB in TexImage2D. The last row of pixels is treated specially because we don't need to round up to the unpack alignment. This fixes an ASAN error with some 1x1 texture tests with small-sized formats. Test: TextureUploadFormatTest Bug: angleproject:5133 Change-Id: I4c56958b83406aff380bda56b90d3258020a1f99 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3104685 Reviewed-by: Cody Northrop Reviewed-by: Tim Van Patten Commit-Queue: Jamie Madill --- src/libANGLE/capture/capture_gles_2_0_params.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libANGLE/capture/capture_gles_2_0_params.cpp b/src/libANGLE/capture/capture_gles_2_0_params.cpp index b657f6184..c1a4acb64 100644 --- a/src/libANGLE/capture/capture_gles_2_0_params.cpp +++ b/src/libANGLE/capture/capture_gles_2_0_params.cpp @@ -704,8 +704,16 @@ void CaptureTexImage2D_pixels(const State &glState, (void)internalFormatInfo.computeSkipBytes(type, srcRowPitch, srcDepthPitch, unpack, false, &srcSkipBytes); - size_t captureSize = srcRowPitch * height + srcSkipBytes; - CaptureMemory(pixels, captureSize, paramCapture); + // For the last row of pixels, we don't round up to the unpack alignment. This often affects + // 1x1 sized textures because they may be 1 or 2 bytes wide with an alignment of 4 bytes. + size_t allRowSizeMinusLastRowSize = height == 0 ? 0 : (srcRowPitch * (height - 1)); + size_t lastRowSize = width * internalFormatInfo.pixelBytes; + size_t captureSize = allRowSizeMinusLastRowSize + lastRowSize + srcSkipBytes; + + if (captureSize > 0) + { + CaptureMemory(pixels, captureSize, paramCapture); + } } void CaptureTexParameterfv_params(const State &glState,