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

fix heap-buffer-overflow in function ICOInput::readimg in file src/ic… #3872

Merged
merged 1 commit into from
Jun 9, 2023
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
22 changes: 19 additions & 3 deletions src/ico.imageio/icoinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ ICOInput::readimg()
std::vector<unsigned char> scanline(slb);
ico_palette_entry* pe;
int k;
int index;
for (int y = m_spec.height - 1; y >= 0; y--) {
if (!fread(&scanline[0], 1, slb))
return false;
Expand All @@ -316,13 +317,23 @@ ICOInput::readimg()
// fill the buffer
switch (m_bpp) {
case 1:
pe = &palette[(scanline[x / 8] & (1 << (7 - x % 8))) != 0];
index = ((scanline[x / 8] & (1 << (7 - x % 8))) != 0);
if (index >= m_palette_size) {
errorfmt("Possible corruption: index exceeds palette size");
return false;
}
pe = &palette[index];
m_buf[k + 0] = pe->r;
m_buf[k + 1] = pe->g;
m_buf[k + 2] = pe->b;
break;
case 4:
pe = &palette[(scanline[x / 2] & 0xF0) >> 4];
index = ((scanline[x / 2] & 0xF0) >> 4);
if (index >= m_palette_size) {
errorfmt("Possible corruption: index exceeds palette size");
return false;
}
pe = &palette[index];
m_buf[k + 0] = pe->r;
m_buf[k + 1] = pe->g;
m_buf[k + 2] = pe->b;
Expand All @@ -341,7 +352,12 @@ ICOInput::readimg()
<< "\n";*/
break;
case 8:
pe = &palette[scanline[x]];
index = scanline[x];
if (index >= m_palette_size) {
errorfmt("Possible corruption: index exceeds palette size");
return false;
}
pe = &palette[index];
m_buf[k + 0] = pe->r;
m_buf[k + 1] = pe->g;
m_buf[k + 2] = pe->b;
Expand Down