1
From eb81375d6c3924d0f430cdc47be1a88483c47104 Mon Sep 17 00:00:00 2001
2
From: Tormod Volden <debian.tormod@gmail.com>
3
Date: Thu, 15 Nov 2012 21:17:29 +0100
4
Subject: [PATCH] Fix parsing of JPEG orientation tag
6
Parsing the orientation tag in big-endian file formats got broken in
7
commit 0179dfd as reported in https://bugs.launchpad.net/bugs/1077186
9
A short (16 bit) value like the orientation value occupies the two first
10
bytes of the 4-byte offset field, independently of endianness. The
11
commit changed the code from using de_get16() to de_get32 to read out
12
this value, which broke on big-endian (MM/Motorola) byte order JPEG file
13
formats. I believe little-endian files would still work as long as the
14
two last, unused bytes were zero.
16
From http://www.cipa.jp/english/hyoujunka/kikaku/pdf/DC-008-2010_E.pdf
19
This tag records the offset from the start of the TIFF header to the
20
position where the value itself is recorded. In cases where the value
21
fits in 4 Bytes, the value itself is recorded. If the value is smaller
22
than 4 Bytes, the value is stored in the 4-Byte area starting from the
23
left, i.e., from the lower end of the byte offset area. For example, in
24
big endian format, if the type is SHORT and the value is 1, it is
25
recorded as 00010000.H."
27
Also avoid the confusing recycling of the "offset" variable, use a
28
better name for the second use and make it and its siblings
29
local to the block where they are used.
31
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
33
gdk-pixbuf/io-jpeg.c | 14 ++++++--------
34
1 file changed, 6 insertions(+), 8 deletions(-)
36
diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c
37
index bcdf0bb..910158b 100644
38
--- a/gdk-pixbuf/io-jpeg.c
39
+++ b/gdk-pixbuf/io-jpeg.c
40
@@ -393,9 +393,6 @@ jpeg_parse_exif_app1 (JpegExifContext *context, jpeg_saved_marker_ptr marker)
43
guint tags; /* number of tags in current ifd */
47
guint endian = 0; /* detected endian of data */
48
const char leth[] = {0x49, 0x49, 0x2a, 0x00}; // Little endian TIFF header
49
const char beth[] = {0x4d, 0x4d, 0x00, 0x2a}; // Big endian TIFF header
50
@@ -472,10 +469,11 @@ jpeg_parse_exif_app1 (JpegExifContext *context, jpeg_saved_marker_ptr marker)
52
/* check through IFD0 for tags */
54
- tag = de_get16(&marker->data[i + 0], endian);
55
- type = de_get16(&marker->data[i + 2], endian);
56
- count = de_get32(&marker->data[i + 4], endian);
57
- offset = de_get32(&marker->data[i + 8], endian);
58
+ guint tag = de_get16(&marker->data[i + 0], endian);
59
+ guint type = de_get16(&marker->data[i + 2], endian);
60
+ guint count = de_get32(&marker->data[i + 4], endian);
61
+ /* values of types small enough to fit are stored directly in the (first) bytes of the Value Offset field */
62
+ guint short_value = de_get16(&marker->data[i + 8], endian);
64
/* orientation tag? */
66
@@ -485,7 +483,7 @@ jpeg_parse_exif_app1 (JpegExifContext *context, jpeg_saved_marker_ptr marker)
69
/* get the orientation value */
70
- context->orientation = offset <= 8 ? offset : 0;
71
+ context->orientation = short_value <= 8 ? short_value : 0;
73
/* move the pointer to the next 12-byte tag field. */