nsxiv5dea695
Fixed image orientation if a JFIF APP0 segment is present in a JPEG header.
+12 −5
2 files changed
| @@ -73,16 +73,22 @@ int exif_orientation(const fileinfo_t *file) | |||
| 73 | 73 | if (fd < 0) | |
| 74 | 74 | return -1; | |
| 75 | 75 | ||
| 76 | − | if (s_read(fd, file->name, data, 4) < 0) | |
| 76 | + | if (s_read(fd, file->name, data, 2) < 0) | |
| 77 | 77 | goto abort; | |
| 78 | 78 | if (btous(data, order) != JPEG_MARKER_SOI) | |
| 79 | 79 | goto abort; | |
| 80 | − | if (btous(data + 2, order) != JPEG_MARKER_APP1) | |
| 80 | + | if (s_read(fd, file->name, data, 4) < 0) | |
| 81 | 81 | 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) | |
| 84 | 90 | goto abort; | |
| 85 | − | len = btous(data, order); | |
| 91 | + | len = btous(data + 2, order); | |
| 86 | 92 | if (len < 8) | |
| 87 | 93 | goto abort; | |
| 88 | 94 | ||
| @@ -23,6 +23,7 @@ | |||
| 23 | 23 | ||
| 24 | 24 | enum { | |
| 25 | 25 | JPEG_MARKER_SOI = 0xFFD8, | |
| 26 | + | JPEG_MARKER_APP0 = 0xFFE0, | |
| 26 | 27 | JPEG_MARKER_APP1 = 0xFFE1 | |
| 27 | 28 | }; | |
| 28 | 29 | ||