aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacek Naglak <jnaglak@tlen.pl>2013-09-24 22:14:47 +0200
committerJacek Naglak <jnaglak@tlen.pl>2013-09-24 22:14:47 +0200
commit5dea695c719dc2ee61e7677d553f16c1c4c3ac52 (patch)
tree7331c4db114ff1e3d1de05a48c3e18a8d24d7e63
parent745eacbcf5404cd0b597ac4d986e819c3e03e786 (diff)
Fixed image orientation if a JFIF APP0 segment is present in a JPEG header.
-rw-r--r--exif.c16
-rw-r--r--exif.h1
2 files changed, 12 insertions, 5 deletions
diff --git a/exif.c b/exif.c
index ae2c2d1..098fa72 100644
--- a/exif.c
+++ b/exif.c
@@ -73,16 +73,22 @@ int exif_orientation(const fileinfo_t *file)
if (fd < 0)
return -1;
- if (s_read(fd, file->name, data, 4) < 0)
+ if (s_read(fd, file->name, data, 2) < 0)
goto abort;
if (btous(data, order) != JPEG_MARKER_SOI)
goto abort;
- if (btous(data + 2, order) != JPEG_MARKER_APP1)
+ if (s_read(fd, file->name, data, 4) < 0)
goto abort;
-
- if (s_read(fd, file->name, data, 2) < 0)
+ if (btous(data, order) == JPEG_MARKER_APP0){
+ len = btous(data + 2, order);
+ if (s_read(fd, file->name, data, len - 2) < 0)
+ goto abort;
+ if (s_read(fd, file->name, data, 4) < 0)
+ goto abort;
+ }
+ if (btous(data, order) != JPEG_MARKER_APP1)
goto abort;
- len = btous(data, order);
+ len = btous(data + 2, order);
if (len < 8)
goto abort;
diff --git a/exif.h b/exif.h
index b37b2cc..257f094 100644
--- a/exif.h
+++ b/exif.h
@@ -23,6 +23,7 @@
enum {
JPEG_MARKER_SOI = 0xFFD8,
+ JPEG_MARKER_APP0 = 0xFFE0,
JPEG_MARKER_APP1 = 0xFFE1
};