In NtGdiGetPixel check if the requested pixel is inside the boundaries of the surface, and return CLR_INVALID if not.

svn path=/trunk/; revision=56437
This commit is contained in:
Timo Kreuzer 2012-04-27 10:12:26 +00:00
parent e33dcea4d4
commit dfa925989c

View file

@ -1109,8 +1109,7 @@ NtGdiGetPixel(
_In_ INT y) _In_ INT y)
{ {
PDC pdc; PDC pdc;
ULONG ulRGBColor; ULONG ulRGBColor = CLR_INVALID;
BOOL bResult = FALSE;
POINTL ptlSrc; POINTL ptlSrc;
PSURFACE psurfSrc, psurfDest; PSURFACE psurfSrc, psurfDest;
@ -1119,7 +1118,7 @@ NtGdiGetPixel(
if (!pdc) if (!pdc)
{ {
EngSetLastError(ERROR_INVALID_HANDLE); EngSetLastError(ERROR_INVALID_HANDLE);
return -1; return CLR_INVALID;
} }
/* Check if the DC has no surface (empty mem or info DC) */ /* Check if the DC has no surface (empty mem or info DC) */
@ -1127,8 +1126,7 @@ NtGdiGetPixel(
if (psurfSrc == NULL) if (psurfSrc == NULL)
{ {
/* Fail! */ /* Fail! */
DC_UnlockDc(pdc); goto leave;
return -1;
} }
/* Get the logical coordinates */ /* Get the logical coordinates */
@ -1140,6 +1138,14 @@ NtGdiGetPixel(
ptlSrc.x += pdc->ptlDCOrig.x; ptlSrc.x += pdc->ptlDCOrig.x;
ptlSrc.y += pdc->ptlDCOrig.y; ptlSrc.y += pdc->ptlDCOrig.y;
/* Check if the pixel is outside the surface */
if ((ptlSrc.x >= psurfSrc->SurfObj.sizlBitmap.cx) ||
(ptlSrc.y >= psurfSrc->SurfObj.sizlBitmap.cy))
{
/* Fail! */
goto leave;
}
/* Allocate a surface */ /* Allocate a surface */
psurfDest = SURFACE_AllocSurface(STYPE_BITMAP, 1, 1, BMF_32BPP); psurfDest = SURFACE_AllocSurface(STYPE_BITMAP, 1, 1, BMF_32BPP);
if (psurfDest) if (psurfDest)
@ -1159,12 +1165,12 @@ NtGdiGetPixel(
RGB(0,0,0)); RGB(0,0,0));
/* Call the copy bits function */ /* Call the copy bits function */
bResult = IntEngCopyBits(&psurfDest->SurfObj, EngCopyBits(&psurfDest->SurfObj,
&psurfSrc->SurfObj, &psurfSrc->SurfObj,
NULL, NULL,
&exlo.xlo, &exlo.xlo,
&rclDest, &rclDest,
&ptlSrc); &ptlSrc);
/* Cleanup the XLATEOBJ */ /* Cleanup the XLATEOBJ */
EXLATEOBJ_vCleanup(&exlo); EXLATEOBJ_vCleanup(&exlo);
@ -1174,10 +1180,11 @@ NtGdiGetPixel(
GDIOBJ_vDeleteObject(&psurfDest->BaseObject); GDIOBJ_vDeleteObject(&psurfDest->BaseObject);
} }
leave:
/* Unlock the DC */ /* Unlock the DC */
DC_UnlockDc(pdc); DC_UnlockDc(pdc);
/* Return the new RGB color or -1 on failure */ /* Return the new RGB color or -1 on failure */
return bResult ? ulRGBColor : -1; return ulRGBColor;
} }