Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Fixed image orientation if a JFIF APP0 segment is present in a JPEG h…
Browse files Browse the repository at this point in the history
…eader.
  • Loading branch information
naglak committed Sep 24, 2013
1 parent 745eacb commit 5dea695
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions exif.c
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions exif.h
Expand Up @@ -23,6 +23,7 @@

enum {
JPEG_MARKER_SOI = 0xFFD8,
JPEG_MARKER_APP0 = 0xFFE0,
JPEG_MARKER_APP1 = 0xFFE1
};

Expand Down

0 comments on commit 5dea695

Please sign in to comment.