summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2016-09-21 10:21:43 -0700
committerJohn Stebbins <[email protected]>2016-09-21 10:22:55 -0700
commitcb4dc1d1837603fd9ede3b462fbe7211353b9c15 (patch)
tree0741811c2d4d42fb02d4f8fd628ae47ce12bd346 /libhb
parentedae772b99de734485869ddf6a8548bc22c2bc88 (diff)
decsrtsub: fix crash on empty UTF8 files
fixes https://github.com/HandBrake/HandBrake/issues/332
Diffstat (limited to 'libhb')
-rw-r--r--libhb/decsrtsub.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/libhb/decsrtsub.c b/libhb/decsrtsub.c
index c9f0ad3e4..14136cac9 100644
--- a/libhb/decsrtsub.c
+++ b/libhb/decsrtsub.c
@@ -257,10 +257,7 @@ static int utf8_fill( hb_work_private_t * pv )
pv->end = bytes;
if( bytes == 0 )
{
- if( conversion )
- return 1;
- else
- return 0;
+ return conversion;
}
}
@@ -269,8 +266,10 @@ static int utf8_fill( hb_work_private_t * pv )
in_size = pv->end - pv->pos;
retval = iconv( pv->iconv_context, &p, &in_size, &q, &out_size);
- if( q != pv->utf8_buf + pv->utf8_pos )
+ if (q != pv->utf8_buf + pv->utf8_end)
+ {
conversion = 1;
+ }
pv->utf8_end = q - pv->utf8_buf;
pv->pos = p - pv->buf;
@@ -281,6 +280,11 @@ static int utf8_fill( hb_work_private_t * pv )
if (buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)
{
pv->utf8_pos = 3;
+ if (pv->utf8_pos == pv->utf8_end)
+ {
+ // If only the bom was converted, indicate no conversion
+ conversion = 0;
+ }
}
pv->utf8_bom_skipped = 1;
}
@@ -294,10 +298,7 @@ static int utf8_fill( hb_work_private_t * pv )
bytes = fread( pv->buf + pv->end, 1, 1024 - pv->end, pv->file );
if( bytes == 0 )
{
- if( !conversion )
- return 0;
- else
- return 1;
+ return conversion;
}
pv->end += bytes;
} else if ( ( retval == -1 ) && ( errno == EILSEQ ) )