[PATCH v3 0/6] MR10480: gdiplus: Fix GdipGetImage* functions
In case HEMF (Handle to an Enhanced Metafile) is missing, we should return InvalidParameter. Additionally bounds were fixed for GdipGetImageBounds. -- v3: gdiplus: Make function which using GdipGetImage* more reboust https://gitlab.winehq.org/wine/wine/-/merge_requests/10480
From: Bartosz Kosiorek <gang65@poczta.onet.pl> --- dlls/gdiplus/metafile.c | 4 ++-- dlls/gdiplus/tests/metafile.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dlls/gdiplus/metafile.c b/dlls/gdiplus/metafile.c index a786297a40b..20adc83b95f 100644 --- a/dlls/gdiplus/metafile.c +++ b/dlls/gdiplus/metafile.c @@ -1709,8 +1709,8 @@ GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) af_min->X = fmin(af_min->X, gdi_bounds_rc.left); af_min->Y = fmin(af_min->Y, gdi_bounds_rc.top); - af_max->X = fmax(af_max->X, gdi_bounds_rc.right); - af_max->Y = fmax(af_max->Y, gdi_bounds_rc.bottom); + af_max->X = fmax(af_max->X, gdi_bounds_rc.right + 1); + af_max->Y = fmax(af_max->Y, gdi_bounds_rc.bottom + 1); } bounds_rc.left = floorf(metafile->auto_frame_min.X * x_scale); diff --git a/dlls/gdiplus/tests/metafile.c b/dlls/gdiplus/tests/metafile.c index 401b3ea6bac..23d2f50c6d7 100644 --- a/dlls/gdiplus/tests/metafile.c +++ b/dlls/gdiplus/tests/metafile.c @@ -1427,8 +1427,7 @@ static void test_nullframerect(void) { expect(UnitPixel, unit); expectf_(20.0, bounds.X, 0.05); expectf_(25.0, bounds.Y, 0.05); - expectf_(55.0, bounds.Width, 1.00); - todo_wine expectf_(55.0, bounds.Width, 0.05); + expectf_(55.0, bounds.Width, 0.05); expectf_(85.0, bounds.Height, 0.05); stat = GdipDisposeImage((GpImage*)metafile); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10480
From: Bartosz Kosiorek <gang65@poczta.onet.pl> In case HEMF (Handle to an Enhanced Metafile) is missing, we should return InvalidParameter --- dlls/gdiplus/image.c | 3 +++ dlls/gdiplus/tests/metafile.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index 035db159d5b..9bd992a4578 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -2243,6 +2243,9 @@ GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res) if(!image || !res) return InvalidParameter; + if(!((GpMetafile*)image)->hemf) + return InvalidParameter; + *res = image->xres; TRACE("(%p) <-- %0.2f\n", image, *res); diff --git a/dlls/gdiplus/tests/metafile.c b/dlls/gdiplus/tests/metafile.c index 23d2f50c6d7..f610775adc0 100644 --- a/dlls/gdiplus/tests/metafile.c +++ b/dlls/gdiplus/tests/metafile.c @@ -1477,7 +1477,7 @@ static void test_pagetransform(void) return; stat = GdipGetImageHorizontalResolution((GpImage*)metafile, &dpix); - todo_wine expect(InvalidParameter, stat); + expect(InvalidParameter, stat); stat = GdipGetImageVerticalResolution((GpImage*)metafile, &dpiy); todo_wine expect(InvalidParameter, stat); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10480
From: Bartosz Kosiorek <gang65@poczta.onet.pl> In case HEMF (Handle to an Enhanced Metafile) is missing, we should return InvalidParameter --- dlls/gdiplus/image.c | 3 +++ dlls/gdiplus/tests/metafile.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index 9bd992a4578..ce644d98478 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -2321,6 +2321,9 @@ GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res) if(!image || !res) return InvalidParameter; + if(!((GpMetafile*)image)->hemf) + return InvalidParameter; + *res = image->yres; TRACE("(%p) <-- %0.2f\n", image, *res); diff --git a/dlls/gdiplus/tests/metafile.c b/dlls/gdiplus/tests/metafile.c index f610775adc0..04b6eb02aad 100644 --- a/dlls/gdiplus/tests/metafile.c +++ b/dlls/gdiplus/tests/metafile.c @@ -1480,7 +1480,7 @@ static void test_pagetransform(void) expect(InvalidParameter, stat); stat = GdipGetImageVerticalResolution((GpImage*)metafile, &dpiy); - todo_wine expect(InvalidParameter, stat); + expect(InvalidParameter, stat); stat = GdipGetImageWidth((GpImage*)metafile, &width); todo_wine expect(InvalidParameter, stat); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10480
From: Bartosz Kosiorek <gang65@poczta.onet.pl> In case HEMF (Handle to an Enhanced Metafile) is missing, we should return InvalidParameter --- dlls/gdiplus/image.c | 3 +++ dlls/gdiplus/tests/metafile.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index ce644d98478..7adb97c1ef2 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -2337,6 +2337,9 @@ GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width) if(!image || !width) return InvalidParameter; + + if(!((GpMetafile*)image)->hemf) + return InvalidParameter; if(image->type == ImageTypeMetafile) *width = units_to_pixels(((GpMetafile*)image)->bounds.Width, ((GpMetafile*)image)->unit, diff --git a/dlls/gdiplus/tests/metafile.c b/dlls/gdiplus/tests/metafile.c index 04b6eb02aad..11eac354dc7 100644 --- a/dlls/gdiplus/tests/metafile.c +++ b/dlls/gdiplus/tests/metafile.c @@ -1483,7 +1483,7 @@ static void test_pagetransform(void) expect(InvalidParameter, stat); stat = GdipGetImageWidth((GpImage*)metafile, &width); - todo_wine expect(InvalidParameter, stat); + expect(InvalidParameter, stat); stat = GdipGetImageHeight((GpImage*)metafile, &height); todo_wine expect(InvalidParameter, stat); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10480
From: Bartosz Kosiorek <gang65@poczta.onet.pl> In case HEMF (Handle to an Enhanced Metafile) is missing, we should return InvalidParameter --- dlls/gdiplus/image.c | 3 +++ dlls/gdiplus/tests/metafile.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index 7adb97c1ef2..ee89b11ffc0 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -2222,6 +2222,9 @@ GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height) if(!image || !height) return InvalidParameter; + if(!((GpMetafile*)image)->hemf) + return InvalidParameter; + if(image->type == ImageTypeMetafile) *height = units_to_pixels(((GpMetafile*)image)->bounds.Height, ((GpMetafile*)image)->unit, image->yres, ((GpMetafile*)image)->printer_display); diff --git a/dlls/gdiplus/tests/metafile.c b/dlls/gdiplus/tests/metafile.c index 11eac354dc7..9ee052b23d3 100644 --- a/dlls/gdiplus/tests/metafile.c +++ b/dlls/gdiplus/tests/metafile.c @@ -1486,7 +1486,7 @@ static void test_pagetransform(void) expect(InvalidParameter, stat); stat = GdipGetImageHeight((GpImage*)metafile, &height); - todo_wine expect(InvalidParameter, stat); + expect(InvalidParameter, stat); stat = GdipGetImageGraphicsContext((GpImage*)metafile, &graphics); expect(Ok, stat); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10480
From: Bartosz Kosiorek <gang65@poczta.onet.pl> --- dlls/gdiplus/image.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index ee89b11ffc0..f7d1aa5e549 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -1551,8 +1551,18 @@ GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, if (!bitmap || !hbmReturn) return InvalidParameter; if (!image_lock(&bitmap->image)) return ObjectBusy; - GdipGetImageWidth(&bitmap->image, &width); - GdipGetImageHeight(&bitmap->image, &height); + stat = GdipGetImageWidth(&bitmap->image, &width); + if (stat != Ok) + { + image_unlock(&bitmap->image); + return stat; + } + stat = GdipGetImageHeight(&bitmap->image, &height); + if (stat != Ok) + { + image_unlock(&bitmap->image); + return stat; + } bih.biSize = sizeof(bih); bih.biWidth = width; @@ -4704,8 +4714,12 @@ static GpStatus encode_frame_wic(IWICBitmapEncoder *encoder, GpImage *image) bitmap = (GpBitmap*)image; - GdipGetImageWidth(image, &width); - GdipGetImageHeight(image, &height); + stat = GdipGetImageWidth(image, &width); + if (stat != Ok) + return stat; + stat = GdipGetImageHeight(image, &height); + if (stat != Ok) + return stat; rc.X = 0; rc.Y = 0; @@ -5787,8 +5801,12 @@ GpStatus WINGDIPAPI GdipGetImageThumbnail(GpImage *image, UINT width, UINT heigh if (!width) width = 120; if (!height) height = 120; - GdipGetImageWidth(image, &srcwidth); - GdipGetImageHeight(image, &srcheight); + stat = GdipGetImageWidth(image, &srcwidth); + if (stat != Ok) + return stat; + stat = GdipGetImageHeight(image, &srcheight); + if (stat != Ok) + return stat; stat = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat32bppPARGB, NULL, (GpBitmap**)ret_image); @@ -6063,8 +6081,12 @@ GpStatus WINGDIPAPI GdipBitmapGetHistogram(GpBitmap *bitmap, HistogramFormat for return InvalidParameter; } - GdipGetImageWidth(&bitmap->image, &width); - GdipGetImageHeight(&bitmap->image, &height); + stat = GdipGetImageWidth(&bitmap->image, &width); + if (stat != Ok) + return stat; + stat = GdipGetImageHeight(&bitmap->image, &height); + if (stat != Ok) + return stat; for (y = 0; y < height; y++) for (x = 0; x < width; x++) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10480
participants (2)
-
Bartosz Kosiorek -
Bartosz Kosiorek (@gang65)