Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 64 bit crash on large gamedata files #2173

Merged
merged 1 commit into from
Jun 9, 2024
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
8 changes: 7 additions & 1 deletion core/logic/TextParsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
SMCResult res;
SMCStates states;
char c;
bool end_of_last_buffer_was_backslash = false;

StringInfo strings[3];
StringInfo emptystring;
Expand Down Expand Up @@ -383,6 +384,10 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (reparse_point)
{
read += (parse_point - reparse_point);
if(read > 0)
{
end_of_last_buffer_was_backslash = reparse_point[-1] == '\\';
}
parse_point = reparse_point;
reparse_point = NULL;
}
Expand Down Expand Up @@ -454,7 +459,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (in_quote)
{
/* If i was 0, we could have reparsed, so make sure there's no buffer underrun */
if ((&parse_point[i] != in_buf) && c == '"' && parse_point[i-1] != '\\')
if ( (&parse_point[i] != in_buf) && c == '"' && !((i == 0 && end_of_last_buffer_was_backslash) || (i > 0 && parse_point[i-1] == '\\')) )
{
/* If we reached a quote in an ignore phase,
* we're staging a string and we must rotate it out.
Expand Down Expand Up @@ -726,6 +731,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
if (parse_point)
{
parse_point = &parse_point[read];
end_of_last_buffer_was_backslash = parse_point[-1] == '\\';
parse_point -= bytes;
}
}
Expand Down