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

prevent integer overflows in file exrmultipart.cpp #1681

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/bin/exrmultipart/exrmultipart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,17 @@ convert (
}

Box2i dataWindow = infile.header (0).dataWindow ();
int pixel_count = (dataWindow.size ().y + 1) * (dataWindow.size ().x + 1);
int pixel_width = dataWindow.size ().x + 1;
//
// use int64_t for dimensions, since possible overflow int storage
//
int64_t pixel_count = (static_cast<int64_t>(dataWindow.size ().y) + 1) * (static_cast<int64_t>(dataWindow.size ().x) + 1);
int64_t pixel_width = static_cast<int64_t>(dataWindow.size ().x) + 1;

//
// offset in pixels between base of array and 0,0
int pixel_base = dataWindow.min.y * pixel_width + dataWindow.min.x;
// use int64_t for dimensions, since dataWindow.min.y * pixel_width could overflow int storage
//
int64_t pixel_base = static_cast<int64_t>(dataWindow.min.y) * pixel_width + static_cast<int64_t>(dataWindow.min.x);

vector<vector<char>> channelstore (channel_count);

Expand Down