Skip to content

Commit

Permalink
unescape: Try to handle length of continuous characters after \u
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Jan 14, 2025
1 parent 55e49be commit a0acbff
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/flb_unescape.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static int u8_read_escape_sequence(const char *str, int size, uint32_t *dest)
{
uint32_t ch = 0;
char digs[9]="\0\0\0\0\0\0\0\0";
char ldigs[9]="\0\0\0\0\0\0\0\0";
int dno=0, i=1;
uint32_t low = 0;

Expand Down Expand Up @@ -122,8 +123,10 @@ static int u8_read_escape_sequence(const char *str, int size, uint32_t *dest)
}
if (dno != 4) {
/* Incomplete \u escape sequence */
ch = L'\uFFFD';
goto invalid_sequence;
if (dno > 0) {
ch = L'\uFFFD';
goto invalid_sequence;
}
}
ch = strtol(digs, NULL, 16);
if (u8_low_surrogate(ch)) {
Expand All @@ -138,14 +141,16 @@ static int u8_read_escape_sequence(const char *str, int size, uint32_t *dest)
dno = 0;
i += 2; /* Skip "\u" */
while (i < size && hex_digit(str[i]) && dno < 4) {
digs[dno++] = str[i++];
ldigs[dno++] = str[i++];
}
if (dno != 4) {
/* Incomplete low surrogate */
ch = L'\uFFFD';
goto invalid_sequence;
if (dno > 0) {
ch = L'\uFFFD';
goto invalid_sequence;
}
}
low = strtol(digs, NULL, 16);
low = strtol(ldigs, NULL, 16);
if (u8_low_surrogate(low)) {
ch = u8_combine_surrogates(ch, low);
}
Expand Down

0 comments on commit a0acbff

Please sign in to comment.