Skip to content

Commit e4bcade

Browse files
authored
Fix potential out-of-bounds access in write_stringz_as_srt_to_output (#2128)
* Fix loop condition for reading unescaped string * Fix condition to check for newline escape sequence * Fix formatting
1 parent f377be9 commit e4bcade

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/lib_ccx/ccx_encoders_srt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int write_stringz_as_srt_to_output(char *string, struct encoder_ctx *cont
4747
// Scan for \n in the string and replace it with a 0
4848
while (pos_r < len)
4949
{
50-
if (string[pos_r] == '\\' && string[pos_r + 1] == 'n')
50+
if (pos_r < len - 1 && string[pos_r] == '\\' && string[pos_r + 1] == 'n')
5151
{
5252
unescaped[pos_w] = 0;
5353
pos_r += 2;
@@ -62,7 +62,7 @@ static int write_stringz_as_srt_to_output(char *string, struct encoder_ctx *cont
6262
unescaped[pos_w] = 0;
6363
// Now read the unescaped string (now several string'z and write them)
6464
unsigned char *begin = unescaped;
65-
while (begin < unescaped + len)
65+
while (begin < unescaped + pos_w)
6666
{
6767
unsigned int u = encode_line(context, el, begin);
6868
if (context->encoding != CCX_ENC_UNICODE)

0 commit comments

Comments
 (0)