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

exif: fix integer overflow in position check #1050

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 8 additions & 8 deletions libheif/exif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

static int32_t read32(const uint8_t* data, int size, int pos, bool littleEndian)
{
if (pos + 4 > size) {
if (pos > size - 4) {
return -1;
}

Expand All @@ -45,7 +45,7 @@ static int32_t read32(const uint8_t* data, int size, int pos, bool littleEndian)

static int32_t read16(const uint8_t* data, int size, int pos, bool littleEndian)
{
if (pos + 2 > size) {
if (pos > size - 2) {
return -1;
}

Expand All @@ -62,7 +62,7 @@ static int32_t read16(const uint8_t* data, int size, int pos, bool littleEndian)

static void write16(uint8_t* data, int size, int pos, uint16_t value, bool littleEndian)
{
if (pos + 2 > size) {
if (pos > size - 2) {
return;
}

Expand Down Expand Up @@ -95,18 +95,18 @@ static int find_exif_tag(const uint8_t* exif, int size, uint16_t query_tag, boo
assert(out_littleEndian);
*out_littleEndian = littleEndian;

int offset = read32(exif, size, 4, littleEndian);
int32_t offset = read32(exif, size, 4, littleEndian);
if (offset < 0) {
return -1;
}

int cnt = read16(exif, size, offset, littleEndian);
int32_t cnt = read16(exif, size, offset, littleEndian);
if (cnt < 1) {
return -1;
}

for (int i = 0; i < cnt; i++) {
int tag = read16(exif, size, offset + 2 + i * 12, littleEndian);
int32_t tag = read16(exif, size, offset + 2 + i * 12, littleEndian);
if (tag == query_tag) {
return offset + 2 + i * 12;
}
Expand Down Expand Up @@ -149,8 +149,8 @@ int read_exif_orientation_tag(const uint8_t* exif, int size)
return DEFAULT_EXIF_ORIENTATION;
}

int type = read16(exif, size, pos + 2, little_endian);
int count = read32(exif, size, pos + 4, little_endian);
int32_t type = read16(exif, size, pos + 2, little_endian);
int32_t count = read32(exif, size, pos + 4, little_endian);

if (type == EXIF_TYPE_SHORT && count == 1) {
return read16(exif, size, pos + 8, little_endian);
Expand Down
Loading