throw FileError ("Could not open file for reading", path);
}
uint8_t* buffer = new uint8_t[size];
- fread (buffer, 1, size, f);
+ checked_fread (buffer, size, f, path);
fclose (f);
try {
_video_size = dcp::decompress_j2k (buffer, size, 0)->size ();
{
dcp::FrameInfo info;
dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET);
- fread (&info.offset, sizeof (info.offset), 1, file);
- fread (&info.size, sizeof (info.size), 1, file);
+ checked_fread (&info.offset, sizeof(info.offset), file, _film->info_file(_period));
+ checked_fread (&info.size, sizeof(info.size), file, _film->info_file(_period));
char hash_buffer[33];
- fread (hash_buffer, 1, 32, file);
+ checked_fread (hash_buffer, 32, file, _film->info_file(_period));
hash_buffer[32] = '\0';
info.hash = hash_buffer;
}
boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));
- fread (p, 1, this_time, f);
+ checked_fread (p, this_time, f, files[i]);
p += this_time;
to_do -= this_time;
fclose (f);
boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));
dcpomatic_fseek (f, -this_time, SEEK_END);
- fread (p, 1, this_time, f);
+ checked_fread (p, this_time, f, files[i]);
p += this_time;
to_do -= this_time;
fclose (f);
return EYES_LEFT;
}
+
+void
+checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path path)
+{
+ size_t N = fread (ptr, 1, size, stream);
+ if (N != size) {
+ if (ferror(stream)) {
+ throw FileError (String::compose("fread error %1", errno), path);
+ } else {
+ throw FileError ("Unexpected short read", path);
+ }
+ }
+}
extern std::pair<int, int> audio_channel_types (std::list<int> mapped, int channels);
extern boost::shared_ptr<AudioBuffers> remap (boost::shared_ptr<const AudioBuffers> input, int output_channels, AudioMapping map);
extern Eyes increment_eyes (Eyes e);
+extern void checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path path);
#endif