Rémi Bernon (@rbernon) commented about dlls/dmime/midi.c:
TRACE("Start parsing track %u\n", i);
if ((hr = IStream_Read(parser->stream, magic, sizeof(magic), &read)) != S_OK) return hr;
if (read == 0)
{
TRACE("End of file\n");
break;
}
if (memcmp(magic, "MTrk", 4) != 0)
{
WARN("Invalid track magic number\n");
return DMUS_E_UNSUPPORTED_STREAM;
}
if ((hr = IStream_Read(parser->stream, &length, sizeof(length), NULL)) != S_OK) return E_FAIL;
length = GET_BE_DWORD(length);
TRACE("Track %u, length %lu bytes\n", i, length);
What about allocating a `length` sized buffer and read everything at once? Would probably make the parsing a bit simpler wrt backtracking.