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 buffer overflows when reading invalid GPS data #9

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(
switch (tag) {
case 1:
// GPS north or south
if (offs + 8 > len) {
return easyexif::ParseError::DataCorrupt;
}

GeoLocation.LatComponents.direction = *(buf + offs + 8);

if (GeoLocation.LatComponents.direction == 0) {
Expand All @@ -960,6 +964,10 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(
// GPS latitude
if ((format == UnsignedRational || format == SignedRational) &&
length == 3) {
if (data + tiff_header_start + 16 > len) {
return easyexif::ParseError::DataCorrupt;
}

GeoLocation.LatComponents.degrees = parse_value<Rational>(
buf + data + tiff_header_start, alignIntel);

Expand All @@ -981,6 +989,10 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(

case 3:
// GPS east or west
if (offs + 8 > len) {
return easyexif::ParseError::DataCorrupt;
}

GeoLocation.LonComponents.direction = *(buf + offs + 8);

if (GeoLocation.LonComponents.direction == 0) {
Expand All @@ -996,6 +1008,10 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(
// GPS longitude
if ((format == UnsignedRational || format == SignedRational) &&
length == 3) {
if (data + tiff_header_start + 16 > len) {
return easyexif::ParseError::DataCorrupt;
}

GeoLocation.LonComponents.degrees = parse_value<Rational>(
buf + data + tiff_header_start, alignIntel);

Expand All @@ -1016,6 +1032,10 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(

case 5:
// GPS altitude reference (below or above sea level)
if (offs + 8 > len) {
return easyexif::ParseError::DataCorrupt;
}

GeoLocation.AltitudeRef = *(buf + offs + 8);

if (1 == GeoLocation.AltitudeRef) {
Expand All @@ -1026,6 +1046,10 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(
case 6:
// GPS altitude
if (format == UnsignedRational || format == SignedRational) {
if (data + tiff_header_start > len) {
return easyexif::ParseError::DataCorrupt;
}

GeoLocation.Altitude = parse_value<Rational>(
buf + data + tiff_header_start, alignIntel);

Expand All @@ -1038,6 +1062,10 @@ easyexif::ParseError easyexif::EXIFInfo::parseFromEXIFSegment(
case 11:
// GPS degree of precision (DOP)
if (format == UnsignedRational || format == SignedRational) {
if (data + tiff_header_start > len) {
return easyexif::ParseError::DataCorrupt;
}

GeoLocation.DOP = parse_value<Rational>(
buf + data + tiff_header_start, alignIntel);
}
Expand Down
Binary file added test-images/gps-invalid.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-images/gps-invalid.jpg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error parsing EXIF: code 1985