summaryrefslogtreecommitdiffstats
path: root/libhb/stream.c
diff options
context:
space:
mode:
authorSean McGovern <[email protected]>2016-07-17 14:49:25 -0400
committerBradley Sepos <[email protected]>2016-07-28 15:21:40 -0400
commita0401eace97ab267a9c21897dd8c880203d4ea31 (patch)
tree3467b11ffa5f70f5bb474df50c5857cf3e76a77e /libhb/stream.c
parentf5430c963bca9d09cf612c1a97c761499084f16d (diff)
libhb: make hb_ps_read_packet() more robust
Diffstat (limited to 'libhb/stream.c')
-rw-r--r--libhb/stream.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/libhb/stream.c b/libhb/stream.c
index f885cae3d..f5a6cb7df 100644
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -3281,18 +3281,25 @@ static int hb_ps_read_packet( hb_stream_t * stream, hb_buffer_t *b )
}
// There are at least 8 bytes. More if this is mpeg2 pack.
- fread( cp+pos, 1, 8, stream->file_handle );
+ 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 = cp[start+13] & 0x7;
+ pos += 2;
+ if (len > 0 &&
+ fread( cp+pos, 1, len, stream->file_handle ) == len)
+ pos += len;
+ else
+ goto done;
+ }
}
}
// Non-video streams can emulate start codes, so we need