Skip to content

Commit e4bb2d1

Browse files
MatmaRexHhvm Bot
authored and
Hhvm Bot
committed
ext_gd: exif_process_IFD_TAG: Use the right offset if reading from stream
Summary: When the location of the data is outside of the range we have preloaded (for example, if it's before the beginning of the IFD structure), we have to read it from the stream into a separate buffer. The offset calculations in this case were incorrect, resulting in bogus values being read for the affected fields (sometimes parts of other fields, sometimes binary data). The included test image, sourced from [1], is in the public domain. [1] https://commons.wikimedia.org/wiki/File:U.S._Marines_Prepare_to_board_an_MV-22_Osprey_160509-M-AF202-041.jpg (This is the same fix as PHP commit c794d53c0377be960a17c3279715436e405b83f4 / php/php-src#1943.) Closes #7208 Reviewed By: Orvid Differential Revision: D3518486 fbshipit-source-id: e0560e9455177d873b9494f736fb140810b25633
1 parent 3b52c47 commit e4bb2d1

File tree

7 files changed

+140
-3
lines changed

7 files changed

+140
-3
lines changed

hphp/runtime/ext/gd/ext_gd.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6435,12 +6435,12 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry,
64356435
}
64366436

64376437
fpos = ImageInfo->infile->tell();
6438-
ImageInfo->infile->seek(offset_val, SEEK_SET);
6438+
ImageInfo->infile->seek(displacement+offset_val, SEEK_SET);
64396439
fgot = ImageInfo->infile->tell();
6440-
if (fgot!=offset_val) {
6440+
if (fgot!=displacement+offset_val) {
64416441
if (outside) IM_FREE(outside);
64426442
raise_warning("Wrong file pointer: 0x%08lX != 0x%08lX",
6443-
fgot, offset_val);
6443+
fgot, displacement+offset_val);
64446444
return 0;
64456445
}
64466446
String str = ImageInfo->infile->read(byte_count);

hphp/test/tools/import_zend_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@
683683
'/ext/dom/tests/xinclude.xml',
684684
'/ext/exif/tests/bug34704.jpg',
685685
'/ext/exif/tests/bug48378.jpeg',
686+
'/ext/exif/tests/bug50845.jpg',
686687
'/ext/exif/tests/bug60150.jpg',
687688
'/ext/exif/tests/bug62523_1.jpg',
688689
'/ext/exif/tests/bug62523_2.jpg',

hphp/test/zend/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ good/ext/date/tests/bug65371.php binary
355355
good/ext/date/tests/bug65371.php.expectf binary
356356
good/ext/exif/tests/bug34704.jpg binary
357357
good/ext/exif/tests/bug48378.jpeg binary
358+
good/ext/exif/tests/bug50845.jpg binary
358359
good/ext/exif/tests/bug60150.jpg binary
359360
good/ext/exif/tests/bug62523_2.jpg binary
360361
good/ext/exif/tests/exif_encoding_crash.jpg binary
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
$infile = dirname(__FILE__).'/bug50845.jpg';
3+
var_dump(exif_read_data($infile));
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
array(44) {
2+
["FileName"]=>
3+
string(12) "bug50845.jpg"
4+
["FileDateTime"]=>
5+
int(%d)
6+
["FileSize"]=>
7+
int(803603)
8+
["FileType"]=>
9+
int(2)
10+
["MimeType"]=>
11+
string(10) "image/jpeg"
12+
["SectionsFound"]=>
13+
string(30) "ANY_TAG, IFD0, THUMBNAIL, EXIF"
14+
["COMPUTED"]=>
15+
array(9) {
16+
["html"]=>
17+
string(26) "width="5472" height="3648""
18+
["Height"]=>
19+
int(3648)
20+
["Width"]=>
21+
int(5472)
22+
["IsColor"]=>
23+
int(1)
24+
["ByteOrderMotorola"]=>
25+
int(0)
26+
["ApertureFNumber"]=>
27+
string(5) "f/7.1"
28+
["Copyright"]=>
29+
string(13) "Public Domain"
30+
["Thumbnail.FileType"]=>
31+
int(2)
32+
["Thumbnail.MimeType"]=>
33+
string(10) "image/jpeg"
34+
}
35+
["ImageDescription"]=>
36+
string(295) "A U.S. Marine Corps MV-22 Osprey lands on the USS Whidbey Island (LSD-41), May 5, 2016. The vehicles were loaded to support a theater security cooperation event as a part of a MEU readiness exercise. (U.S. Marine Corps photo by Lance Cpl. Koby I. Saunders/22 Marine Expeditionary Unit/ Released)"
37+
["Make"]=>
38+
string(5) "Canon"
39+
["Model"]=>
40+
string(22) "Canon EOS-1D X Mark II"
41+
["Orientation"]=>
42+
int(1)
43+
["XResolution"]=>
44+
string(5) "240/1"
45+
["YResolution"]=>
46+
string(5) "240/1"
47+
["ResolutionUnit"]=>
48+
int(2)
49+
["Artist"]=>
50+
string(24) "Lance Cpl. Koby Saunders"
51+
["Copyright"]=>
52+
string(13) "Public Domain"
53+
["Exif_IFD_Pointer"]=>
54+
int(12572)
55+
["THUMBNAIL"]=>
56+
array(6) {
57+
["Compression"]=>
58+
int(6)
59+
["XResolution"]=>
60+
string(5) "240/1"
61+
["YResolution"]=>
62+
string(5) "240/1"
63+
["ResolutionUnit"]=>
64+
int(2)
65+
["JPEGInterchangeFormat"]=>
66+
int(860)
67+
["JPEGInterchangeFormatLength"]=>
68+
int(11204)
69+
}
70+
["ExposureTime"]=>
71+
string(5) "1/200"
72+
["FNumber"]=>
73+
string(5) "71/10"
74+
["ExposureProgram"]=>
75+
int(1)
76+
["ISOSpeedRatings"]=>
77+
int(100)
78+
["UndefinedTag:0x8830"]=>
79+
int(2)
80+
["UndefinedTag:0x8832"]=>
81+
int(100)
82+
["ExifVersion"]=>
83+
string(4) "0230"
84+
["ShutterSpeedValue"]=>
85+
string(15) "7643856/1000000"
86+
["ApertureValue"]=>
87+
string(15) "5655638/1000000"
88+
["ExposureBiasValue"]=>
89+
string(3) "0/1"
90+
["MaxApertureValue"]=>
91+
string(3) "4/1"
92+
["MeteringMode"]=>
93+
int(5)
94+
["Flash"]=>
95+
int(16)
96+
["FocalLength"]=>
97+
string(4) "24/1"
98+
["ColorSpace"]=>
99+
int(65535)
100+
["FocalPlaneXResolution"]=>
101+
string(12) "5472000/1438"
102+
["FocalPlaneYResolution"]=>
103+
string(11) "3648000/958"
104+
["FocalPlaneResolutionUnit"]=>
105+
int(2)
106+
["CustomRendered"]=>
107+
int(0)
108+
["ExposureMode"]=>
109+
int(1)
110+
["WhiteBalance"]=>
111+
int(0)
112+
["SceneCaptureType"]=>
113+
int(0)
114+
["UndefinedTag:0xA431"]=>
115+
string(12) "002099000358"
116+
["UndefinedTag:0xA432"]=>
117+
array(4) {
118+
[0]=>
119+
string(4) "24/1"
120+
[1]=>
121+
string(5) "105/1"
122+
[2]=>
123+
string(3) "0/0"
124+
[3]=>
125+
string(3) "0/0"
126+
}
127+
["UndefinedTag:0xA434"]=>
128+
string(22) "EF24-105mm f/4L IS USM"
129+
["UndefinedTag:0xA435"]=>
130+
string(10) "000044bc4c"
131+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>

0 commit comments

Comments
 (0)