Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions code/savever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,20 +658,29 @@ HRESULT SaveVersionInfo::Load_String(IStorage *storage, int id, char *string)
return(res);
}

WCHAR buf[128];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holds 127 char + terminator, new loop never reads i = 127. A stream where the terminator is there returns S_OK with an empty destination. Handle the full representable range + fail if no terminator is found.

ULONG count;

int i = 0;
while (true) {
WCHAR buf[128];
res = stm->Read(&buf[i], sizeof(buf[i]), NULL);
for (; i < ARRAY_SIZE(buf); i++) {
res = stm->Read(&buf[i], sizeof(buf[i]), &count);
if (FAILED(res)) {
return(res);
}
if (res != S_OK || count != sizeof(buf[i])) {
return(E_FAIL);
}
if (buf[i] == '\0') {
WideCharToMultiByte(CP_ACP, 0, buf, -1, string, ARRAY_SIZE(buf) - 1, 0, 0);
return(res);
break;
}
i++;
}

if (i == ARRAY_SIZE(buf)) {
return(E_FAIL);
}

WideCharToMultiByte(CP_ACP, 0, buf, -1, string, ARRAY_SIZE(buf) - 1, 0, 0);

return(S_OK);
}

Expand Down