Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add size check to memory stream check program #1187

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/bin/exrcheck/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,24 @@ exrCheck(const char* filename, bool reduceMemory, bool reduceTime, bool useStrea
// open file as stream, check size
//
ifstream instream(filename,ifstream::binary);

if ( ! instream )
{
cerr << "internal error: bad file '" << filename << "' for in-memory stream" << endl;
return true;
}

instream.seekg(0,instream.end);
streampos length = instream.tellg();
instream.seekg(0,instream.beg);

const uintptr_t kMaxSize = uintptr_t(-1) / 4;
if (length < 0 || length > (streampos)kMaxSize)
{
cerr << "internal error: bad file length " << length << " for in-memory stream" << endl;
return true;
}

//
// read into memory
//
Expand Down