summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean McGovern <[email protected]>2016-06-30 11:56:46 -0400
committerSean McGovern <[email protected]>2016-07-01 14:07:30 -0400
commitb7645e7842703d52c44feaa85cfb3c490e09c8dc (patch)
treefff45a18b5dab225397f326e10b00e2c61158d60
parent4275507a21562299ed6b27cebc40c7308fd594a8 (diff)
libhb: don't ignore the return result from fread()
-rw-r--r--libhb/encavcodec.c6
-rw-r--r--libhb/hb.c8
-rw-r--r--libhb/stream.c19
3 files changed, 24 insertions, 9 deletions
diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c
index f7ed25233..a8781f057 100644
--- a/libhb/encavcodec.c
+++ b/libhb/encavcodec.c
@@ -302,7 +302,11 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
fseek( pv->file, 0, SEEK_SET );
log = malloc( size + 1 );
log[size] = '\0';
- fread( log, size, 1, pv->file );
+ if (size > 0 &&
+ fread( log, size, 1, pv->file ) < size)
+ {
+ hb_log( "encavcodecInit: Failed to read %s" , filename);
+ }
fclose( pv->file );
pv->file = NULL;
diff --git a/libhb/hb.c b/libhb/hb.c
index abcfa72eb..d84fece27 100644
--- a/libhb/hb.c
+++ b/libhb/hb.c
@@ -696,7 +696,13 @@ hb_buffer_t * hb_read_preview(hb_handle_t * h, hb_title_t *title, int preview)
for (hh = 0; hh < h; hh++)
{
- fread(data, w, 1, file);
+ if (fread(data, w, 1, file) < w)
+ {
+ hb_error( "hb_read_preview: Failed to read line %d from %s" , hh, filename );
+ hb_buffer_close(&buf);
+ break;
+ }
+
data += stride;
}
}
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