avifil32: Fix EditStreamSetInfo wine checks [try 2]
Alexandre Goujon
ale.goujon at gmail.com
Sun Aug 15 13:24:11 CDT 2010
This version includes more tests and passes on my XP *and* WineTestBot VMs.
---
dlls/avifil32/api.c | 7 ++-
dlls/avifil32/editstream.c | 17 ++-----
dlls/avifil32/tests/api.c | 106 +++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 113 insertions(+), 17 deletions(-)
diff --git a/dlls/avifil32/api.c b/dlls/avifil32/api.c
index 8ef75d3..642042e 100644
--- a/dlls/avifil32/api.c
+++ b/dlls/avifil32/api.c
@@ -2150,9 +2150,7 @@ HRESULT WINAPI EditStreamSetInfoA(PAVISTREAM pstream, LPAVISTREAMINFOA asi,
TRACE("(%p,%p,%d)\n", pstream, asi, size);
- if (pstream == NULL)
- return AVIERR_BADHANDLE;
- if ((DWORD)size < sizeof(AVISTREAMINFOA))
+ if (size >= 0 && size < sizeof(AVISTREAMINFOA))
return AVIERR_BADSIZE;
memcpy(&asiw, asi, sizeof(asiw) - sizeof(asiw.szName));
@@ -2173,6 +2171,9 @@ HRESULT WINAPI EditStreamSetInfoW(PAVISTREAM pstream, LPAVISTREAMINFOW asi,
TRACE("(%p,%p,%d)\n", pstream, asi, size);
+ if (size >= 0 && size < sizeof(AVISTREAMINFOW))
+ return AVIERR_BADSIZE;
+
hr = IAVIStream_QueryInterface(pstream, &IID_IAVIEditStream,(LPVOID*)&pEdit);
if (SUCCEEDED(hr) && pEdit != NULL) {
hr = IAVIEditStream_SetInfo(pEdit, asi, size);
diff --git a/dlls/avifil32/editstream.c b/dlls/avifil32/editstream.c
index f19f3ac..595413e 100644
--- a/dlls/avifil32/editstream.c
+++ b/dlls/avifil32/editstream.c
@@ -775,23 +775,16 @@ static HRESULT WINAPI IAVIEditStream_fnSetInfo(IAVIEditStream*iface,
TRACE("(%p,%p,%d)\n",iface,asi,size);
/* check parameters */
- if (asi == NULL)
- return AVIERR_BADPARAM;
- if (size != sizeof(AVISTREAMINFOW))
+ if (size >= 0 && size < sizeof(AVISTREAMINFOW))
return AVIERR_BADSIZE;
- if (asi->dwScale == 0 || asi->dwRate == 0 || (LONG)asi->dwQuality < -1 ||
- asi->dwQuality > ICQUALITY_HIGH)
- return AVIERR_ERROR;
This->sInfo.wLanguage = asi->wLanguage;
This->sInfo.wPriority = asi->wPriority;
This->sInfo.dwStart = asi->dwStart;
- if (asi->dwRate != 0)
- This->sInfo.dwRate = asi->dwRate;
- if (asi->dwScale != 0)
- This->sInfo.dwScale = asi->dwScale;
- if (asi->dwQuality <= ICQUALITY_HIGH)
- This->sInfo.dwQuality = ICQUALITY_HIGH;
+ This->sInfo.dwRate = asi->dwRate;
+ This->sInfo.dwScale = asi->dwScale;
+ This->sInfo.dwQuality = asi->dwQuality;
+
CopyRect(&This->sInfo.rcFrame, &asi->rcFrame);
memcpy(This->sInfo.szName, asi->szName, sizeof(asi->szName));
This->sInfo.dwEditCount++;
diff --git a/dlls/avifil32/tests/api.c b/dlls/avifil32/tests/api.c
index fe295bf..60f269d 100644
--- a/dlls/avifil32/tests/api.c
+++ b/dlls/avifil32/tests/api.c
@@ -171,6 +171,107 @@ static DWORD data[] =
/* ########################### */
+static void test_EditStreamSetInfo(void)
+{
+ PAVISTREAM stream = NULL;
+ HRESULT hres;
+ AVISTREAMINFO info, info2;
+
+ hres = CreateEditableStream(&stream, NULL);
+ ok(hres == AVIERR_OK, "got 0x%08X, expected AVIERR_OK\n", hres);
+
+
+ /*
+ The following test crashes so there is no NULL check for the first parameter
+ hres = EditStreamSetInfo(NULL, &info, sizeof(AVISTREAMINFO) );
+ */
+
+ hres = EditStreamSetInfo(stream, NULL, 0);
+ ok( hres == AVIERR_BADSIZE, "got 0x%08X, expected AVIERR_BADSIZE\n", hres);
+
+ hres = EditStreamSetInfo(stream, NULL, sizeof(AVISTREAMINFO)-1 );
+ ok( hres == AVIERR_BADSIZE, "got 0x%08X, expected AVIERR_BADSIZE\n", hres);
+
+ /*
+ The following test crashes so :
+ the size is checked
+ if the size is correct, there is not NULL check for the second argument
+ hres = EditStreamSetInfo(stream, NULL, sizeof(AVISTREAMINFO) );
+
+ The following test passes on my XP but not with WineTestBot VMs.
+ hres = EditStreamSetInfo(stream, NULL, sizeof(AVISTREAMINFO)+1 );
+ ok( hres == AVIERR_BADSIZE, "got 0x%08X, expected AVIERR_BADSIZE\n", hres);
+
+ This one crashes too
+ hres = EditStreamSetInfo(stream, NULL, -1);
+ ok( hres == AVIERR_BADSIZE, "got 0x%08X, expected AVIERR_BADSIZE\n", hres);
+
+ So instead of checking if size != sizeof(), I'll check if size >= 0 and size < sizeof()
+ */
+
+ hres = AVIStreamInfo(stream, &info, sizeof(AVISTREAMINFO) );
+ ok( hres == 0, "got 0x%08X, expected 0\n", hres);
+
+#define TEST_SETINFO_(m) \
+ hres = EditStreamSetInfo(stream, &info, sizeof(AVISTREAMINFO) ); \
+ ok( hres == 0, "got 0x%08X, expected 0\n", hres); \
+ hres = AVIStreamInfo(stream, &info2, sizeof(AVISTREAMINFO) ); \
+ ok( hres == 0, "got 0x%08X, expected 0\n", hres); \
+ ok( info2.m == info.m, "EditStreamSetInfo did not update "#m" parameter\n" );
+
+#define TEST_SETINFO(m) \
+ info.m++; \
+ TEST_SETINFO_(m); \
+ \
+ info.m = 0; \
+ TEST_SETINFO_(m);
+
+
+ TEST_SETINFO(dwStart)
+ TEST_SETINFO(wPriority)
+ TEST_SETINFO(wLanguage)
+ TEST_SETINFO(dwScale)
+ TEST_SETINFO(dwRate)
+ TEST_SETINFO(dwQuality)
+
+ info.dwQuality = -2;
+ TEST_SETINFO_(dwQuality)
+
+ info.dwQuality = ICQUALITY_HIGH + 1;
+ TEST_SETINFO_(dwQuality)
+
+ info.rcFrame.left = 0;
+ TEST_SETINFO_(rcFrame.left)
+
+ info.rcFrame.top = 0;
+ TEST_SETINFO_(rcFrame.top)
+
+ info.rcFrame.right = 0;
+ TEST_SETINFO_(rcFrame.right)
+
+ info.rcFrame.bottom = 0;
+ TEST_SETINFO_(rcFrame.bottom)
+
+ info.rcFrame.left = -1;
+ TEST_SETINFO_(rcFrame.left)
+
+ info.rcFrame.top = -1;
+ TEST_SETINFO_(rcFrame.top)
+
+ info.rcFrame.right = -1;
+ TEST_SETINFO_(rcFrame.right)
+
+ info.rcFrame.bottom = -1;
+ TEST_SETINFO_(rcFrame.bottom)
+
+ /* All these tests prove that EditStreamSetInfo does not check the stream info. So do we. */
+
+ AVIStreamRelease(stream);
+#undef TEST_SETINFO
+#undef TEST_SETINFO_
+}
+
+
static void test_AVISaveOptions(void)
{
AVICOMPRESSOPTIONS options[2];
@@ -194,11 +295,11 @@ static void test_AVISaveOptions(void)
SetLastError(0xdeadbeef);
hres = EditStreamSetNameA(streams[0], winetest0);
- todo_wine ok(hres == AVIERR_OK, "0: got 0x%x (expected AVIERR_OK)\n", hres);
+ ok(hres == AVIERR_OK, "0: got 0x%x (expected AVIERR_OK)\n", hres);
SetLastError(0xdeadbeef);
hres = EditStreamSetNameA(streams[1], winetest1);
- todo_wine ok(hres == AVIERR_OK, "1: got 0x%x (expected AVIERR_OK)\n", hres);
+ ok(hres == AVIERR_OK, "1: got 0x%x (expected AVIERR_OK)\n", hres);
if (winetest_interactive) {
SetLastError(0xdeadbeef);
@@ -451,6 +552,7 @@ START_TEST(api)
{
AVIFileInit();
+ test_EditStreamSetInfo();
test_AVISaveOptions();
test_default_data();
test_amh_corruption();
--
1.7.0.4
More information about the wine-patches
mailing list