[PATCH 0/1] MR2723: evr: Fix incorrect integral computation.
Note: typeof (int * unsigned) is unsigned. So: - on 64bit CPUs, where sizeof(int) = 4 < sizeof(void*) = 8, - when the result of the multiplication is supposed to be negative - there's no progation of the negative sign from 32bit to 64 bit integers Fixes a crash in Age of Empire II. Signed-off-by: Eric Pouech <epouech(a)codeweavers.com> -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2723
From: Eric Pouech <epouech(a)codeweavers.com> Note: typeof (int * unsigned) is unsigned. So: - on 64bit CPUs, where sizeof(int) = 4 < sizeof(void*) = 8, - when the result of the multiplication is supposed to be negative - there's no progation of the negative sign from 32bit to 64 bit integers Fixes a crash in Age of Empire II. Signed-off-by: Eric Pouech <epouech(a)codeweavers.com> --- dlls/evr/evr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlls/evr/evr.c b/dlls/evr/evr.c index 26a2a3a1eb5..611f6762844 100644 --- a/dlls/evr/evr.c +++ b/dlls/evr/evr.c @@ -382,7 +382,7 @@ static HRESULT evr_copy_sample_buffer(struct evr *filter, IMediaSample *input_sa { if (SUCCEEDED(hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, D3DLOCK_DISCARD))) { - if (src_stride < 0) src -= src_stride * (lines - 1); + if (src_stride < 0) src -= src_stride * (INT32)(lines - 1); MFCopyImage(locked_rect.pBits, locked_rect.Pitch, src, src_stride, width * 4, lines); IDirect3DSurface9_UnlockRect(surface); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2723
Will it work if you made "lines" signed? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2723#note_31771
yes, any form that lets the result of the multiplication to be signed integer so any of these will do - make lines a signed int - or cast (lines - 1) to a signed int - or cast the result of the (unsigned) multiplication to a signed int one could event prefer adding a positive integer to subtracting a negative one: ``` if (src_stride < 0) src += (-src_stride) * (lines - 1); ``` which I find more readable to show to intent to walk the image starting from last line in memory order -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2723#note_31773
one could event prefer adding a positive integer to subtracting a negative one:
``` if (src_stride < 0) src += (-src_stride) * (lines - 1); ```
which I find more readable to show to intent to walk the image starting from last line in memory order
Yes, that's definitely better. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2723#note_31780
participants (4)
-
Alexandre Julliard (@julliard) -
Eric Pouech -
eric pouech (@epo) -
Nikolay Sivov (@nsivov)