Krolyxon
Commit 5dea695

Branches

Refs →

nsxiv5dea695

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

Author
Jacek Naglak
Date
2013-09-24 22:14 +0200
Parent
745eacb
Commit
5dea695c719dc2ee61e7677d553f16c1c4c3ac52

+12 −5

2 files changed

  1. M exif.c +11 −5
  2. M exif.h +1 −0
M exif.c View
@@ -73,16 +73,22 @@ int exif_orientation(const fileinfo_t *file)
7373 if (fd < 0)
7474 return -1;
7575
76− if (s_read(fd, file->name, data, 4) < 0)
76+ if (s_read(fd, file->name, data, 2) < 0)
7777 goto abort;
7878 if (btous(data, order) != JPEG_MARKER_SOI)
7979 goto abort;
80− if (btous(data + 2, order) != JPEG_MARKER_APP1)
80+ if (s_read(fd, file->name, data, 4) < 0)
8181 goto abort;
82−
83− if (s_read(fd, file->name, data, 2) < 0)
82+ if (btous(data, order) == JPEG_MARKER_APP0){
83+ len = btous(data + 2, order);
84+ if (s_read(fd, file->name, data, len - 2) < 0)
85+ goto abort;
86+ if (s_read(fd, file->name, data, 4) < 0)
87+ goto abort;
88+ }
89+ if (btous(data, order) != JPEG_MARKER_APP1)
8490 goto abort;
85− len = btous(data, order);
91+ len = btous(data + 2, order);
8692 if (len < 8)
8793 goto abort;
8894
M exif.h View
@@ -23,6 +23,7 @@
2323
2424 enum {
2525 JPEG_MARKER_SOI = 0xFFD8,
26+ JPEG_MARKER_APP0 = 0xFFE0,
2627 JPEG_MARKER_APP1 = 0xFFE1
2728 };
2829