http://bugs.winehq.org/show_bug.cgi?id=11716
--- Comment #8 from Jesse Allen the3dfxdude@gmail.com 2008-12-21 22:02:58 --- Created an attachment (id=18115) --> (http://bugs.winehq.org/attachment.cgi?id=18115) Potential Format Checking Fix
Problem area: if (pwfxe->Format.cbSize > (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX))) { WARN("Too big a cbSize %u\n", pwfxe->Format.cbSize); return DSERR_CONTROLUNAVAIL; }
if (!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))
The game uses WAVEFORMATEXTENSIBLE with the SubFormat KSDATAFORMAT_SUBTYPE_PCM. However for whatever reason, the size is not expected with this type of subformat. cbSize is bigger than "sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)", and then the return is not handled properly causing a crash.
Looking at the dsound tests, there are actually no tests with KSDATAFORMAT_SUBTYPE_PCM explicit (correct me if wrong). Therefore I think the size check "sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)" might be a little misleading when actually dealing with subformats. More tests might need to be done.
So the code for WAVEFORMATEXTENSIBLE in CreateSoundBuffer checks the cbSize before it even looks at the SubFormat. My feeling is that if we are going to use the special formats, then we ought to know what the SubFormat is before any size check. Therefore I rearranged the code so the SubFormat check is first, but also still attempt to do a size check. This is the best compromise I can see without diving deeper into handling more formats. This still passes the same dsound tests.