Fixed image orientation if a JFIF APP0 segment is present in a JPEG header.

This commit is contained in:
Jacek Naglak 2013-09-24 22:14:47 +02:00
parent 745eacbcf5
commit 5dea695c71
2 changed files with 12 additions and 5 deletions

16
exif.c
View File

@ -73,16 +73,22 @@ int exif_orientation(const fileinfo_t *file)
if (fd < 0) if (fd < 0)
return -1; return -1;
if (s_read(fd, file->name, data, 4) < 0) if (s_read(fd, file->name, data, 2) < 0)
goto abort; goto abort;
if (btous(data, order) != JPEG_MARKER_SOI) if (btous(data, order) != JPEG_MARKER_SOI)
goto abort; goto abort;
if (btous(data + 2, order) != JPEG_MARKER_APP1) if (s_read(fd, file->name, data, 4) < 0)
goto abort; goto abort;
if (btous(data, order) == JPEG_MARKER_APP0){
if (s_read(fd, file->name, data, 2) < 0) len = btous(data + 2, order);
if (s_read(fd, file->name, data, len - 2) < 0)
goto abort; goto abort;
len = btous(data, order); if (s_read(fd, file->name, data, 4) < 0)
goto abort;
}
if (btous(data, order) != JPEG_MARKER_APP1)
goto abort;
len = btous(data + 2, order);
if (len < 8) if (len < 8)
goto abort; goto abort;

1
exif.h
View File

@ -23,6 +23,7 @@
enum { enum {
JPEG_MARKER_SOI = 0xFFD8, JPEG_MARKER_SOI = 0xFFD8,
JPEG_MARKER_APP0 = 0xFFE0,
JPEG_MARKER_APP1 = 0xFFE1 JPEG_MARKER_APP1 = 0xFFE1
}; };