Skip to content

Commit b6d98c7

Browse files
authored
fix parsing crash (#2173)
1 parent d42a8c7 commit b6d98c7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

core/logic/TextParsers.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
342342
SMCResult res;
343343
SMCStates states;
344344
char c;
345+
bool end_of_last_buffer_was_backslash = false;
345346

346347
StringInfo strings[3];
347348
StringInfo emptystring;
@@ -383,6 +384,10 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
383384
if (reparse_point)
384385
{
385386
read += (parse_point - reparse_point);
387+
if(read > 0)
388+
{
389+
end_of_last_buffer_was_backslash = reparse_point[-1] == '\\';
390+
}
386391
parse_point = reparse_point;
387392
reparse_point = NULL;
388393
}
@@ -454,7 +459,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
454459
if (in_quote)
455460
{
456461
/* If i was 0, we could have reparsed, so make sure there's no buffer underrun */
457-
if ((&parse_point[i] != in_buf) && c == '"' && parse_point[i-1] != '\\')
462+
if ( (&parse_point[i] != in_buf) && c == '"' && !((i == 0 && end_of_last_buffer_was_backslash) || (i > 0 && parse_point[i-1] == '\\')) )
458463
{
459464
/* If we reached a quote in an ignore phase,
460465
* we're staging a string and we must rotate it out.
@@ -726,6 +731,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
726731
if (parse_point)
727732
{
728733
parse_point = &parse_point[read];
734+
end_of_last_buffer_was_backslash = parse_point[-1] == '\\';
729735
parse_point -= bytes;
730736
}
731737
}

0 commit comments

Comments
 (0)