diff options
Diffstat (limited to 'libhb/stream.c')
-rw-r--r-- | libhb/stream.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/libhb/stream.c b/libhb/stream.c index f885cae3d..7ea2e1ca9 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -3280,19 +3280,24 @@ static int hb_ps_read_packet( hb_stream_t * stream, hb_buffer_t *b ) hb_buffer_realloc( b, b->alloc * 2 ); } - // There are at least 8 bytes. More if this is mpeg2 pack. - fread( cp+pos, 1, 8, stream->file_handle ); + // There are (hopefully) at least 8 bytes. More if this is mpeg2 pack. + if (fread( cp+pos, 1, 8, stream->file_handle ) < 8) + goto done; int mark = cp[pos] >> 4; pos += 8; if ( mark != 0x02 ) { // mpeg-2 pack, - fread( cp+pos, 1, 2, stream->file_handle ); - pos += 2; - int len = cp[start+13] & 0x7; - fread( cp+pos, 1, len, stream->file_handle ); - pos += len; + if (fread( cp+pos, 1, 2, stream->file_handle ) == 2) + { + int len; + pos += 2; + len = cp[start+13] & 0x7; + if (len > 0 && + fread( cp+pos, 1, len, stream->file_handle ) == len) + pos += len; + } } } // Non-video streams can emulate start codes, so we need |