mirror of
https://github.com/cdcseacave/TinyEXIF.git
synced 2026-07-21 19:23:01 +04:00
Robust parsing if missing offset
This commit is contained in:
@@ -38,3 +38,4 @@ CMakeSettings.json
|
|||||||
.vscode/
|
.vscode/
|
||||||
bin/
|
bin/
|
||||||
binaries/
|
binaries/
|
||||||
|
make/
|
||||||
|
|||||||
+9
-7
@@ -945,15 +945,17 @@ int EXIFInfo::parseFromEXIFSegment(const uint8_t* buf, unsigned len) {
|
|||||||
// entries in the section. The last 4 bytes of the IFD contain an offset
|
// entries in the section. The last 4 bytes of the IFD contain an offset
|
||||||
// to the next IFD, which means this IFD must contain exactly 6 + 12 * num
|
// to the next IFD, which means this IFD must contain exactly 6 + 12 * num
|
||||||
// bytes of data.
|
// bytes of data.
|
||||||
|
// Note that it's possible that the next IFD offset doesn't exist,
|
||||||
|
// so here the last 4 bytes are considered optional.
|
||||||
if (offs + 2 > len)
|
if (offs + 2 > len)
|
||||||
return PARSE_CORRUPT_DATA;
|
return PARSE_CORRUPT_DATA;
|
||||||
int num_entries = EntryParser::parse16(buf + offs, alignIntel);
|
unsigned num_entries = EntryParser::parse16(buf + offs, alignIntel);
|
||||||
if (offs + 6 + 12 * num_entries > len)
|
if (offs + 2 + 12 * num_entries > len)
|
||||||
return PARSE_CORRUPT_DATA;
|
return PARSE_CORRUPT_DATA;
|
||||||
unsigned exif_sub_ifd_offset = len;
|
unsigned exif_sub_ifd_offset = len;
|
||||||
unsigned gps_sub_ifd_offset = len;
|
unsigned gps_sub_ifd_offset = len;
|
||||||
parser.Init(offs+2);
|
parser.Init(offs+2);
|
||||||
while (--num_entries >= 0) {
|
while (num_entries-- > 0) {
|
||||||
parser.ParseTag();
|
parser.ParseTag();
|
||||||
parseIFDImage(parser, exif_sub_ifd_offset, gps_sub_ifd_offset);
|
parseIFDImage(parser, exif_sub_ifd_offset, gps_sub_ifd_offset);
|
||||||
}
|
}
|
||||||
@@ -965,10 +967,10 @@ int EXIFInfo::parseFromEXIFSegment(const uint8_t* buf, unsigned len) {
|
|||||||
if (exif_sub_ifd_offset + 4 <= len) {
|
if (exif_sub_ifd_offset + 4 <= len) {
|
||||||
offs = exif_sub_ifd_offset;
|
offs = exif_sub_ifd_offset;
|
||||||
num_entries = EntryParser::parse16(buf + offs, alignIntel);
|
num_entries = EntryParser::parse16(buf + offs, alignIntel);
|
||||||
if (offs + 6 + 12 * num_entries > len)
|
if (offs + 2 + 12 * num_entries > len)
|
||||||
return PARSE_CORRUPT_DATA;
|
return PARSE_CORRUPT_DATA;
|
||||||
parser.Init(offs+2);
|
parser.Init(offs+2);
|
||||||
while (--num_entries >= 0) {
|
while (num_entries-- > 0) {
|
||||||
parser.ParseTag();
|
parser.ParseTag();
|
||||||
parseIFDExif(parser);
|
parseIFDExif(parser);
|
||||||
}
|
}
|
||||||
@@ -979,10 +981,10 @@ int EXIFInfo::parseFromEXIFSegment(const uint8_t* buf, unsigned len) {
|
|||||||
if (gps_sub_ifd_offset + 4 <= len) {
|
if (gps_sub_ifd_offset + 4 <= len) {
|
||||||
offs = gps_sub_ifd_offset;
|
offs = gps_sub_ifd_offset;
|
||||||
num_entries = EntryParser::parse16(buf + offs, alignIntel);
|
num_entries = EntryParser::parse16(buf + offs, alignIntel);
|
||||||
if (offs + 6 + 12 * num_entries > len)
|
if (offs + 2 + 12 * num_entries > len)
|
||||||
return PARSE_CORRUPT_DATA;
|
return PARSE_CORRUPT_DATA;
|
||||||
parser.Init(offs+2);
|
parser.Init(offs+2);
|
||||||
while (--num_entries >= 0) {
|
while (num_entries-- > 0) {
|
||||||
parser.ParseTag();
|
parser.ParseTag();
|
||||||
parseIFDGPS(parser);
|
parseIFDGPS(parser);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user